Commit f2404867 by Arnaud Charlet

[multiple changes]

2011-09-02  Bob Duff  <duff@adacore.com>

	* lib-xref.adb: (Hash): Avoid use of 'Mod attribute, because old
	compilers don't understand it.

2011-09-02  Gary Dismukes  <dismukes@adacore.com>

	* exp_attr.adb (Expand_N_Attribute_Reference): Pass the
	underlying subtype rather than its base type on the call to
	Build_Record_Or_Elementary_Input_Function, so that any
	constraints on a discriminated subtype will be available for
	doing the check required by AI05-0192.
	* exp_strm.adb (Build_Record_Or_Elementary_Input_Function):
	If the prefix subtype of the 'Input attribute is a constrained
	discriminated subtype, then check each constrained discriminant value
	against the corresponding value read from the stream.

From-SVN: r178453
parent 029b67ba
2011-09-02 Bob Duff <duff@adacore.com>
* lib-xref.adb: (Hash): Avoid use of 'Mod attribute, because old
compilers don't understand it.
2011-09-02 Gary Dismukes <dismukes@adacore.com>
* exp_attr.adb (Expand_N_Attribute_Reference): Pass the
underlying subtype rather than its base type on the call to
Build_Record_Or_Elementary_Input_Function, so that any
constraints on a discriminated subtype will be available for
doing the check required by AI05-0192.
* exp_strm.adb (Build_Record_Or_Elementary_Input_Function):
If the prefix subtype of the 'Input attribute is a constrained
discriminated subtype, then check each constrained discriminant value
against the corresponding value read from the stream.
2011-09-02 Yannick Moy <moy@adacore.com> 2011-09-02 Yannick Moy <moy@adacore.com>
* usage.adb, warnsw.adb, sem_ch6.adb, opt.ads: Disable by default * usage.adb, warnsw.adb, sem_ch6.adb, opt.ads: Disable by default
......
...@@ -2531,8 +2531,12 @@ package body Exp_Attr is ...@@ -2531,8 +2531,12 @@ package body Exp_Attr is
return; return;
end if; end if;
-- Build the type's Input function, passing the subtype rather
-- than its base type, because checks are needed in the case of
-- constrained discriminants (see Ada 2012 AI05-0192).
Build_Record_Or_Elementary_Input_Function Build_Record_Or_Elementary_Input_Function
(Loc, Base_Type (U_Type), Decl, Fname); (Loc, U_Type, Decl, Fname);
Insert_Action (N, Decl); Insert_Action (N, Decl);
if Nkind (Parent (N)) = N_Object_Declaration if Nkind (Parent (N)) = N_Object_Declaration
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
with Atree; use Atree; with Atree; use Atree;
with Einfo; use Einfo; with Einfo; use Einfo;
with Elists; use Elists;
with Exp_Util; use Exp_Util; with Exp_Util; use Exp_Util;
with Namet; use Namet; with Namet; use Namet;
with Nlists; use Nlists; with Nlists; use Nlists;
...@@ -1106,14 +1107,16 @@ package body Exp_Strm is ...@@ -1106,14 +1107,16 @@ package body Exp_Strm is
Decl : out Node_Id; Decl : out Node_Id;
Fnam : out Entity_Id) Fnam : out Entity_Id)
is is
Cn : Name_Id; B_Typ : constant Entity_Id := Base_Type (Typ);
Constr : List_Id; Cn : Name_Id;
Decls : List_Id; Constr : List_Id;
Discr : Entity_Id; Decls : List_Id;
J : Pos; Discr : Entity_Id;
Obj_Decl : Node_Id; Discr_Elmt : Elmt_Id := No_Elmt;
Odef : Node_Id; J : Pos;
Stms : List_Id; Obj_Decl : Node_Id;
Odef : Node_Id;
Stms : List_Id;
begin begin
Decls := New_List; Decls := New_List;
...@@ -1121,8 +1124,15 @@ package body Exp_Strm is ...@@ -1121,8 +1124,15 @@ package body Exp_Strm is
J := 1; J := 1;
if Has_Discriminants (Typ) then if Has_Discriminants (B_Typ) then
Discr := First_Discriminant (Typ); Discr := First_Discriminant (B_Typ);
-- If the prefix subtype is constrained, then retrieve the first
-- element of its constraint.
if Is_Constrained (Typ) then
Discr_Elmt := First_Elmt (Discriminant_Constraint (Typ));
end if;
while Present (Discr) loop while Present (Discr) loop
Cn := New_External_Name ('C', J); Cn := New_External_Name ('C', J);
...@@ -1153,13 +1163,30 @@ package body Exp_Strm is ...@@ -1153,13 +1163,30 @@ package body Exp_Strm is
Append_To (Constr, Make_Identifier (Loc, Cn)); Append_To (Constr, Make_Identifier (Loc, Cn));
-- If the prefix subtype imposes a discriminant constraint, then
-- check that each discriminant value equals the value read.
if Present (Discr_Elmt) then
Append_To (Decls,
Make_Raise_Constraint_Error (Loc,
Condition => Make_Op_Ne (Loc,
Left_Opnd =>
New_Reference_To
(Defining_Identifier (Decl), Loc),
Right_Opnd =>
New_Copy_Tree (Node (Discr_Elmt))),
Reason => CE_Discriminant_Check_Failed));
Next_Elmt (Discr_Elmt);
end if;
Next_Discriminant (Discr); Next_Discriminant (Discr);
J := J + 1; J := J + 1;
end loop; end loop;
Odef := Odef :=
Make_Subtype_Indication (Loc, Make_Subtype_Indication (Loc,
Subtype_Mark => New_Occurrence_Of (Typ, Loc), Subtype_Mark => New_Occurrence_Of (B_Typ, Loc),
Constraint => Constraint =>
Make_Index_Or_Discriminant_Constraint (Loc, Make_Index_Or_Discriminant_Constraint (Loc,
Constraints => Constr)); Constraints => Constr));
...@@ -1167,7 +1194,7 @@ package body Exp_Strm is ...@@ -1167,7 +1194,7 @@ package body Exp_Strm is
-- If no discriminants, then just use the type with no constraint -- If no discriminants, then just use the type with no constraint
else else
Odef := New_Occurrence_Of (Typ, Loc); Odef := New_Occurrence_Of (B_Typ, Loc);
end if; end if;
-- Create an extended return statement encapsulating the result object -- Create an extended return statement encapsulating the result object
...@@ -1184,7 +1211,7 @@ package body Exp_Strm is ...@@ -1184,7 +1211,7 @@ package body Exp_Strm is
-- The object is about to get its value from Read, and if the type is -- The object is about to get its value from Read, and if the type is
-- null excluding we do not want spurious warnings on an initial null. -- null excluding we do not want spurious warnings on an initial null.
if Is_Access_Type (Typ) then if Is_Access_Type (B_Typ) then
Set_No_Initialization (Obj_Decl); Set_No_Initialization (Obj_Decl);
end if; end if;
...@@ -1195,15 +1222,15 @@ package body Exp_Strm is ...@@ -1195,15 +1222,15 @@ package body Exp_Strm is
Make_Handled_Sequence_Of_Statements (Loc, Make_Handled_Sequence_Of_Statements (Loc,
Statements => New_List ( Statements => New_List (
Make_Attribute_Reference (Loc, Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Typ, Loc), Prefix => New_Occurrence_Of (B_Typ, Loc),
Attribute_Name => Name_Read, Attribute_Name => Name_Read,
Expressions => New_List ( Expressions => New_List (
Make_Identifier (Loc, Name_S), Make_Identifier (Loc, Name_S),
Make_Identifier (Loc, Name_V))))))); Make_Identifier (Loc, Name_V)))))));
Fnam := Make_Stream_Subprogram_Name (Loc, Typ, TSS_Stream_Input); Fnam := Make_Stream_Subprogram_Name (Loc, B_Typ, TSS_Stream_Input);
Build_Stream_Function (Loc, Typ, Decl, Fnam, Decls, Stms); Build_Stream_Function (Loc, B_Typ, Decl, Fnam, Decls, Stms);
end Build_Record_Or_Elementary_Input_Function; end Build_Record_Or_Elementary_Input_Function;
------------------------------------------------- -------------------------------------------------
......
...@@ -1057,7 +1057,11 @@ package body Lib.Xref is ...@@ -1057,7 +1057,11 @@ package body Lib.Xref is
XE : Xref_Entry renames Xrefs.Table (F); XE : Xref_Entry renames Xrefs.Table (F);
type M is mod 2**32; type M is mod 2**32;
H : constant M := M'Mod (XE.Key.Ent) + 2**7 * M'Mod (XE.Key.Loc);
H : constant M := M (XE.Key.Ent) + 2**7 * M (abs XE.Key.Loc);
-- We can't use M'Mod above, because it prevents bootstrapping with
-- older compilers. Loc can be negative, so we do "abs" before
-- converting.
begin begin
return Header_Num (H mod Num_Buckets); return Header_Num (H mod Num_Buckets);
end Hash; end Hash;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment