1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2003, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Exp_Tss; use Exp_Tss;
32 with Exp_Util; use Exp_Util;
33 with Hostparm; use Hostparm;
35 with Nlists; use Nlists;
36 with Nmake; use Nmake;
38 with Rtsfind; use Rtsfind;
40 with Sem_Ch8; use Sem_Ch8;
41 with Sem_Eval; use Sem_Eval;
42 with Sem_Res; use Sem_Res;
43 with Sem_Type; use Sem_Type;
44 with Sem_Util; use Sem_Util;
45 with Snames; use Snames;
46 with Stand; use Stand;
47 with Sinfo; use Sinfo;
49 with Ttypes; use Ttypes;
50 with Tbuild; use Tbuild;
51 with Urealp; use Urealp;
53 with GNAT.Heap_Sort_A; use GNAT.Heap_Sort_A;
55 package body Sem_Ch13 is
57 SSU : constant Pos := System_Storage_Unit;
58 -- Convenient short hand for commonly used constant
60 -----------------------
61 -- Local Subprograms --
62 -----------------------
64 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id);
65 -- This routine is called after setting the Esize of type entity Typ.
66 -- The purpose is to deal with the situation where an aligment has been
67 -- inherited from a derived type that is no longer appropriate for the
68 -- new Esize value. In this case, we reset the Alignment to unknown.
70 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
71 -- Given two entities for record components or discriminants, checks
72 -- if they hav overlapping component clauses and issues errors if so.
74 function Get_Alignment_Value (Expr : Node_Id) return Uint;
75 -- Given the expression for an alignment value, returns the corresponding
76 -- Uint value. If the value is inappropriate, then error messages are
77 -- posted as required, and a value of No_Uint is returned.
79 function Is_Operational_Item (N : Node_Id) return Boolean;
80 -- A specification for a stream attribute is allowed before the full
81 -- type is declared, as explained in AI-00137 and the corrigendum.
82 -- Attributes that do not specify a representation characteristic are
83 -- operational attributes.
85 function Address_Aliased_Entity (N : Node_Id) return Entity_Id;
86 -- If expression N is of the form E'Address, return E.
88 procedure Mark_Aliased_Address_As_Volatile (N : Node_Id);
89 -- This is used for processing of an address representation clause. If
90 -- the expression N is of the form of K'Address, then the entity that
91 -- is associated with K is marked as volatile.
93 procedure New_Stream_Function
98 -- Create a function renaming of a given stream attribute to the
99 -- designated subprogram and then in the tagged case, provide this as
100 -- a primitive operation, or in the non-tagged case make an appropriate
101 -- TSS entry. Used for Input. This is more properly an expansion activity
102 -- than just semantics, but the presence of user-defined stream functions
103 -- for limited types is a legality check, which is why this takes place
104 -- here rather than in exp_ch13, where it was previously. Nam indicates
105 -- the name of the TSS function to be generated.
107 -- To avoid elaboration anomalies with freeze nodes, for untagged types
108 -- we generate both a subprogram declaration and a subprogram renaming
109 -- declaration, so that the attribute specification is handled as a
110 -- renaming_as_body. For tagged types, the specification is one of the
113 procedure New_Stream_Procedure
118 Out_P : Boolean := False);
119 -- Create a procedure renaming of a given stream attribute to the
120 -- designated subprogram and then in the tagged case, provide this as
121 -- a primitive operation, or in the non-tagged case make an appropriate
122 -- TSS entry. Used for Read, Output, Write. Nam indicates the name of
123 -- the TSS procedure to be generated.
125 ----------------------------------------------
126 -- Table for Validate_Unchecked_Conversions --
127 ----------------------------------------------
129 -- The following table collects unchecked conversions for validation.
130 -- Entries are made by Validate_Unchecked_Conversion and then the
131 -- call to Validate_Unchecked_Conversions does the actual error
132 -- checking and posting of warnings. The reason for this delayed
133 -- processing is to take advantage of back-annotations of size and
134 -- alignment values peformed by the back end.
136 type UC_Entry is record
137 Enode : Node_Id; -- node used for posting warnings
138 Source : Entity_Id; -- source type for unchecked conversion
139 Target : Entity_Id; -- target type for unchecked conversion
142 package Unchecked_Conversions is new Table.Table (
143 Table_Component_Type => UC_Entry,
144 Table_Index_Type => Int,
145 Table_Low_Bound => 1,
147 Table_Increment => 200,
148 Table_Name => "Unchecked_Conversions");
150 ----------------------------
151 -- Address_Aliased_Entity --
152 ----------------------------
154 function Address_Aliased_Entity (N : Node_Id) return Entity_Id is
156 if Nkind (N) = N_Attribute_Reference
157 and then Attribute_Name (N) = Name_Address
160 Nam : Node_Id := Prefix (N);
163 or else Nkind (Nam) = N_Selected_Component
164 or else Nkind (Nam) = N_Indexed_Component
169 if Is_Entity_Name (Nam) then
176 end Address_Aliased_Entity;
178 --------------------------------------
179 -- Alignment_Check_For_Esize_Change --
180 --------------------------------------
182 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id) is
184 -- If the alignment is known, and not set by a rep clause, and is
185 -- inconsistent with the size being set, then reset it to unknown,
186 -- we assume in this case that the size overrides the inherited
187 -- alignment, and that the alignment must be recomputed.
189 if Known_Alignment (Typ)
190 and then not Has_Alignment_Clause (Typ)
191 and then Esize (Typ) mod (Alignment (Typ) * SSU) /= 0
193 Init_Alignment (Typ);
195 end Alignment_Check_For_Esize_Change;
197 -----------------------
198 -- Analyze_At_Clause --
199 -----------------------
201 -- An at clause is replaced by the corresponding Address attribute
202 -- definition clause that is the preferred approach in Ada 95.
204 procedure Analyze_At_Clause (N : Node_Id) is
206 if Warn_On_Obsolescent_Feature then
208 ("at clause is an obsolescent feature ('R'M 'J.7(2))?", N);
210 ("|use address attribute definition clause instead?", N);
214 Make_Attribute_Definition_Clause (Sloc (N),
215 Name => Identifier (N),
216 Chars => Name_Address,
217 Expression => Expression (N)));
218 Analyze_Attribute_Definition_Clause (N);
219 end Analyze_At_Clause;
221 -----------------------------------------
222 -- Analyze_Attribute_Definition_Clause --
223 -----------------------------------------
225 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
226 Loc : constant Source_Ptr := Sloc (N);
227 Nam : constant Node_Id := Name (N);
228 Attr : constant Name_Id := Chars (N);
229 Expr : constant Node_Id := Expression (N);
230 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
234 FOnly : Boolean := False;
235 -- Reset to True for subtype specific attribute (Alignment, Size)
236 -- and for stream attributes, i.e. those cases where in the call
237 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
238 -- rules are checked. Note that the case of stream attributes is not
239 -- clear from the RM, but see AI95-00137. Also, the RM seems to
240 -- disallow Storage_Size for derived task types, but that is also
241 -- clearly unintentional.
247 if Rep_Item_Too_Early (Ent, N) then
251 -- Rep clause applies to full view of incomplete type or private type
252 -- if we have one (if not, this is a premature use of the type).
253 -- However, certain semantic checks need to be done on the specified
254 -- entity (i.e. the private view), so we save it in Ent.
256 if Is_Private_Type (Ent)
257 and then Is_Derived_Type (Ent)
258 and then not Is_Tagged_Type (Ent)
259 and then No (Full_View (Ent))
261 -- If this is a private type whose completion is a derivation
262 -- from another private type, there is no full view, and the
263 -- attribute belongs to the type itself, not its underlying parent.
267 elsif Ekind (Ent) = E_Incomplete_Type then
268 Ent := Underlying_Type (Ent);
271 U_Ent := Underlying_Type (Ent);
274 -- Complete other routine error checks
276 if Etype (Nam) = Any_Type then
279 elsif Scope (Ent) /= Current_Scope then
280 Error_Msg_N ("entity must be declared in this scope", Nam);
283 elsif No (U_Ent) then
286 elsif Is_Type (U_Ent)
287 and then not Is_First_Subtype (U_Ent)
288 and then Id /= Attribute_Object_Size
289 and then Id /= Attribute_Value_Size
290 and then not From_At_Mod (N)
292 Error_Msg_N ("cannot specify attribute for subtype", Nam);
297 -- Switch on particular attribute
305 -- Address attribute definition clause
307 when Attribute_Address => Address : begin
308 Analyze_And_Resolve (Expr, RTE (RE_Address));
310 if Present (Address_Clause (U_Ent)) then
311 Error_Msg_N ("address already given for &", Nam);
313 -- Case of address clause for subprogram
315 elsif Is_Subprogram (U_Ent) then
316 if Has_Homonym (U_Ent) then
318 ("address clause cannot be given " &
319 "for overloaded subprogram",
323 -- For subprograms, all address clauses are permitted,
324 -- and we mark the subprogram as having a deferred freeze
325 -- so that Gigi will not elaborate it too soon.
327 -- Above needs more comments, what is too soon about???
329 Set_Has_Delayed_Freeze (U_Ent);
331 -- Case of address clause for entry
333 elsif Ekind (U_Ent) = E_Entry then
334 if Nkind (Parent (N)) = N_Task_Body then
336 ("entry address must be specified in task spec", Nam);
339 -- For entries, we require a constant address
341 Check_Constant_Address_Clause (Expr, U_Ent);
343 if Is_Task_Type (Scope (U_Ent))
344 and then Comes_From_Source (Scope (U_Ent))
347 ("?entry address declared for entry in task type", N);
349 ("\?only one task can be declared of this type", N);
352 if Warn_On_Obsolescent_Feature then
354 ("attaching interrupt to task entry is an " &
355 "obsolescent feature ('R'M 'J.7.1)?", N);
357 ("|use interrupt procedure instead?", N);
360 -- Case of an address clause for a controlled object:
361 -- erroneous execution.
363 elsif Is_Controlled (Etype (U_Ent)) then
365 ("?controlled object& must not be overlaid", Nam, U_Ent);
367 ("\?Program_Error will be raised at run time", Nam);
368 Insert_Action (Declaration_Node (U_Ent),
369 Make_Raise_Program_Error (Loc,
370 Reason => PE_Overlaid_Controlled_Object));
372 -- Case of address clause for a (non-controlled) object
375 Ekind (U_Ent) = E_Variable
377 Ekind (U_Ent) = E_Constant
380 Expr : constant Node_Id := Expression (N);
381 Aent : constant Entity_Id := Address_Aliased_Entity (Expr);
384 -- Exported variables cannot have an address clause,
385 -- because this cancels the effect of the pragma Export
387 if Is_Exported (U_Ent) then
389 ("cannot export object with address clause", Nam);
391 -- Overlaying controlled objects is erroneous
394 and then Is_Controlled (Etype (Aent))
397 ("?controlled object must not be overlaid", Expr);
399 ("\?Program_Error will be raised at run time", Expr);
400 Insert_Action (Declaration_Node (U_Ent),
401 Make_Raise_Program_Error (Loc,
402 Reason => PE_Overlaid_Controlled_Object));
405 and then Ekind (U_Ent) = E_Constant
406 and then Ekind (Aent) /= E_Constant
408 Error_Msg_N ("constant overlays a variable?", Expr);
410 elsif Present (Renamed_Object (U_Ent)) then
412 ("address clause not allowed"
413 & " for a renaming declaration ('R'M 13.1(6))", Nam);
415 -- Imported variables can have an address clause, but then
416 -- the import is pretty meaningless except to suppress
417 -- initializations, so we do not need such variables to
418 -- be statically allocated (and in fact it causes trouble
419 -- if the address clause is a local value).
421 elsif Is_Imported (U_Ent) then
422 Set_Is_Statically_Allocated (U_Ent, False);
425 -- We mark a possible modification of a variable with an
426 -- address clause, since it is likely aliasing is occurring.
428 Note_Possible_Modification (Nam);
430 -- Here we are checking for explicit overlap of one
431 -- variable by another, and if we find this, then we
432 -- mark the overlapped variable as also being aliased.
434 -- First case is where we have an explicit
436 -- for J'Address use K'Address;
438 -- In this case, we mark K as volatile
440 Mark_Aliased_Address_As_Volatile (Expr);
442 -- Second case is where we have a constant whose
443 -- definition is of the form of an adress as in:
445 -- A : constant Address := K'Address;
447 -- for B'Address use A;
449 -- In this case we also mark K as volatile
451 if Is_Entity_Name (Expr) then
453 Ent : constant Entity_Id := Entity (Expr);
454 Decl : constant Node_Id := Declaration_Node (Ent);
457 if Ekind (Ent) = E_Constant
458 and then Nkind (Decl) = N_Object_Declaration
459 and then Present (Expression (Decl))
461 Mark_Aliased_Address_As_Volatile
467 -- Legality checks on the address clause for initialized
468 -- objects is deferred until the freeze point, because
469 -- a subsequent pragma might indicate that the object is
470 -- imported and thus not initialized.
472 Set_Has_Delayed_Freeze (U_Ent);
474 if Is_Exported (U_Ent) then
476 ("& cannot be exported if an address clause is given",
479 ("\define and export a variable " &
480 "that holds its address instead",
484 -- Entity has delayed freeze, so we will generate
485 -- an alignment check at the freeze point.
487 Set_Check_Address_Alignment
488 (N, not Range_Checks_Suppressed (U_Ent));
490 -- Kill the size check code, since we are not allocating
491 -- the variable, it is somewhere else.
493 Kill_Size_Check_Code (U_Ent);
496 -- Not a valid entity for an address clause
499 Error_Msg_N ("address cannot be given for &", Nam);
507 -- Alignment attribute definition clause
509 when Attribute_Alignment => Alignment_Block : declare
510 Align : constant Uint := Get_Alignment_Value (Expr);
515 if not Is_Type (U_Ent)
516 and then Ekind (U_Ent) /= E_Variable
517 and then Ekind (U_Ent) /= E_Constant
519 Error_Msg_N ("alignment cannot be given for &", Nam);
521 elsif Has_Alignment_Clause (U_Ent) then
522 Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
523 Error_Msg_N ("alignment clause previously given#", N);
525 elsif Align /= No_Uint then
526 Set_Has_Alignment_Clause (U_Ent);
527 Set_Alignment (U_Ent, Align);
535 -- Bit_Order attribute definition clause
537 when Attribute_Bit_Order => Bit_Order : declare
539 if not Is_Record_Type (U_Ent) then
541 ("Bit_Order can only be defined for record type", Nam);
544 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
546 if Etype (Expr) = Any_Type then
549 elsif not Is_Static_Expression (Expr) then
551 ("Bit_Order requires static expression!", Expr);
554 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
555 Set_Reverse_Bit_Order (U_Ent, True);
565 -- Component_Size attribute definition clause
567 when Attribute_Component_Size => Component_Size_Case : declare
568 Csize : constant Uint := Static_Integer (Expr);
571 New_Ctyp : Entity_Id;
575 if not Is_Array_Type (U_Ent) then
576 Error_Msg_N ("component size requires array type", Nam);
580 Btype := Base_Type (U_Ent);
582 if Has_Component_Size_Clause (Btype) then
584 ("component size clase for& previously given", Nam);
586 elsif Csize /= No_Uint then
587 Check_Size (Expr, Component_Type (Btype), Csize, Biased);
589 if Has_Aliased_Components (Btype)
595 ("component size incorrect for aliased components", N);
599 -- For the biased case, build a declaration for a subtype
600 -- that will be used to represent the biased subtype that
601 -- reflects the biased representation of components. We need
602 -- this subtype to get proper conversions on referencing
603 -- elements of the array.
607 Make_Defining_Identifier (Loc,
608 Chars => New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
611 Make_Subtype_Declaration (Loc,
612 Defining_Identifier => New_Ctyp,
613 Subtype_Indication =>
614 New_Occurrence_Of (Component_Type (Btype), Loc));
616 Set_Parent (Decl, N);
617 Analyze (Decl, Suppress => All_Checks);
619 Set_Has_Delayed_Freeze (New_Ctyp, False);
620 Set_Esize (New_Ctyp, Csize);
621 Set_RM_Size (New_Ctyp, Csize);
622 Init_Alignment (New_Ctyp);
623 Set_Has_Biased_Representation (New_Ctyp, True);
624 Set_Is_Itype (New_Ctyp, True);
625 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
627 Set_Component_Type (Btype, New_Ctyp);
630 Set_Component_Size (Btype, Csize);
631 Set_Has_Component_Size_Clause (Btype, True);
632 Set_Has_Non_Standard_Rep (Btype, True);
634 end Component_Size_Case;
640 when Attribute_External_Tag => External_Tag :
642 if not Is_Tagged_Type (U_Ent) then
643 Error_Msg_N ("should be a tagged type", Nam);
646 Analyze_And_Resolve (Expr, Standard_String);
648 if not Is_Static_Expression (Expr) then
650 ("static string required for tag name!", Nam);
653 Set_Has_External_Tag_Rep_Clause (U_Ent);
660 when Attribute_Input => Input : declare
661 Subp : Entity_Id := Empty;
666 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
667 -- Return true if the entity is a function with an appropriate
668 -- profile for the Input attribute.
670 ----------------------
671 -- Has_Good_Profile --
672 ----------------------
674 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
676 Ok : Boolean := False;
679 if Ekind (Subp) = E_Function then
680 F := First_Formal (Subp);
682 if Present (F) and then No (Next_Formal (F)) then
683 if Ekind (Etype (F)) = E_Anonymous_Access_Type
685 Designated_Type (Etype (F)) =
686 Class_Wide_Type (RTE (RE_Root_Stream_Type))
688 Ok := Base_Type (Etype (Subp)) = Base_Type (Ent);
694 end Has_Good_Profile;
696 -- Start of processing for Input attribute definition
701 if not Is_Type (U_Ent) then
702 Error_Msg_N ("local name must be a subtype", Nam);
706 Pnam := TSS (Base_Type (U_Ent), TSS_Stream_Input);
709 and then Base_Type (Etype (Pnam)) = Base_Type (U_Ent)
711 Error_Msg_Sloc := Sloc (Pnam);
712 Error_Msg_N ("input attribute already defined #", Nam);
719 if Is_Entity_Name (Expr) then
720 if not Is_Overloaded (Expr) then
721 if Has_Good_Profile (Entity (Expr)) then
722 Subp := Entity (Expr);
726 Get_First_Interp (Expr, I, It);
728 while Present (It.Nam) loop
729 if Has_Good_Profile (It.Nam) then
734 Get_Next_Interp (I, It);
739 if Present (Subp) then
740 Set_Entity (Expr, Subp);
741 Set_Etype (Expr, Etype (Subp));
742 New_Stream_Function (N, U_Ent, Subp, TSS_Stream_Input);
744 Error_Msg_N ("incorrect expression for input attribute", Expr);
753 -- Machine radix attribute definition clause
755 when Attribute_Machine_Radix => Machine_Radix : declare
756 Radix : constant Uint := Static_Integer (Expr);
759 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
760 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
762 elsif Has_Machine_Radix_Clause (U_Ent) then
763 Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
764 Error_Msg_N ("machine radix clause previously given#", N);
766 elsif Radix /= No_Uint then
767 Set_Has_Machine_Radix_Clause (U_Ent);
768 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
772 elsif Radix = 10 then
773 Set_Machine_Radix_10 (U_Ent);
775 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
784 -- Object_Size attribute definition clause
786 when Attribute_Object_Size => Object_Size : declare
787 Size : constant Uint := Static_Integer (Expr);
791 if not Is_Type (U_Ent) then
792 Error_Msg_N ("Object_Size cannot be given for &", Nam);
794 elsif Has_Object_Size_Clause (U_Ent) then
795 Error_Msg_N ("Object_Size already given for &", Nam);
798 Check_Size (Expr, U_Ent, Size, Biased);
806 UI_Mod (Size, 64) /= 0
809 ("Object_Size must be 8, 16, 32, or multiple of 64",
813 Set_Esize (U_Ent, Size);
814 Set_Has_Object_Size_Clause (U_Ent);
815 Alignment_Check_For_Esize_Change (U_Ent);
823 when Attribute_Output => Output : declare
824 Subp : Entity_Id := Empty;
829 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
830 -- Return true if the entity is a procedure with an
831 -- appropriate profile for the output attribute.
833 ----------------------
834 -- Has_Good_Profile --
835 ----------------------
837 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
839 Ok : Boolean := False;
842 if Ekind (Subp) = E_Procedure then
843 F := First_Formal (Subp);
846 if Ekind (Etype (F)) = E_Anonymous_Access_Type
848 Designated_Type (Etype (F)) =
849 Class_Wide_Type (RTE (RE_Root_Stream_Type))
853 and then Parameter_Mode (F) = E_In_Parameter
854 and then Base_Type (Etype (F)) = Base_Type (Ent)
855 and then No (Next_Formal (F));
861 end Has_Good_Profile;
863 -- Start of processing for Output attribute definition
868 if not Is_Type (U_Ent) then
869 Error_Msg_N ("local name must be a subtype", Nam);
873 Pnam := TSS (Base_Type (U_Ent), TSS_Stream_Output);
877 Base_Type (Etype (Next_Formal (First_Formal (Pnam))))
880 Error_Msg_Sloc := Sloc (Pnam);
881 Error_Msg_N ("output attribute already defined #", Nam);
888 if Is_Entity_Name (Expr) then
889 if not Is_Overloaded (Expr) then
890 if Has_Good_Profile (Entity (Expr)) then
891 Subp := Entity (Expr);
895 Get_First_Interp (Expr, I, It);
897 while Present (It.Nam) loop
898 if Has_Good_Profile (It.Nam) then
903 Get_Next_Interp (I, It);
908 if Present (Subp) then
909 Set_Entity (Expr, Subp);
910 Set_Etype (Expr, Etype (Subp));
911 New_Stream_Procedure (N, U_Ent, Subp, TSS_Stream_Output);
913 Error_Msg_N ("incorrect expression for output attribute", Expr);
922 when Attribute_Read => Read : declare
923 Subp : Entity_Id := Empty;
928 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
929 -- Return true if the entity is a procedure with an appropriate
930 -- profile for the Read attribute.
932 ----------------------
933 -- Has_Good_Profile --
934 ----------------------
936 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
938 Ok : Boolean := False;
941 if Ekind (Subp) = E_Procedure then
942 F := First_Formal (Subp);
945 if Ekind (Etype (F)) = E_Anonymous_Access_Type
947 Designated_Type (Etype (F)) =
948 Class_Wide_Type (RTE (RE_Root_Stream_Type))
952 and then Parameter_Mode (F) = E_Out_Parameter
953 and then Base_Type (Etype (F)) = Base_Type (Ent)
954 and then No (Next_Formal (F));
960 end Has_Good_Profile;
962 -- Start of processing for Read attribute definition
967 if not Is_Type (U_Ent) then
968 Error_Msg_N ("local name must be a subtype", Nam);
972 Pnam := TSS (Base_Type (U_Ent), TSS_Stream_Read);
975 and then Base_Type (Etype (Next_Formal (First_Formal (Pnam))))
978 Error_Msg_Sloc := Sloc (Pnam);
979 Error_Msg_N ("read attribute already defined #", Nam);
986 if Is_Entity_Name (Expr) then
987 if not Is_Overloaded (Expr) then
988 if Has_Good_Profile (Entity (Expr)) then
989 Subp := Entity (Expr);
993 Get_First_Interp (Expr, I, It);
995 while Present (It.Nam) loop
996 if Has_Good_Profile (It.Nam) then
1001 Get_Next_Interp (I, It);
1006 if Present (Subp) then
1007 Set_Entity (Expr, Subp);
1008 Set_Etype (Expr, Etype (Subp));
1009 New_Stream_Procedure (N, U_Ent, Subp, TSS_Stream_Read, True);
1011 Error_Msg_N ("incorrect expression for read attribute", Expr);
1020 -- Size attribute definition clause
1022 when Attribute_Size => Size : declare
1023 Size : constant Uint := Static_Integer (Expr);
1030 if Has_Size_Clause (U_Ent) then
1031 Error_Msg_N ("size already given for &", Nam);
1033 elsif not Is_Type (U_Ent)
1034 and then Ekind (U_Ent) /= E_Variable
1035 and then Ekind (U_Ent) /= E_Constant
1037 Error_Msg_N ("size cannot be given for &", Nam);
1039 elsif Is_Array_Type (U_Ent)
1040 and then not Is_Constrained (U_Ent)
1043 ("size cannot be given for unconstrained array", Nam);
1045 elsif Size /= No_Uint then
1046 if Is_Type (U_Ent) then
1049 Etyp := Etype (U_Ent);
1052 -- Check size, note that Gigi is in charge of checking
1053 -- that the size of an array or record type is OK. Also
1054 -- we do not check the size in the ordinary fixed-point
1055 -- case, since it is too early to do so (there may be a
1056 -- subsequent small clause that affects the size). We can
1057 -- check the size if a small clause has already been given.
1059 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
1060 or else Has_Small_Clause (U_Ent)
1062 Check_Size (Expr, Etyp, Size, Biased);
1063 Set_Has_Biased_Representation (U_Ent, Biased);
1066 -- For types set RM_Size and Esize if possible
1068 if Is_Type (U_Ent) then
1069 Set_RM_Size (U_Ent, Size);
1071 -- For scalar types, increase Object_Size to power of 2,
1072 -- but not less than a storage unit in any case (i.e.,
1073 -- normally this means it will be byte addressable).
1075 if Is_Scalar_Type (U_Ent) then
1076 if Size <= System_Storage_Unit then
1077 Init_Esize (U_Ent, System_Storage_Unit);
1078 elsif Size <= 16 then
1079 Init_Esize (U_Ent, 16);
1080 elsif Size <= 32 then
1081 Init_Esize (U_Ent, 32);
1083 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
1086 -- For all other types, object size = value size. The
1087 -- backend will adjust as needed.
1090 Set_Esize (U_Ent, Size);
1093 Alignment_Check_For_Esize_Change (U_Ent);
1095 -- For objects, set Esize only
1098 if Is_Elementary_Type (Etyp) then
1099 if Size /= System_Storage_Unit
1101 Size /= System_Storage_Unit * 2
1103 Size /= System_Storage_Unit * 4
1105 Size /= System_Storage_Unit * 8
1108 ("size for primitive object must be power of 2", N);
1112 Set_Esize (U_Ent, Size);
1115 Set_Has_Size_Clause (U_Ent);
1123 -- Small attribute definition clause
1125 when Attribute_Small => Small : declare
1126 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
1130 Analyze_And_Resolve (Expr, Any_Real);
1132 if Etype (Expr) = Any_Type then
1135 elsif not Is_Static_Expression (Expr) then
1136 Flag_Non_Static_Expr
1137 ("small requires static expression!", Expr);
1141 Small := Expr_Value_R (Expr);
1143 if Small <= Ureal_0 then
1144 Error_Msg_N ("small value must be greater than zero", Expr);
1150 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
1152 ("small requires an ordinary fixed point type", Nam);
1154 elsif Has_Small_Clause (U_Ent) then
1155 Error_Msg_N ("small already given for &", Nam);
1157 elsif Small > Delta_Value (U_Ent) then
1159 ("small value must not be greater then delta value", Nam);
1162 Set_Small_Value (U_Ent, Small);
1163 Set_Small_Value (Implicit_Base, Small);
1164 Set_Has_Small_Clause (U_Ent);
1165 Set_Has_Small_Clause (Implicit_Base);
1166 Set_Has_Non_Standard_Rep (Implicit_Base);
1174 -- Storage_Size attribute definition clause
1176 when Attribute_Storage_Size => Storage_Size : declare
1177 Btype : constant Entity_Id := Base_Type (U_Ent);
1181 if Is_Task_Type (U_Ent) then
1182 if Warn_On_Obsolescent_Feature then
1184 ("storage size clause for task is an " &
1185 "obsolescent feature ('R'M 'J.9)?", N);
1187 ("|use Storage_Size pragma instead?", N);
1193 if not Is_Access_Type (U_Ent)
1194 and then Ekind (U_Ent) /= E_Task_Type
1196 Error_Msg_N ("storage size cannot be given for &", Nam);
1198 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
1200 ("storage size cannot be given for a derived access type",
1203 elsif Has_Storage_Size_Clause (Btype) then
1204 Error_Msg_N ("storage size already given for &", Nam);
1207 Analyze_And_Resolve (Expr, Any_Integer);
1209 if Is_Access_Type (U_Ent) then
1211 if Present (Associated_Storage_Pool (U_Ent)) then
1212 Error_Msg_N ("storage pool already given for &", Nam);
1216 if Compile_Time_Known_Value (Expr)
1217 and then Expr_Value (Expr) = 0
1219 Set_No_Pool_Assigned (Btype);
1222 else -- Is_Task_Type (U_Ent)
1223 Sprag := Get_Rep_Pragma (Btype, Name_Storage_Size);
1225 if Present (Sprag) then
1226 Error_Msg_Sloc := Sloc (Sprag);
1228 ("Storage_Size already specified#", Nam);
1233 Set_Has_Storage_Size_Clause (Btype);
1241 -- Storage_Pool attribute definition clause
1243 when Attribute_Storage_Pool => Storage_Pool : declare
1247 if Ekind (U_Ent) /= E_Access_Type
1248 and then Ekind (U_Ent) /= E_General_Access_Type
1251 "storage pool can only be given for access types", Nam);
1254 elsif Is_Derived_Type (U_Ent) then
1256 ("storage pool cannot be given for a derived access type",
1259 elsif Has_Storage_Size_Clause (U_Ent) then
1260 Error_Msg_N ("storage size already given for &", Nam);
1263 elsif Present (Associated_Storage_Pool (U_Ent)) then
1264 Error_Msg_N ("storage pool already given for &", Nam);
1269 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
1271 -- If the argument is a name that is not an entity name, then
1272 -- we construct a renaming operation to define an entity of
1273 -- type storage pool.
1275 if not Is_Entity_Name (Expr)
1276 and then Is_Object_Reference (Expr)
1279 Make_Defining_Identifier (Loc,
1280 Chars => New_Internal_Name ('P'));
1283 Rnode : constant Node_Id :=
1284 Make_Object_Renaming_Declaration (Loc,
1285 Defining_Identifier => Pool,
1287 New_Occurrence_Of (Etype (Expr), Loc),
1291 Insert_Before (N, Rnode);
1293 Set_Associated_Storage_Pool (U_Ent, Pool);
1296 elsif Is_Entity_Name (Expr) then
1297 Pool := Entity (Expr);
1299 -- If pool is a renamed object, get original one. This can
1300 -- happen with an explicit renaming, and within instances.
1302 while Present (Renamed_Object (Pool))
1303 and then Is_Entity_Name (Renamed_Object (Pool))
1305 Pool := Entity (Renamed_Object (Pool));
1308 if Present (Renamed_Object (Pool))
1309 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
1310 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
1312 Pool := Entity (Expression (Renamed_Object (Pool)));
1315 if Present (Etype (Pool))
1316 and then Etype (Pool) /= RTE (RE_Stack_Bounded_Pool)
1317 and then Etype (Pool) /= RTE (RE_Unbounded_Reclaim_Pool)
1319 Set_Associated_Storage_Pool (U_Ent, Pool);
1321 Error_Msg_N ("Non sharable GNAT Pool", Expr);
1324 -- The pool may be specified as the Storage_Pool of some other
1325 -- type. It is rewritten as a class_wide conversion of the
1326 -- corresponding pool entity.
1328 elsif Nkind (Expr) = N_Type_Conversion
1329 and then Is_Entity_Name (Expression (Expr))
1330 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
1332 Pool := Entity (Expression (Expr));
1334 if Present (Etype (Pool))
1335 and then Etype (Pool) /= RTE (RE_Stack_Bounded_Pool)
1336 and then Etype (Pool) /= RTE (RE_Unbounded_Reclaim_Pool)
1338 Set_Associated_Storage_Pool (U_Ent, Pool);
1340 Error_Msg_N ("Non sharable GNAT Pool", Expr);
1344 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
1353 -- Value_Size attribute definition clause
1355 when Attribute_Value_Size => Value_Size : declare
1356 Size : constant Uint := Static_Integer (Expr);
1360 if not Is_Type (U_Ent) then
1361 Error_Msg_N ("Value_Size cannot be given for &", Nam);
1364 (Get_Attribute_Definition_Clause
1365 (U_Ent, Attribute_Value_Size))
1367 Error_Msg_N ("Value_Size already given for &", Nam);
1370 if Is_Elementary_Type (U_Ent) then
1371 Check_Size (Expr, U_Ent, Size, Biased);
1372 Set_Has_Biased_Representation (U_Ent, Biased);
1375 Set_RM_Size (U_Ent, Size);
1383 -- Write attribute definition clause
1384 -- check for class-wide case will be performed later
1386 when Attribute_Write => Write : declare
1387 Subp : Entity_Id := Empty;
1392 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
1393 -- Return true if the entity is a procedure with an
1394 -- appropriate profile for the write attribute.
1396 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
1398 Ok : Boolean := False;
1401 if Ekind (Subp) = E_Procedure then
1402 F := First_Formal (Subp);
1405 if Ekind (Etype (F)) = E_Anonymous_Access_Type
1407 Designated_Type (Etype (F)) =
1408 Class_Wide_Type (RTE (RE_Root_Stream_Type))
1412 and then Parameter_Mode (F) = E_In_Parameter
1413 and then Base_Type (Etype (F)) = Base_Type (Ent)
1414 and then No (Next_Formal (F));
1420 end Has_Good_Profile;
1422 -- Start of processing for Write attribute definition
1427 if not Is_Type (U_Ent) then
1428 Error_Msg_N ("local name must be a subtype", Nam);
1432 Pnam := TSS (Base_Type (U_Ent), TSS_Stream_Write);
1435 and then Base_Type (Etype (Next_Formal (First_Formal (Pnam))))
1438 Error_Msg_Sloc := Sloc (Pnam);
1439 Error_Msg_N ("write attribute already defined #", Nam);
1445 if Is_Entity_Name (Expr) then
1446 if not Is_Overloaded (Expr) then
1447 if Has_Good_Profile (Entity (Expr)) then
1448 Subp := Entity (Expr);
1452 Get_First_Interp (Expr, I, It);
1454 while Present (It.Nam) loop
1455 if Has_Good_Profile (It.Nam) then
1460 Get_Next_Interp (I, It);
1465 if Present (Subp) then
1466 Set_Entity (Expr, Subp);
1467 Set_Etype (Expr, Etype (Subp));
1468 New_Stream_Procedure (N, U_Ent, Subp, TSS_Stream_Write);
1470 Error_Msg_N ("incorrect expression for write attribute", Expr);
1475 -- All other attributes cannot be set
1479 ("attribute& cannot be set with definition clause", N);
1483 -- The test for the type being frozen must be performed after
1484 -- any expression the clause has been analyzed since the expression
1485 -- itself might cause freezing that makes the clause illegal.
1487 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
1490 end Analyze_Attribute_Definition_Clause;
1492 ----------------------------
1493 -- Analyze_Code_Statement --
1494 ----------------------------
1496 procedure Analyze_Code_Statement (N : Node_Id) is
1497 HSS : constant Node_Id := Parent (N);
1498 SBody : constant Node_Id := Parent (HSS);
1499 Subp : constant Entity_Id := Current_Scope;
1506 -- Analyze and check we get right type, note that this implements the
1507 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1508 -- is the only way that Asm_Insn could possibly be visible.
1510 Analyze_And_Resolve (Expression (N));
1512 if Etype (Expression (N)) = Any_Type then
1514 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
1515 Error_Msg_N ("incorrect type for code statement", N);
1519 -- Make sure we appear in the handled statement sequence of a
1520 -- subprogram (RM 13.8(3)).
1522 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
1523 or else Nkind (SBody) /= N_Subprogram_Body
1526 ("code statement can only appear in body of subprogram", N);
1530 -- Do remaining checks (RM 13.8(3)) if not already done
1532 if not Is_Machine_Code_Subprogram (Subp) then
1533 Set_Is_Machine_Code_Subprogram (Subp);
1535 -- No exception handlers allowed
1537 if Present (Exception_Handlers (HSS)) then
1539 ("exception handlers not permitted in machine code subprogram",
1540 First (Exception_Handlers (HSS)));
1543 -- No declarations other than use clauses and pragmas (we allow
1544 -- certain internally generated declarations as well).
1546 Decl := First (Declarations (SBody));
1547 while Present (Decl) loop
1548 DeclO := Original_Node (Decl);
1549 if Comes_From_Source (DeclO)
1550 and then Nkind (DeclO) /= N_Pragma
1551 and then Nkind (DeclO) /= N_Use_Package_Clause
1552 and then Nkind (DeclO) /= N_Use_Type_Clause
1553 and then Nkind (DeclO) /= N_Implicit_Label_Declaration
1556 ("this declaration not allowed in machine code subprogram",
1563 -- No statements other than code statements, pragmas, and labels.
1564 -- Again we allow certain internally generated statements.
1566 Stmt := First (Statements (HSS));
1567 while Present (Stmt) loop
1568 StmtO := Original_Node (Stmt);
1569 if Comes_From_Source (StmtO)
1570 and then Nkind (StmtO) /= N_Pragma
1571 and then Nkind (StmtO) /= N_Label
1572 and then Nkind (StmtO) /= N_Code_Statement
1575 ("this statement is not allowed in machine code subprogram",
1582 end Analyze_Code_Statement;
1584 -----------------------------------------------
1585 -- Analyze_Enumeration_Representation_Clause --
1586 -----------------------------------------------
1588 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
1589 Ident : constant Node_Id := Identifier (N);
1590 Aggr : constant Node_Id := Array_Aggregate (N);
1591 Enumtype : Entity_Id;
1597 Err : Boolean := False;
1599 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
1600 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
1605 -- First some basic error checks
1608 Enumtype := Entity (Ident);
1610 if Enumtype = Any_Type
1611 or else Rep_Item_Too_Early (Enumtype, N)
1615 Enumtype := Underlying_Type (Enumtype);
1618 if not Is_Enumeration_Type (Enumtype) then
1620 ("enumeration type required, found}",
1621 Ident, First_Subtype (Enumtype));
1625 -- Ignore rep clause on generic actual type. This will already have
1626 -- been flagged on the template as an error, and this is the safest
1627 -- way to ensure we don't get a junk cascaded message in the instance.
1629 if Is_Generic_Actual_Type (Enumtype) then
1632 -- Type must be in current scope
1634 elsif Scope (Enumtype) /= Current_Scope then
1635 Error_Msg_N ("type must be declared in this scope", Ident);
1638 -- Type must be a first subtype
1640 elsif not Is_First_Subtype (Enumtype) then
1641 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
1644 -- Ignore duplicate rep clause
1646 elsif Has_Enumeration_Rep_Clause (Enumtype) then
1647 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
1650 -- Don't allow rep clause if root type is standard [wide_]character
1652 elsif Root_Type (Enumtype) = Standard_Character
1653 or else Root_Type (Enumtype) = Standard_Wide_Character
1655 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
1658 -- All tests passed, so set rep clause in place
1661 Set_Has_Enumeration_Rep_Clause (Enumtype);
1662 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
1665 -- Now we process the aggregate. Note that we don't use the normal
1666 -- aggregate code for this purpose, because we don't want any of the
1667 -- normal expansion activities, and a number of special semantic
1668 -- rules apply (including the component type being any integer type)
1670 -- Badent signals that we found some incorrect entries processing
1671 -- the list. The final checks for completeness and ordering are
1672 -- skipped in this case.
1674 Elit := First_Literal (Enumtype);
1676 -- First the positional entries if any
1678 if Present (Expressions (Aggr)) then
1679 Expr := First (Expressions (Aggr));
1680 while Present (Expr) loop
1682 Error_Msg_N ("too many entries in aggregate", Expr);
1686 Val := Static_Integer (Expr);
1688 if Val = No_Uint then
1691 elsif Val < Lo or else Hi < Val then
1692 Error_Msg_N ("value outside permitted range", Expr);
1696 Set_Enumeration_Rep (Elit, Val);
1697 Set_Enumeration_Rep_Expr (Elit, Expr);
1703 -- Now process the named entries if present
1705 if Present (Component_Associations (Aggr)) then
1706 Assoc := First (Component_Associations (Aggr));
1707 while Present (Assoc) loop
1708 Choice := First (Choices (Assoc));
1710 if Present (Next (Choice)) then
1712 ("multiple choice not allowed here", Next (Choice));
1716 if Nkind (Choice) = N_Others_Choice then
1717 Error_Msg_N ("others choice not allowed here", Choice);
1720 elsif Nkind (Choice) = N_Range then
1721 -- ??? should allow zero/one element range here
1722 Error_Msg_N ("range not allowed here", Choice);
1726 Analyze_And_Resolve (Choice, Enumtype);
1728 if Is_Entity_Name (Choice)
1729 and then Is_Type (Entity (Choice))
1731 Error_Msg_N ("subtype name not allowed here", Choice);
1733 -- ??? should allow static subtype with zero/one entry
1735 elsif Etype (Choice) = Base_Type (Enumtype) then
1736 if not Is_Static_Expression (Choice) then
1737 Flag_Non_Static_Expr
1738 ("non-static expression used for choice!", Choice);
1742 Elit := Expr_Value_E (Choice);
1744 if Present (Enumeration_Rep_Expr (Elit)) then
1745 Error_Msg_Sloc := Sloc (Enumeration_Rep_Expr (Elit));
1747 ("representation for& previously given#",
1752 Set_Enumeration_Rep_Expr (Elit, Choice);
1754 Expr := Expression (Assoc);
1755 Val := Static_Integer (Expr);
1757 if Val = No_Uint then
1760 elsif Val < Lo or else Hi < Val then
1761 Error_Msg_N ("value outside permitted range", Expr);
1765 Set_Enumeration_Rep (Elit, Val);
1774 -- Aggregate is fully processed. Now we check that a full set of
1775 -- representations was given, and that they are in range and in order.
1776 -- These checks are only done if no other errors occurred.
1782 Elit := First_Literal (Enumtype);
1783 while Present (Elit) loop
1784 if No (Enumeration_Rep_Expr (Elit)) then
1785 Error_Msg_NE ("missing representation for&!", N, Elit);
1788 Val := Enumeration_Rep (Elit);
1790 if Min = No_Uint then
1794 if Val /= No_Uint then
1795 if Max /= No_Uint and then Val <= Max then
1797 ("enumeration value for& not ordered!",
1798 Enumeration_Rep_Expr (Elit), Elit);
1804 -- If there is at least one literal whose representation
1805 -- is not equal to the Pos value, then note that this
1806 -- enumeration type has a non-standard representation.
1808 if Val /= Enumeration_Pos (Elit) then
1809 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
1816 -- Now set proper size information
1819 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
1822 if Has_Size_Clause (Enumtype) then
1823 if Esize (Enumtype) >= Minsize then
1828 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
1830 if Esize (Enumtype) < Minsize then
1831 Error_Msg_N ("previously given size is too small", N);
1834 Set_Has_Biased_Representation (Enumtype);
1839 Set_RM_Size (Enumtype, Minsize);
1840 Set_Enum_Esize (Enumtype);
1843 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
1844 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
1845 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
1849 -- We repeat the too late test in case it froze itself!
1851 if Rep_Item_Too_Late (Enumtype, N) then
1854 end Analyze_Enumeration_Representation_Clause;
1856 ----------------------------
1857 -- Analyze_Free_Statement --
1858 ----------------------------
1860 procedure Analyze_Free_Statement (N : Node_Id) is
1862 Analyze (Expression (N));
1863 end Analyze_Free_Statement;
1865 ------------------------------------------
1866 -- Analyze_Record_Representation_Clause --
1867 ------------------------------------------
1869 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
1870 Loc : constant Source_Ptr := Sloc (N);
1871 Ident : constant Node_Id := Identifier (N);
1872 Rectype : Entity_Id;
1878 Hbit : Uint := Uint_0;
1883 Max_Bit_So_Far : Uint;
1884 -- Records the maximum bit position so far. If all field positions
1885 -- are monotonically increasing, then we can skip the circuit for
1886 -- checking for overlap, since no overlap is possible.
1888 Overlap_Check_Required : Boolean;
1889 -- Used to keep track of whether or not an overlap check is required
1891 Ccount : Natural := 0;
1892 -- Number of component clauses in record rep clause
1896 Rectype := Entity (Ident);
1898 if Rectype = Any_Type
1899 or else Rep_Item_Too_Early (Rectype, N)
1903 Rectype := Underlying_Type (Rectype);
1906 -- First some basic error checks
1908 if not Is_Record_Type (Rectype) then
1910 ("record type required, found}", Ident, First_Subtype (Rectype));
1913 elsif Is_Unchecked_Union (Rectype) then
1915 ("record rep clause not allowed for Unchecked_Union", N);
1917 elsif Scope (Rectype) /= Current_Scope then
1918 Error_Msg_N ("type must be declared in this scope", N);
1921 elsif not Is_First_Subtype (Rectype) then
1922 Error_Msg_N ("cannot give record rep clause for subtype", N);
1925 elsif Has_Record_Rep_Clause (Rectype) then
1926 Error_Msg_N ("duplicate record rep clause ignored", N);
1929 elsif Rep_Item_Too_Late (Rectype, N) then
1933 if Present (Mod_Clause (N)) then
1935 Loc : constant Source_Ptr := Sloc (N);
1936 M : constant Node_Id := Mod_Clause (N);
1937 P : constant List_Id := Pragmas_Before (M);
1941 pragma Warnings (Off, Mod_Val);
1944 if Warn_On_Obsolescent_Feature then
1946 ("mod clause is an obsolescent feature ('R'M 'J.8)?", N);
1948 ("|use alignment attribute definition clause instead?", N);
1955 -- In ASIS_Mode mode, expansion is disabled, but we must
1956 -- convert the Mod clause into an alignment clause anyway, so
1957 -- that the back-end can compute and back-annotate properly the
1958 -- size and alignment of types that may include this record.
1960 if Operating_Mode = Check_Semantics
1964 Make_Attribute_Definition_Clause (Loc,
1965 Name => New_Reference_To (Base_Type (Rectype), Loc),
1966 Chars => Name_Alignment,
1967 Expression => Relocate_Node (Expression (M)));
1969 Set_From_At_Mod (AtM_Nod);
1970 Insert_After (N, AtM_Nod);
1971 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
1972 Set_Mod_Clause (N, Empty);
1975 -- Get the alignment value to perform error checking
1977 Mod_Val := Get_Alignment_Value (Expression (M));
1983 -- Clear any existing component clauses for the type (this happens
1984 -- with derived types, where we are now overriding the original)
1986 Fent := First_Entity (Rectype);
1989 while Present (Comp) loop
1990 if Ekind (Comp) = E_Component
1991 or else Ekind (Comp) = E_Discriminant
1993 Set_Component_Clause (Comp, Empty);
1999 -- All done if no component clauses
2001 CC := First (Component_Clauses (N));
2007 -- If a tag is present, then create a component clause that places
2008 -- it at the start of the record (otherwise gigi may place it after
2009 -- other fields that have rep clauses).
2011 if Nkind (Fent) = N_Defining_Identifier
2012 and then Chars (Fent) = Name_uTag
2014 Set_Component_Bit_Offset (Fent, Uint_0);
2015 Set_Normalized_Position (Fent, Uint_0);
2016 Set_Normalized_First_Bit (Fent, Uint_0);
2017 Set_Normalized_Position_Max (Fent, Uint_0);
2018 Init_Esize (Fent, System_Address_Size);
2020 Set_Component_Clause (Fent,
2021 Make_Component_Clause (Loc,
2023 Make_Identifier (Loc,
2024 Chars => Name_uTag),
2027 Make_Integer_Literal (Loc,
2031 Make_Integer_Literal (Loc,
2035 Make_Integer_Literal (Loc,
2036 UI_From_Int (System_Address_Size))));
2038 Ccount := Ccount + 1;
2041 -- A representation like this applies to the base type
2043 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
2044 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
2045 Set_Has_Specified_Layout (Base_Type (Rectype));
2047 Max_Bit_So_Far := Uint_Minus_1;
2048 Overlap_Check_Required := False;
2050 -- Process the component clauses
2052 while Present (CC) loop
2054 -- If pragma, just analyze it
2056 if Nkind (CC) = N_Pragma then
2059 -- Processing for real component clause
2062 Ccount := Ccount + 1;
2063 Posit := Static_Integer (Position (CC));
2064 Fbit := Static_Integer (First_Bit (CC));
2065 Lbit := Static_Integer (Last_Bit (CC));
2068 and then Fbit /= No_Uint
2069 and then Lbit /= No_Uint
2073 ("position cannot be negative", Position (CC));
2077 ("first bit cannot be negative", First_Bit (CC));
2079 -- Values look OK, so find the corresponding record component
2080 -- Even though the syntax allows an attribute reference for
2081 -- implementation-defined components, GNAT does not allow the
2082 -- tag to get an explicit position.
2084 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
2086 if Attribute_Name (Component_Name (CC)) = Name_Tag then
2087 Error_Msg_N ("position of tag cannot be specified", CC);
2089 Error_Msg_N ("illegal component name", CC);
2093 Comp := First_Entity (Rectype);
2094 while Present (Comp) loop
2095 exit when Chars (Comp) = Chars (Component_Name (CC));
2101 -- Maybe component of base type that is absent from
2102 -- statically constrained first subtype.
2104 Comp := First_Entity (Base_Type (Rectype));
2105 while Present (Comp) loop
2106 exit when Chars (Comp) = Chars (Component_Name (CC));
2113 ("component clause is for non-existent field", CC);
2115 elsif Present (Component_Clause (Comp)) then
2116 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
2118 ("component clause previously given#", CC);
2121 -- Update Fbit and Lbit to the actual bit number.
2123 Fbit := Fbit + UI_From_Int (SSU) * Posit;
2124 Lbit := Lbit + UI_From_Int (SSU) * Posit;
2126 if Fbit <= Max_Bit_So_Far then
2127 Overlap_Check_Required := True;
2129 Max_Bit_So_Far := Lbit;
2132 if Has_Size_Clause (Rectype)
2133 and then Esize (Rectype) <= Lbit
2136 ("bit number out of range of specified size",
2139 Set_Component_Clause (Comp, CC);
2140 Set_Component_Bit_Offset (Comp, Fbit);
2141 Set_Esize (Comp, 1 + (Lbit - Fbit));
2142 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
2143 Set_Normalized_Position (Comp, Fbit / SSU);
2145 Set_Normalized_Position_Max
2146 (Fent, Normalized_Position (Fent));
2148 if Is_Tagged_Type (Rectype)
2149 and then Fbit < System_Address_Size
2152 ("component overlaps tag field of&",
2156 -- This information is also set in the corresponding
2157 -- component of the base type, found by accessing the
2158 -- Original_Record_Component link if it is present.
2160 Ocomp := Original_Record_Component (Comp);
2167 (Component_Name (CC),
2172 Set_Has_Biased_Representation (Comp, Biased);
2174 if Present (Ocomp) then
2175 Set_Component_Clause (Ocomp, CC);
2176 Set_Component_Bit_Offset (Ocomp, Fbit);
2177 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
2178 Set_Normalized_Position (Ocomp, Fbit / SSU);
2179 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
2181 Set_Normalized_Position_Max
2182 (Ocomp, Normalized_Position (Ocomp));
2184 Set_Has_Biased_Representation
2185 (Ocomp, Has_Biased_Representation (Comp));
2188 if Esize (Comp) < 0 then
2189 Error_Msg_N ("component size is negative", CC);
2200 -- Now that we have processed all the component clauses, check for
2201 -- overlap. We have to leave this till last, since the components
2202 -- can appear in any arbitrary order in the representation clause.
2204 -- We do not need this check if all specified ranges were monotonic,
2205 -- as recorded by Overlap_Check_Required being False at this stage.
2207 -- This first section checks if there are any overlapping entries
2208 -- at all. It does this by sorting all entries and then seeing if
2209 -- there are any overlaps. If there are none, then that is decisive,
2210 -- but if there are overlaps, they may still be OK (they may result
2211 -- from fields in different variants).
2213 if Overlap_Check_Required then
2214 Overlap_Check1 : declare
2216 OC_Fbit : array (0 .. Ccount) of Uint;
2217 -- First-bit values for component clauses, the value is the
2218 -- offset of the first bit of the field from start of record.
2219 -- The zero entry is for use in sorting.
2221 OC_Lbit : array (0 .. Ccount) of Uint;
2222 -- Last-bit values for component clauses, the value is the
2223 -- offset of the last bit of the field from start of record.
2224 -- The zero entry is for use in sorting.
2226 OC_Count : Natural := 0;
2227 -- Count of entries in OC_Fbit and OC_Lbit
2229 function OC_Lt (Op1, Op2 : Natural) return Boolean;
2230 -- Compare routine for Sort (See GNAT.Heap_Sort_A)
2232 procedure OC_Move (From : Natural; To : Natural);
2233 -- Move routine for Sort (see GNAT.Heap_Sort_A)
2235 function OC_Lt (Op1, Op2 : Natural) return Boolean is
2237 return OC_Fbit (Op1) < OC_Fbit (Op2);
2240 procedure OC_Move (From : Natural; To : Natural) is
2242 OC_Fbit (To) := OC_Fbit (From);
2243 OC_Lbit (To) := OC_Lbit (From);
2247 CC := First (Component_Clauses (N));
2248 while Present (CC) loop
2249 if Nkind (CC) /= N_Pragma then
2250 Posit := Static_Integer (Position (CC));
2251 Fbit := Static_Integer (First_Bit (CC));
2252 Lbit := Static_Integer (Last_Bit (CC));
2255 and then Fbit /= No_Uint
2256 and then Lbit /= No_Uint
2258 OC_Count := OC_Count + 1;
2259 Posit := Posit * SSU;
2260 OC_Fbit (OC_Count) := Fbit + Posit;
2261 OC_Lbit (OC_Count) := Lbit + Posit;
2270 OC_Move'Unrestricted_Access,
2271 OC_Lt'Unrestricted_Access);
2273 Overlap_Check_Required := False;
2274 for J in 1 .. OC_Count - 1 loop
2275 if OC_Lbit (J) >= OC_Fbit (J + 1) then
2276 Overlap_Check_Required := True;
2283 -- If Overlap_Check_Required is still True, then we have to do
2284 -- the full scale overlap check, since we have at least two fields
2285 -- that do overlap, and we need to know if that is OK since they
2286 -- are in the same variant, or whether we have a definite problem
2288 if Overlap_Check_Required then
2289 Overlap_Check2 : declare
2290 C1_Ent, C2_Ent : Entity_Id;
2291 -- Entities of components being checked for overlap
2294 -- Component_List node whose Component_Items are being checked
2297 -- Component declaration for component being checked
2300 C1_Ent := First_Entity (Base_Type (Rectype));
2302 -- Loop through all components in record. For each component check
2303 -- for overlap with any of the preceding elements on the component
2304 -- list containing the component, and also, if the component is in
2305 -- a variant, check against components outside the case structure.
2306 -- This latter test is repeated recursively up the variant tree.
2308 Main_Component_Loop : while Present (C1_Ent) loop
2309 if Ekind (C1_Ent) /= E_Component
2310 and then Ekind (C1_Ent) /= E_Discriminant
2312 goto Continue_Main_Component_Loop;
2315 -- Skip overlap check if entity has no declaration node. This
2316 -- happens with discriminants in constrained derived types.
2317 -- Probably we are missing some checks as a result, but that
2318 -- does not seem terribly serious ???
2320 if No (Declaration_Node (C1_Ent)) then
2321 goto Continue_Main_Component_Loop;
2324 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
2326 -- Loop through component lists that need checking. Check the
2327 -- current component list and all lists in variants above us.
2329 Component_List_Loop : loop
2331 -- If derived type definition, go to full declaration
2332 -- If at outer level, check discriminants if there are any
2334 if Nkind (Clist) = N_Derived_Type_Definition then
2335 Clist := Parent (Clist);
2338 -- Outer level of record definition, check discriminants
2340 if Nkind (Clist) = N_Full_Type_Declaration
2341 or else Nkind (Clist) = N_Private_Type_Declaration
2343 if Has_Discriminants (Defining_Identifier (Clist)) then
2345 First_Discriminant (Defining_Identifier (Clist));
2347 while Present (C2_Ent) loop
2348 exit when C1_Ent = C2_Ent;
2349 Check_Component_Overlap (C1_Ent, C2_Ent);
2350 Next_Discriminant (C2_Ent);
2354 -- Record extension case
2356 elsif Nkind (Clist) = N_Derived_Type_Definition then
2359 -- Otherwise check one component list
2362 Citem := First (Component_Items (Clist));
2364 while Present (Citem) loop
2365 if Nkind (Citem) = N_Component_Declaration then
2366 C2_Ent := Defining_Identifier (Citem);
2367 exit when C1_Ent = C2_Ent;
2368 Check_Component_Overlap (C1_Ent, C2_Ent);
2375 -- Check for variants above us (the parent of the Clist can
2376 -- be a variant, in which case its parent is a variant part,
2377 -- and the parent of the variant part is a component list
2378 -- whose components must all be checked against the current
2379 -- component for overlap.
2381 if Nkind (Parent (Clist)) = N_Variant then
2382 Clist := Parent (Parent (Parent (Clist)));
2384 -- Check for possible discriminant part in record, this is
2385 -- treated essentially as another level in the recursion.
2386 -- For this case we have the parent of the component list
2387 -- is the record definition, and its parent is the full
2388 -- type declaration which contains the discriminant
2391 elsif Nkind (Parent (Clist)) = N_Record_Definition then
2392 Clist := Parent (Parent ((Clist)));
2394 -- If neither of these two cases, we are at the top of
2398 exit Component_List_Loop;
2400 end loop Component_List_Loop;
2402 <<Continue_Main_Component_Loop>>
2403 Next_Entity (C1_Ent);
2405 end loop Main_Component_Loop;
2409 -- For records that have component clauses for all components, and
2410 -- whose size is less than or equal to 32, we need to know the size
2411 -- in the front end to activate possible packed array processing
2412 -- where the component type is a record.
2414 -- At this stage Hbit + 1 represents the first unused bit from all
2415 -- the component clauses processed, so if the component clauses are
2416 -- complete, then this is the length of the record.
2418 -- For records longer than System.Storage_Unit, and for those where
2419 -- not all components have component clauses, the back end determines
2420 -- the length (it may for example be appopriate to round up the size
2421 -- to some convenient boundary, based on alignment considerations etc).
2423 if Unknown_RM_Size (Rectype)
2424 and then Hbit + 1 <= 32
2426 -- Nothing to do if at least one component with no component clause
2428 Comp := First_Entity (Rectype);
2429 while Present (Comp) loop
2430 if Ekind (Comp) = E_Component
2431 or else Ekind (Comp) = E_Discriminant
2433 if No (Component_Clause (Comp)) then
2441 -- If we fall out of loop, all components have component clauses
2442 -- and so we can set the size to the maximum value.
2444 Set_RM_Size (Rectype, Hbit + 1);
2446 end Analyze_Record_Representation_Clause;
2448 -----------------------------
2449 -- Check_Component_Overlap --
2450 -----------------------------
2452 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
2454 if Present (Component_Clause (C1_Ent))
2455 and then Present (Component_Clause (C2_Ent))
2457 -- Exclude odd case where we have two tag fields in the same
2458 -- record, both at location zero. This seems a bit strange,
2459 -- but it seems to happen in some circumstances ???
2461 if Chars (C1_Ent) = Name_uTag
2462 and then Chars (C2_Ent) = Name_uTag
2467 -- Here we check if the two fields overlap
2470 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
2471 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
2472 E1 : constant Uint := S1 + Esize (C1_Ent);
2473 E2 : constant Uint := S2 + Esize (C2_Ent);
2476 if E2 <= S1 or else E1 <= S2 then
2480 Component_Name (Component_Clause (C2_Ent));
2481 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
2483 Component_Name (Component_Clause (C1_Ent));
2485 ("component& overlaps & #",
2486 Component_Name (Component_Clause (C1_Ent)));
2490 end Check_Component_Overlap;
2492 -----------------------------------
2493 -- Check_Constant_Address_Clause --
2494 -----------------------------------
2496 procedure Check_Constant_Address_Clause
2500 procedure Check_At_Constant_Address (Nod : Node_Id);
2501 -- Checks that the given node N represents a name whose 'Address
2502 -- is constant (in the same sense as OK_Constant_Address_Clause,
2503 -- i.e. the address value is the same at the point of declaration
2504 -- of U_Ent and at the time of elaboration of the address clause.
2506 procedure Check_Expr_Constants (Nod : Node_Id);
2507 -- Checks that Nod meets the requirements for a constant address
2508 -- clause in the sense of the enclosing procedure.
2510 procedure Check_List_Constants (Lst : List_Id);
2511 -- Check that all elements of list Lst meet the requirements for a
2512 -- constant address clause in the sense of the enclosing procedure.
2514 -------------------------------
2515 -- Check_At_Constant_Address --
2516 -------------------------------
2518 procedure Check_At_Constant_Address (Nod : Node_Id) is
2520 if Is_Entity_Name (Nod) then
2521 if Present (Address_Clause (Entity ((Nod)))) then
2523 ("invalid address clause for initialized object &!",
2526 ("address for& cannot" &
2527 " depend on another address clause! ('R'M 13.1(22))!",
2530 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
2531 and then Sloc (U_Ent) < Sloc (Entity (Nod))
2534 ("invalid address clause for initialized object &!",
2536 Error_Msg_Name_1 := Chars (Entity (Nod));
2537 Error_Msg_Name_2 := Chars (U_Ent);
2539 ("\% must be defined before % ('R'M 13.1(22))!",
2543 elsif Nkind (Nod) = N_Selected_Component then
2545 T : constant Entity_Id := Etype (Prefix (Nod));
2548 if (Is_Record_Type (T)
2549 and then Has_Discriminants (T))
2552 and then Is_Record_Type (Designated_Type (T))
2553 and then Has_Discriminants (Designated_Type (T)))
2556 ("invalid address clause for initialized object &!",
2559 ("\address cannot depend on component" &
2560 " of discriminated record ('R'M 13.1(22))!",
2563 Check_At_Constant_Address (Prefix (Nod));
2567 elsif Nkind (Nod) = N_Indexed_Component then
2568 Check_At_Constant_Address (Prefix (Nod));
2569 Check_List_Constants (Expressions (Nod));
2572 Check_Expr_Constants (Nod);
2574 end Check_At_Constant_Address;
2576 --------------------------
2577 -- Check_Expr_Constants --
2578 --------------------------
2580 procedure Check_Expr_Constants (Nod : Node_Id) is
2581 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
2582 Ent : Entity_Id := Empty;
2585 if Nkind (Nod) in N_Has_Etype
2586 and then Etype (Nod) = Any_Type
2592 when N_Empty | N_Error =>
2595 when N_Identifier | N_Expanded_Name =>
2596 Ent := Entity (Nod);
2598 -- We need to look at the original node if it is different
2599 -- from the node, since we may have rewritten things and
2600 -- substituted an identifier representing the rewrite.
2602 if Original_Node (Nod) /= Nod then
2603 Check_Expr_Constants (Original_Node (Nod));
2605 -- If the node is an object declaration without initial
2606 -- value, some code has been expanded, and the expression
2607 -- is not constant, even if the constituents might be
2608 -- acceptable, as in A'Address + offset.
2610 if Ekind (Ent) = E_Variable
2611 and then Nkind (Declaration_Node (Ent))
2612 = N_Object_Declaration
2614 No (Expression (Declaration_Node (Ent)))
2617 ("invalid address clause for initialized object &!",
2620 -- If entity is constant, it may be the result of expanding
2621 -- a check. We must verify that its declaration appears
2622 -- before the object in question, else we also reject the
2625 elsif Ekind (Ent) = E_Constant
2626 and then In_Same_Source_Unit (Ent, U_Ent)
2627 and then Sloc (Ent) > Loc_U_Ent
2630 ("invalid address clause for initialized object &!",
2637 -- Otherwise look at the identifier and see if it is OK.
2639 if Ekind (Ent) = E_Named_Integer
2641 Ekind (Ent) = E_Named_Real
2648 Ekind (Ent) = E_Constant
2650 Ekind (Ent) = E_In_Parameter
2652 -- This is the case where we must have Ent defined
2653 -- before U_Ent. Clearly if they are in different
2654 -- units this requirement is met since the unit
2655 -- containing Ent is already processed.
2657 if not In_Same_Source_Unit (Ent, U_Ent) then
2660 -- Otherwise location of Ent must be before the
2661 -- location of U_Ent, that's what prior defined means.
2663 elsif Sloc (Ent) < Loc_U_Ent then
2668 ("invalid address clause for initialized object &!",
2670 Error_Msg_Name_1 := Chars (Ent);
2671 Error_Msg_Name_2 := Chars (U_Ent);
2673 ("\% must be defined before % ('R'M 13.1(22))!",
2677 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
2678 Check_Expr_Constants (Original_Node (Nod));
2682 ("invalid address clause for initialized object &!",
2685 if Comes_From_Source (Ent) then
2686 Error_Msg_Name_1 := Chars (Ent);
2688 ("\reference to variable% not allowed"
2689 & " ('R'M 13.1(22))!", Nod);
2692 ("non-static expression not allowed"
2693 & " ('R'M 13.1(22))!", Nod);
2697 when N_Integer_Literal |
2700 N_Character_Literal =>
2704 Check_Expr_Constants (Low_Bound (Nod));
2705 Check_Expr_Constants (High_Bound (Nod));
2707 when N_Explicit_Dereference =>
2708 Check_Expr_Constants (Prefix (Nod));
2710 when N_Indexed_Component =>
2711 Check_Expr_Constants (Prefix (Nod));
2712 Check_List_Constants (Expressions (Nod));
2715 Check_Expr_Constants (Prefix (Nod));
2716 Check_Expr_Constants (Discrete_Range (Nod));
2718 when N_Selected_Component =>
2719 Check_Expr_Constants (Prefix (Nod));
2721 when N_Attribute_Reference =>
2723 if Attribute_Name (Nod) = Name_Address
2725 Attribute_Name (Nod) = Name_Access
2727 Attribute_Name (Nod) = Name_Unchecked_Access
2729 Attribute_Name (Nod) = Name_Unrestricted_Access
2731 Check_At_Constant_Address (Prefix (Nod));
2734 Check_Expr_Constants (Prefix (Nod));
2735 Check_List_Constants (Expressions (Nod));
2739 Check_List_Constants (Component_Associations (Nod));
2740 Check_List_Constants (Expressions (Nod));
2742 when N_Component_Association =>
2743 Check_Expr_Constants (Expression (Nod));
2745 when N_Extension_Aggregate =>
2746 Check_Expr_Constants (Ancestor_Part (Nod));
2747 Check_List_Constants (Component_Associations (Nod));
2748 Check_List_Constants (Expressions (Nod));
2753 when N_Binary_Op | N_And_Then | N_Or_Else | N_In | N_Not_In =>
2754 Check_Expr_Constants (Left_Opnd (Nod));
2755 Check_Expr_Constants (Right_Opnd (Nod));
2758 Check_Expr_Constants (Right_Opnd (Nod));
2760 when N_Type_Conversion |
2761 N_Qualified_Expression |
2763 Check_Expr_Constants (Expression (Nod));
2765 when N_Unchecked_Type_Conversion =>
2766 Check_Expr_Constants (Expression (Nod));
2768 -- If this is a rewritten unchecked conversion, subtypes
2769 -- in this node are those created within the instance.
2770 -- To avoid order of elaboration issues, replace them
2771 -- with their base types. Note that address clauses can
2772 -- cause order of elaboration problems because they are
2773 -- elaborated by the back-end at the point of definition,
2774 -- and may mention entities declared in between (as long
2775 -- as everything is static). It is user-friendly to allow
2776 -- unchecked conversions in this context.
2778 if Nkind (Original_Node (Nod)) = N_Function_Call then
2779 Set_Etype (Expression (Nod),
2780 Base_Type (Etype (Expression (Nod))));
2781 Set_Etype (Nod, Base_Type (Etype (Nod)));
2784 when N_Function_Call =>
2785 if not Is_Pure (Entity (Name (Nod))) then
2787 ("invalid address clause for initialized object &!",
2791 ("\function & is not pure ('R'M 13.1(22))!",
2792 Nod, Entity (Name (Nod)));
2795 Check_List_Constants (Parameter_Associations (Nod));
2798 when N_Parameter_Association =>
2799 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
2803 ("invalid address clause for initialized object &!",
2806 ("\must be constant defined before& ('R'M 13.1(22))!",
2809 end Check_Expr_Constants;
2811 --------------------------
2812 -- Check_List_Constants --
2813 --------------------------
2815 procedure Check_List_Constants (Lst : List_Id) is
2819 if Present (Lst) then
2820 Nod1 := First (Lst);
2821 while Present (Nod1) loop
2822 Check_Expr_Constants (Nod1);
2826 end Check_List_Constants;
2828 -- Start of processing for Check_Constant_Address_Clause
2831 Check_Expr_Constants (Expr);
2832 end Check_Constant_Address_Clause;
2838 procedure Check_Size
2842 Biased : out Boolean)
2844 UT : constant Entity_Id := Underlying_Type (T);
2850 -- Dismiss cases for generic types or types with previous errors
2853 or else UT = Any_Type
2854 or else Is_Generic_Type (UT)
2855 or else Is_Generic_Type (Root_Type (UT))
2859 -- Check case of bit packed array
2861 elsif Is_Array_Type (UT)
2862 and then Known_Static_Component_Size (UT)
2863 and then Is_Bit_Packed_Array (UT)
2871 Asiz := Component_Size (UT);
2872 Indx := First_Index (UT);
2874 Ityp := Etype (Indx);
2876 -- If non-static bound, then we are not in the business of
2877 -- trying to check the length, and indeed an error will be
2878 -- issued elsewhere, since sizes of non-static array types
2879 -- cannot be set implicitly or explicitly.
2881 if not Is_Static_Subtype (Ityp) then
2885 -- Otherwise accumulate next dimension
2887 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
2888 Expr_Value (Type_Low_Bound (Ityp)) +
2892 exit when No (Indx);
2898 Error_Msg_Uint_1 := Asiz;
2900 ("size for& too small, minimum allowed is ^", N, T);
2904 -- All other composite types are ignored
2906 elsif Is_Composite_Type (UT) then
2909 -- For fixed-point types, don't check minimum if type is not frozen,
2910 -- since we don't know all the characteristics of the type that can
2911 -- affect the size (e.g. a specified small) till freeze time.
2913 elsif Is_Fixed_Point_Type (UT)
2914 and then not Is_Frozen (UT)
2918 -- Cases for which a minimum check is required
2921 -- Ignore if specified size is correct for the type
2923 if Known_Esize (UT) and then Siz = Esize (UT) then
2927 -- Otherwise get minimum size
2929 M := UI_From_Int (Minimum_Size (UT));
2933 -- Size is less than minimum size, but one possibility remains
2934 -- that we can manage with the new size if we bias the type
2936 M := UI_From_Int (Minimum_Size (UT, Biased => True));
2939 Error_Msg_Uint_1 := M;
2941 ("size for& too small, minimum allowed is ^", N, T);
2949 -------------------------
2950 -- Get_Alignment_Value --
2951 -------------------------
2953 function Get_Alignment_Value (Expr : Node_Id) return Uint is
2954 Align : constant Uint := Static_Integer (Expr);
2957 if Align = No_Uint then
2960 elsif Align <= 0 then
2961 Error_Msg_N ("alignment value must be positive", Expr);
2965 for J in Int range 0 .. 64 loop
2967 M : constant Uint := Uint_2 ** J;
2970 exit when M = Align;
2974 ("alignment value must be power of 2", Expr);
2982 end Get_Alignment_Value;
2988 procedure Initialize is
2990 Unchecked_Conversions.Init;
2993 -------------------------
2994 -- Is_Operational_Item --
2995 -------------------------
2997 function Is_Operational_Item (N : Node_Id) return Boolean is
2999 if Nkind (N) /= N_Attribute_Definition_Clause then
3003 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
3006 return Id = Attribute_Input
3007 or else Id = Attribute_Output
3008 or else Id = Attribute_Read
3009 or else Id = Attribute_Write
3010 or else Id = Attribute_External_Tag;
3013 end Is_Operational_Item;
3015 --------------------------------------
3016 -- Mark_Aliased_Address_As_Volatile --
3017 --------------------------------------
3019 procedure Mark_Aliased_Address_As_Volatile (N : Node_Id) is
3020 Ent : constant Entity_Id := Address_Aliased_Entity (N);
3023 if Present (Ent) then
3024 Set_Treat_As_Volatile (Ent);
3026 end Mark_Aliased_Address_As_Volatile;
3032 function Minimum_Size
3034 Biased : Boolean := False)
3037 Lo : Uint := No_Uint;
3038 Hi : Uint := No_Uint;
3039 LoR : Ureal := No_Ureal;
3040 HiR : Ureal := No_Ureal;
3041 LoSet : Boolean := False;
3042 HiSet : Boolean := False;
3046 R_Typ : constant Entity_Id := Root_Type (T);
3049 -- If bad type, return 0
3051 if T = Any_Type then
3054 -- For generic types, just return zero. There cannot be any legitimate
3055 -- need to know such a size, but this routine may be called with a
3056 -- generic type as part of normal processing.
3058 elsif Is_Generic_Type (R_Typ)
3059 or else R_Typ = Any_Type
3065 elsif Is_Access_Type (T) then
3066 return System_Address_Size;
3068 -- Floating-point types
3070 elsif Is_Floating_Point_Type (T) then
3071 return UI_To_Int (Esize (R_Typ));
3075 elsif Is_Discrete_Type (T) then
3077 -- The following loop is looking for the nearest compile time
3078 -- known bounds following the ancestor subtype chain. The idea
3079 -- is to find the most restrictive known bounds information.
3083 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
3088 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
3089 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
3096 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
3097 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
3103 Ancest := Ancestor_Subtype (Ancest);
3106 Ancest := Base_Type (T);
3108 if Is_Generic_Type (Ancest) then
3114 -- Fixed-point types. We can't simply use Expr_Value to get the
3115 -- Corresponding_Integer_Value values of the bounds, since these
3116 -- do not get set till the type is frozen, and this routine can
3117 -- be called before the type is frozen. Similarly the test for
3118 -- bounds being static needs to include the case where we have
3119 -- unanalyzed real literals for the same reason.
3121 elsif Is_Fixed_Point_Type (T) then
3123 -- The following loop is looking for the nearest compile time
3124 -- known bounds following the ancestor subtype chain. The idea
3125 -- is to find the most restrictive known bounds information.
3129 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
3134 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
3135 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
3137 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
3144 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
3145 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
3147 HiR := Expr_Value_R (Type_High_Bound (Ancest));
3153 Ancest := Ancestor_Subtype (Ancest);
3156 Ancest := Base_Type (T);
3158 if Is_Generic_Type (Ancest) then
3164 Lo := UR_To_Uint (LoR / Small_Value (T));
3165 Hi := UR_To_Uint (HiR / Small_Value (T));
3167 -- No other types allowed
3170 raise Program_Error;
3173 -- Fall through with Hi and Lo set. Deal with biased case.
3175 if (Biased and then not Is_Fixed_Point_Type (T))
3176 or else Has_Biased_Representation (T)
3182 -- Signed case. Note that we consider types like range 1 .. -1 to be
3183 -- signed for the purpose of computing the size, since the bounds
3184 -- have to be accomodated in the base type.
3186 if Lo < 0 or else Hi < 0 then
3190 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3191 -- Note that we accommodate the case where the bounds cross. This
3192 -- can happen either because of the way the bounds are declared
3193 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3207 -- If both bounds are positive, make sure that both are represen-
3208 -- table in the case where the bounds are crossed. This can happen
3209 -- either because of the way the bounds are declared, or because of
3210 -- the algorithm in Freeze_Fixed_Point_Type.
3216 -- S = size, (can accommodate 0 .. (2**size - 1))
3219 while Hi >= Uint_2 ** S loop
3227 -------------------------
3228 -- New_Stream_Function --
3229 -------------------------
3231 procedure New_Stream_Function
3235 Nam : TSS_Name_Type)
3237 Loc : constant Source_Ptr := Sloc (N);
3238 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
3239 Subp_Id : Entity_Id;
3240 Subp_Decl : Node_Id;
3244 function Build_Spec return Node_Id;
3245 -- Used for declaration and renaming declaration, so that this is
3246 -- treated as a renaming_as_body.
3252 function Build_Spec return Node_Id is
3254 Subp_Id := Make_Defining_Identifier (Loc, Sname);
3257 Make_Function_Specification (Loc,
3258 Defining_Unit_Name => Subp_Id,
3259 Parameter_Specifications =>
3261 Make_Parameter_Specification (Loc,
3262 Defining_Identifier =>
3263 Make_Defining_Identifier (Loc, Name_S),
3265 Make_Access_Definition (Loc,
3268 Designated_Type (Etype (F)), Loc)))),
3271 New_Reference_To (Etyp, Loc));
3274 -- Start of processing for New_Stream_Function
3277 F := First_Formal (Subp);
3278 Etyp := Etype (Subp);
3280 if not Is_Tagged_Type (Ent) then
3282 Make_Subprogram_Declaration (Loc,
3283 Specification => Build_Spec);
3284 Insert_Action (N, Subp_Decl);
3288 Make_Subprogram_Renaming_Declaration (Loc,
3289 Specification => Build_Spec,
3290 Name => New_Reference_To (Subp, Loc));
3292 if Is_Tagged_Type (Ent) and then not Is_Limited_Type (Ent) then
3293 Set_TSS (Base_Type (Ent), Subp_Id);
3295 Insert_Action (N, Subp_Decl);
3296 Copy_TSS (Subp_Id, Base_Type (Ent));
3298 end New_Stream_Function;
3300 --------------------------
3301 -- New_Stream_Procedure --
3302 --------------------------
3304 procedure New_Stream_Procedure
3308 Nam : TSS_Name_Type;
3309 Out_P : Boolean := False)
3311 Loc : constant Source_Ptr := Sloc (N);
3312 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
3313 Subp_Id : Entity_Id;
3314 Subp_Decl : Node_Id;
3318 function Build_Spec return Node_Id;
3319 -- Used for declaration and renaming declaration, so that this is
3320 -- treated as a renaming_as_body.
3326 function Build_Spec return Node_Id is
3328 Subp_Id := Make_Defining_Identifier (Loc, Sname);
3331 Make_Procedure_Specification (Loc,
3332 Defining_Unit_Name => Subp_Id,
3333 Parameter_Specifications =>
3335 Make_Parameter_Specification (Loc,
3336 Defining_Identifier =>
3337 Make_Defining_Identifier (Loc, Name_S),
3339 Make_Access_Definition (Loc,
3342 Designated_Type (Etype (F)), Loc))),
3344 Make_Parameter_Specification (Loc,
3345 Defining_Identifier =>
3346 Make_Defining_Identifier (Loc, Name_V),
3347 Out_Present => Out_P,
3349 New_Reference_To (Etyp, Loc))));
3352 -- Start of processing for New_Stream_Procedure
3355 F := First_Formal (Subp);
3356 Etyp := Etype (Next_Formal (F));
3358 if not Is_Tagged_Type (Ent) then
3360 Make_Subprogram_Declaration (Loc,
3361 Specification => Build_Spec);
3362 Insert_Action (N, Subp_Decl);
3366 Make_Subprogram_Renaming_Declaration (Loc,
3367 Specification => Build_Spec,
3368 Name => New_Reference_To (Subp, Loc));
3370 if Is_Tagged_Type (Ent) and then not Is_Limited_Type (Ent) then
3371 Set_TSS (Base_Type (Ent), Subp_Id);
3373 Insert_Action (N, Subp_Decl);
3374 Copy_TSS (Subp_Id, Base_Type (Ent));
3376 end New_Stream_Procedure;
3378 ---------------------
3379 -- Record_Rep_Item --
3380 ---------------------
3382 procedure Record_Rep_Item (T : Entity_Id; N : Node_Id) is
3384 Set_Next_Rep_Item (N, First_Rep_Item (T));
3385 Set_First_Rep_Item (T, N);
3386 end Record_Rep_Item;
3388 ------------------------
3389 -- Rep_Item_Too_Early --
3390 ------------------------
3392 function Rep_Item_Too_Early
3398 -- Cannot apply rep items that are not operational items
3401 if Is_Operational_Item (N) then
3405 and then Is_Generic_Type (Root_Type (T))
3408 ("representation item not allowed for generic type", N);
3412 -- Otherwise check for incompleted type
3414 if Is_Incomplete_Or_Private_Type (T)
3415 and then No (Underlying_Type (T))
3418 ("representation item must be after full type declaration", N);
3421 -- If the type has incompleted components, a representation clause is
3422 -- illegal but stream attributes and Convention pragmas are correct.
3424 elsif Has_Private_Component (T) then
3425 if Nkind (N) = N_Pragma then
3429 ("representation item must appear after type is fully defined",
3436 end Rep_Item_Too_Early;
3438 -----------------------
3439 -- Rep_Item_Too_Late --
3440 -----------------------
3442 function Rep_Item_Too_Late
3445 FOnly : Boolean := False)
3449 Parent_Type : Entity_Id;
3452 -- Output the too late message
3454 procedure Too_Late is
3456 Error_Msg_N ("representation item appears too late!", N);
3459 -- Start of processing for Rep_Item_Too_Late
3462 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3463 -- types, which may be frozen if they appear in a representation clause
3464 -- for a local type.
3467 and then not From_With_Type (T)
3470 S := First_Subtype (T);
3472 if Present (Freeze_Node (S)) then
3474 ("?no more representation items for }!", Freeze_Node (S), S);
3479 -- Check for case of non-tagged derived type whose parent either has
3480 -- primitive operations, or is a by reference type (RM 13.1(10)).
3484 and then Is_Derived_Type (T)
3485 and then not Is_Tagged_Type (T)
3487 Parent_Type := Etype (Base_Type (T));
3489 if Has_Primitive_Operations (Parent_Type) then
3492 ("primitive operations already defined for&!", N, Parent_Type);
3495 elsif Is_By_Reference_Type (Parent_Type) then
3498 ("parent type & is a by reference type!", N, Parent_Type);
3503 -- No error, link item into head of chain of rep items for the entity
3505 Record_Rep_Item (T, N);
3507 end Rep_Item_Too_Late;
3509 -------------------------
3510 -- Same_Representation --
3511 -------------------------
3513 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
3514 T1 : constant Entity_Id := Underlying_Type (Typ1);
3515 T2 : constant Entity_Id := Underlying_Type (Typ2);
3518 -- A quick check, if base types are the same, then we definitely have
3519 -- the same representation, because the subtype specific representation
3520 -- attributes (Size and Alignment) do not affect representation from
3521 -- the point of view of this test.
3523 if Base_Type (T1) = Base_Type (T2) then
3526 elsif Is_Private_Type (Base_Type (T2))
3527 and then Base_Type (T1) = Full_View (Base_Type (T2))
3532 -- Tagged types never have differing representations
3534 if Is_Tagged_Type (T1) then
3538 -- Representations are definitely different if conventions differ
3540 if Convention (T1) /= Convention (T2) then
3544 -- Representations are different if component alignments differ
3546 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
3548 (Is_Record_Type (T2) or else Is_Array_Type (T2))
3549 and then Component_Alignment (T1) /= Component_Alignment (T2)
3554 -- For arrays, the only real issue is component size. If we know the
3555 -- component size for both arrays, and it is the same, then that's
3556 -- good enough to know we don't have a change of representation.
3558 if Is_Array_Type (T1) then
3559 if Known_Component_Size (T1)
3560 and then Known_Component_Size (T2)
3561 and then Component_Size (T1) = Component_Size (T2)
3567 -- Types definitely have same representation if neither has non-standard
3568 -- representation since default representations are always consistent.
3569 -- If only one has non-standard representation, and the other does not,
3570 -- then we consider that they do not have the same representation. They
3571 -- might, but there is no way of telling early enough.
3573 if Has_Non_Standard_Rep (T1) then
3574 if not Has_Non_Standard_Rep (T2) then
3578 return not Has_Non_Standard_Rep (T2);
3581 -- Here the two types both have non-standard representation, and we
3582 -- need to determine if they have the same non-standard representation
3584 -- For arrays, we simply need to test if the component sizes are the
3585 -- same. Pragma Pack is reflected in modified component sizes, so this
3586 -- check also deals with pragma Pack.
3588 if Is_Array_Type (T1) then
3589 return Component_Size (T1) = Component_Size (T2);
3591 -- Tagged types always have the same representation, because it is not
3592 -- possible to specify different representations for common fields.
3594 elsif Is_Tagged_Type (T1) then
3597 -- Case of record types
3599 elsif Is_Record_Type (T1) then
3601 -- Packed status must conform
3603 if Is_Packed (T1) /= Is_Packed (T2) then
3606 -- Otherwise we must check components. Typ2 maybe a constrained
3607 -- subtype with fewer components, so we compare the components
3608 -- of the base types.
3611 Record_Case : declare
3612 CD1, CD2 : Entity_Id;
3614 function Same_Rep return Boolean;
3615 -- CD1 and CD2 are either components or discriminants. This
3616 -- function tests whether the two have the same representation
3618 function Same_Rep return Boolean is
3620 if No (Component_Clause (CD1)) then
3621 return No (Component_Clause (CD2));
3625 Present (Component_Clause (CD2))
3627 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
3629 Esize (CD1) = Esize (CD2);
3633 -- Start processing for Record_Case
3636 if Has_Discriminants (T1) then
3637 CD1 := First_Discriminant (T1);
3638 CD2 := First_Discriminant (T2);
3640 -- The number of discriminants may be different if the
3641 -- derived type has fewer (constrained by values). The
3642 -- invisible discriminants retain the representation of
3643 -- the original, so the discrepancy does not per se
3644 -- indicate a different representation.
3647 and then Present (CD2)
3649 if not Same_Rep then
3652 Next_Discriminant (CD1);
3653 Next_Discriminant (CD2);
3658 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
3659 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
3661 while Present (CD1) loop
3662 if not Same_Rep then
3665 Next_Component (CD1);
3666 Next_Component (CD2);
3674 -- For enumeration types, we must check each literal to see if the
3675 -- representation is the same. Note that we do not permit enumeration
3676 -- reprsentation clauses for Character and Wide_Character, so these
3677 -- cases were already dealt with.
3679 elsif Is_Enumeration_Type (T1) then
3681 Enumeration_Case : declare
3685 L1 := First_Literal (T1);
3686 L2 := First_Literal (T2);
3688 while Present (L1) loop
3689 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
3699 end Enumeration_Case;
3701 -- Any other types have the same representation for these purposes
3706 end Same_Representation;
3708 --------------------
3709 -- Set_Enum_Esize --
3710 --------------------
3712 procedure Set_Enum_Esize (T : Entity_Id) is
3720 -- Find the minimum standard size (8,16,32,64) that fits
3722 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
3723 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
3726 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
3727 Sz := Standard_Character_Size; -- May be > 8 on some targets
3729 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
3732 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
3735 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
3740 if Hi < Uint_2**08 then
3741 Sz := Standard_Character_Size; -- May be > 8 on some targets
3743 elsif Hi < Uint_2**16 then
3746 elsif Hi < Uint_2**32 then
3749 else pragma Assert (Hi < Uint_2**63);
3754 -- That minimum is the proper size unless we have a foreign convention
3755 -- and the size required is 32 or less, in which case we bump the size
3756 -- up to 32. This is required for C and C++ and seems reasonable for
3757 -- all other foreign conventions.
3759 if Has_Foreign_Convention (T)
3760 and then Esize (T) < Standard_Integer_Size
3762 Init_Esize (T, Standard_Integer_Size);
3769 -----------------------------------
3770 -- Validate_Unchecked_Conversion --
3771 -----------------------------------
3773 procedure Validate_Unchecked_Conversion
3775 Act_Unit : Entity_Id)
3782 -- Obtain source and target types. Note that we call Ancestor_Subtype
3783 -- here because the processing for generic instantiation always makes
3784 -- subtypes, and we want the original frozen actual types.
3786 -- If we are dealing with private types, then do the check on their
3787 -- fully declared counterparts if the full declarations have been
3788 -- encountered (they don't have to be visible, but they must exist!)
3790 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
3792 if Is_Private_Type (Source)
3793 and then Present (Underlying_Type (Source))
3795 Source := Underlying_Type (Source);
3798 Target := Ancestor_Subtype (Etype (Act_Unit));
3800 -- If either type is generic, the instantiation happens within a
3801 -- generic unit, and there is nothing to check. The proper check
3802 -- will happen when the enclosing generic is instantiated.
3804 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
3808 if Is_Private_Type (Target)
3809 and then Present (Underlying_Type (Target))
3811 Target := Underlying_Type (Target);
3814 -- Source may be unconstrained array, but not target
3816 if Is_Array_Type (Target)
3817 and then not Is_Constrained (Target)
3820 ("unchecked conversion to unconstrained array not allowed", N);
3824 -- Make entry in unchecked conversion table for later processing
3825 -- by Validate_Unchecked_Conversions, which will check sizes and
3826 -- alignments (using values set by the back-end where possible).
3827 -- This is only done if the appropriate warning is active
3829 if Warn_On_Unchecked_Conversion then
3830 Unchecked_Conversions.Append
3831 (New_Val => UC_Entry'
3836 -- If both sizes are known statically now, then back end annotation
3837 -- is not required to do a proper check but if either size is not
3838 -- known statically, then we need the annotation.
3840 if Known_Static_RM_Size (Source)
3841 and then Known_Static_RM_Size (Target)
3845 Back_Annotate_Rep_Info := True;
3849 -- Generate N_Validate_Unchecked_Conversion node for back end if
3850 -- the back end needs to perform special validation checks. At the
3851 -- current time, only the JVM version requires such checks.
3855 Make_Validate_Unchecked_Conversion (Sloc (N));
3856 Set_Source_Type (Vnode, Source);
3857 Set_Target_Type (Vnode, Target);
3858 Insert_After (N, Vnode);
3860 end Validate_Unchecked_Conversion;
3862 ------------------------------------
3863 -- Validate_Unchecked_Conversions --
3864 ------------------------------------
3866 procedure Validate_Unchecked_Conversions is
3868 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
3870 T : UC_Entry renames Unchecked_Conversions.Table (N);
3872 Enode : constant Node_Id := T.Enode;
3873 Source : constant Entity_Id := T.Source;
3874 Target : constant Entity_Id := T.Target;
3880 -- This validation check, which warns if we have unequal sizes
3881 -- for unchecked conversion, and thus potentially implementation
3882 -- dependent semantics, is one of the few occasions on which we
3883 -- use the official RM size instead of Esize. See description
3884 -- in Einfo "Handling of Type'Size Values" for details.
3886 if Serious_Errors_Detected = 0
3887 and then Known_Static_RM_Size (Source)
3888 and then Known_Static_RM_Size (Target)
3890 Source_Siz := RM_Size (Source);
3891 Target_Siz := RM_Size (Target);
3893 if Source_Siz /= Target_Siz then
3895 ("types for unchecked conversion have different sizes?",
3898 if All_Errors_Mode then
3899 Error_Msg_Name_1 := Chars (Source);
3900 Error_Msg_Uint_1 := Source_Siz;
3901 Error_Msg_Name_2 := Chars (Target);
3902 Error_Msg_Uint_2 := Target_Siz;
3904 ("\size of % is ^, size of % is ^?", Enode);
3906 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
3908 if Is_Discrete_Type (Source)
3909 and then Is_Discrete_Type (Target)
3911 if Source_Siz > Target_Siz then
3913 ("\^ high order bits of source will be ignored?",
3916 elsif Is_Unsigned_Type (Source) then
3918 ("\source will be extended with ^ high order " &
3919 "zero bits?", Enode);
3923 ("\source will be extended with ^ high order " &
3928 elsif Source_Siz < Target_Siz then
3929 if Is_Discrete_Type (Target) then
3930 if Bytes_Big_Endian then
3932 ("\target value will include ^ undefined " &
3937 ("\target value will include ^ undefined " &
3944 ("\^ trailing bits of target value will be " &
3945 "undefined?", Enode);
3948 else pragma Assert (Source_Siz > Target_Siz);
3950 ("\^ trailing bits of source will be ignored?",
3957 -- If both types are access types, we need to check the alignment.
3958 -- If the alignment of both is specified, we can do it here.
3960 if Serious_Errors_Detected = 0
3961 and then Ekind (Source) in Access_Kind
3962 and then Ekind (Target) in Access_Kind
3963 and then Target_Strict_Alignment
3964 and then Present (Designated_Type (Source))
3965 and then Present (Designated_Type (Target))
3968 D_Source : constant Entity_Id := Designated_Type (Source);
3969 D_Target : constant Entity_Id := Designated_Type (Target);
3972 if Known_Alignment (D_Source)
3973 and then Known_Alignment (D_Target)
3976 Source_Align : constant Uint := Alignment (D_Source);
3977 Target_Align : constant Uint := Alignment (D_Target);
3980 if Source_Align < Target_Align
3981 and then not Is_Tagged_Type (D_Source)
3983 Error_Msg_Uint_1 := Target_Align;
3984 Error_Msg_Uint_2 := Source_Align;
3985 Error_Msg_Node_2 := D_Source;
3987 ("alignment of & (^) is stricter than " &
3988 "alignment of & (^)?", Enode, D_Target);
3990 if All_Errors_Mode then
3992 ("\resulting access value may have invalid " &
3993 "alignment?", Enode);
4002 end Validate_Unchecked_Conversions;