1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Einfo; use Einfo;
29 with Errout; use Errout;
30 with Exp_Tss; use Exp_Tss;
31 with Exp_Util; use Exp_Util;
33 with Lib.Xref; use Lib.Xref;
34 with Namet; use Namet;
35 with Nlists; use Nlists;
36 with Nmake; use Nmake;
38 with Restrict; use Restrict;
39 with Rident; use Rident;
40 with Rtsfind; use Rtsfind;
42 with Sem_Aux; use Sem_Aux;
43 with Sem_Ch8; use Sem_Ch8;
44 with Sem_Eval; use Sem_Eval;
45 with Sem_Res; use Sem_Res;
46 with Sem_Type; use Sem_Type;
47 with Sem_Util; use Sem_Util;
48 with Sem_Warn; use Sem_Warn;
49 with Snames; use Snames;
50 with Stand; use Stand;
51 with Sinfo; use Sinfo;
53 with Targparm; use Targparm;
54 with Ttypes; use Ttypes;
55 with Tbuild; use Tbuild;
56 with Urealp; use Urealp;
58 with GNAT.Heap_Sort_G;
60 package body Sem_Ch13 is
62 SSU : constant Pos := System_Storage_Unit;
63 -- Convenient short hand for commonly used constant
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id);
70 -- This routine is called after setting the Esize of type entity Typ.
71 -- The purpose is to deal with the situation where an alignment has been
72 -- inherited from a derived type that is no longer appropriate for the
73 -- new Esize value. In this case, we reset the Alignment to unknown.
75 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
76 -- Given two entities for record components or discriminants, checks
77 -- if they have overlapping component clauses and issues errors if so.
79 function Get_Alignment_Value (Expr : Node_Id) return Uint;
80 -- Given the expression for an alignment value, returns the corresponding
81 -- Uint value. If the value is inappropriate, then error messages are
82 -- posted as required, and a value of No_Uint is returned.
84 function Is_Operational_Item (N : Node_Id) return Boolean;
85 -- A specification for a stream attribute is allowed before the full
86 -- type is declared, as explained in AI-00137 and the corrigendum.
87 -- Attributes that do not specify a representation characteristic are
88 -- operational attributes.
90 procedure New_Stream_Subprogram
95 -- Create a subprogram renaming of a given stream attribute to the
96 -- designated subprogram and then in the tagged case, provide this as a
97 -- primitive operation, or in the non-tagged case make an appropriate TSS
98 -- entry. This is more properly an expansion activity than just semantics,
99 -- but the presence of user-defined stream functions for limited types is a
100 -- legality check, which is why this takes place here rather than in
101 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
102 -- function to be generated.
104 -- To avoid elaboration anomalies with freeze nodes, for untagged types
105 -- we generate both a subprogram declaration and a subprogram renaming
106 -- declaration, so that the attribute specification is handled as a
107 -- renaming_as_body. For tagged types, the specification is one of the
110 ----------------------------------------------
111 -- Table for Validate_Unchecked_Conversions --
112 ----------------------------------------------
114 -- The following table collects unchecked conversions for validation.
115 -- Entries are made by Validate_Unchecked_Conversion and then the
116 -- call to Validate_Unchecked_Conversions does the actual error
117 -- checking and posting of warnings. The reason for this delayed
118 -- processing is to take advantage of back-annotations of size and
119 -- alignment values performed by the back end.
121 -- Note: the reason we store a Source_Ptr value instead of a Node_Id
122 -- is that by the time Validate_Unchecked_Conversions is called, Sprint
123 -- will already have modified all Sloc values if the -gnatD option is set.
125 type UC_Entry is record
126 Eloc : Source_Ptr; -- node used for posting warnings
127 Source : Entity_Id; -- source type for unchecked conversion
128 Target : Entity_Id; -- target type for unchecked conversion
131 package Unchecked_Conversions is new Table.Table (
132 Table_Component_Type => UC_Entry,
133 Table_Index_Type => Int,
134 Table_Low_Bound => 1,
136 Table_Increment => 200,
137 Table_Name => "Unchecked_Conversions");
139 ----------------------------------------
140 -- Table for Validate_Address_Clauses --
141 ----------------------------------------
143 -- If an address clause has the form
145 -- for X'Address use Expr
147 -- where Expr is of the form Y'Address or recursively is a reference
148 -- to a constant of either of these forms, and X and Y are entities of
149 -- objects, then if Y has a smaller alignment than X, that merits a
150 -- warning about possible bad alignment. The following table collects
151 -- address clauses of this kind. We put these in a table so that they
152 -- can be checked after the back end has completed annotation of the
153 -- alignments of objects, since we can catch more cases that way.
155 type Address_Clause_Check_Record is record
157 -- The address clause
160 -- The entity of the object overlaying Y
163 -- The entity of the object being overlaid
166 -- Whether the address is offseted within Y
169 package Address_Clause_Checks is new Table.Table (
170 Table_Component_Type => Address_Clause_Check_Record,
171 Table_Index_Type => Int,
172 Table_Low_Bound => 1,
174 Table_Increment => 200,
175 Table_Name => "Address_Clause_Checks");
177 -----------------------------------------
178 -- Adjust_Record_For_Reverse_Bit_Order --
179 -----------------------------------------
181 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
182 Max_Machine_Scalar_Size : constant Uint :=
184 (Standard_Long_Long_Integer_Size);
185 -- We use this as the maximum machine scalar size in the sense of AI-133
189 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
192 -- This first loop through components does two things. First it deals
193 -- with the case of components with component clauses whose length is
194 -- greater than the maximum machine scalar size (either accepting them
195 -- or rejecting as needed). Second, it counts the number of components
196 -- with component clauses whose length does not exceed this maximum for
200 Comp := First_Component_Or_Discriminant (R);
201 while Present (Comp) loop
203 CC : constant Node_Id := Component_Clause (Comp);
208 Fbit : constant Uint := Static_Integer (First_Bit (CC));
211 -- Case of component with size > max machine scalar
213 if Esize (Comp) > Max_Machine_Scalar_Size then
215 -- Must begin on byte boundary
217 if Fbit mod SSU /= 0 then
219 ("illegal first bit value for reverse bit order",
221 Error_Msg_Uint_1 := SSU;
222 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
225 ("\must be a multiple of ^ if size greater than ^",
228 -- Must end on byte boundary
230 elsif Esize (Comp) mod SSU /= 0 then
232 ("illegal last bit value for reverse bit order",
234 Error_Msg_Uint_1 := SSU;
235 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
238 ("\must be a multiple of ^ if size greater than ^",
241 -- OK, give warning if enabled
243 elsif Warn_On_Reverse_Bit_Order then
245 ("multi-byte field specified with non-standard"
246 & " Bit_Order?", CC);
248 if Bytes_Big_Endian then
250 ("\bytes are not reversed "
251 & "(component is big-endian)?", CC);
254 ("\bytes are not reversed "
255 & "(component is little-endian)?", CC);
259 -- Case where size is not greater than max machine
260 -- scalar. For now, we just count these.
263 Num_CC := Num_CC + 1;
269 Next_Component_Or_Discriminant (Comp);
272 -- We need to sort the component clauses on the basis of the Position
273 -- values in the clause, so we can group clauses with the same Position.
274 -- together to determine the relevant machine scalar size.
277 Comps : array (0 .. Num_CC) of Entity_Id;
278 -- Array to collect component and discriminant entities. The data
279 -- starts at index 1, the 0'th entry is for the sort routine.
281 function CP_Lt (Op1, Op2 : Natural) return Boolean;
282 -- Compare routine for Sort
284 procedure CP_Move (From : Natural; To : Natural);
285 -- Move routine for Sort
287 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
291 -- Start and stop positions in component list of set of components
292 -- with the same starting position (that constitute components in
293 -- a single machine scalar).
296 -- Maximum last bit value of any component in this set
299 -- Corresponding machine scalar size
305 function CP_Lt (Op1, Op2 : Natural) return Boolean is
307 return Position (Component_Clause (Comps (Op1))) <
308 Position (Component_Clause (Comps (Op2)));
315 procedure CP_Move (From : Natural; To : Natural) is
317 Comps (To) := Comps (From);
321 -- Collect the component clauses
324 Comp := First_Component_Or_Discriminant (R);
325 while Present (Comp) loop
326 if Present (Component_Clause (Comp))
327 and then Esize (Comp) <= Max_Machine_Scalar_Size
329 Num_CC := Num_CC + 1;
330 Comps (Num_CC) := Comp;
333 Next_Component_Or_Discriminant (Comp);
336 -- Sort by ascending position number
338 Sorting.Sort (Num_CC);
340 -- We now have all the components whose size does not exceed the max
341 -- machine scalar value, sorted by starting position. In this loop
342 -- we gather groups of clauses starting at the same position, to
343 -- process them in accordance with Ada 2005 AI-133.
346 while Stop < Num_CC loop
350 Static_Integer (Last_Bit (Component_Clause (Comps (Start))));
351 while Stop < Num_CC loop
353 (Position (Component_Clause (Comps (Stop + 1)))) =
355 (Position (Component_Clause (Comps (Stop))))
362 (Last_Bit (Component_Clause (Comps (Stop)))));
368 -- Now we have a group of component clauses from Start to Stop
369 -- whose positions are identical, and MaxL is the maximum last bit
370 -- value of any of these components.
372 -- We need to determine the corresponding machine scalar size.
373 -- This loop assumes that machine scalar sizes are even, and that
374 -- each possible machine scalar has twice as many bits as the
377 MSS := Max_Machine_Scalar_Size;
379 and then (MSS / 2) >= SSU
380 and then (MSS / 2) > MaxL
385 -- Here is where we fix up the Component_Bit_Offset value to
386 -- account for the reverse bit order. Some examples of what needs
387 -- to be done for the case of a machine scalar size of 8 are:
389 -- First_Bit .. Last_Bit Component_Bit_Offset
401 -- The general rule is that the first bit is obtained by
402 -- subtracting the old ending bit from machine scalar size - 1.
404 for C in Start .. Stop loop
406 Comp : constant Entity_Id := Comps (C);
407 CC : constant Node_Id := Component_Clause (Comp);
408 LB : constant Uint := Static_Integer (Last_Bit (CC));
409 NFB : constant Uint := MSS - Uint_1 - LB;
410 NLB : constant Uint := NFB + Esize (Comp) - 1;
411 Pos : constant Uint := Static_Integer (Position (CC));
414 if Warn_On_Reverse_Bit_Order then
415 Error_Msg_Uint_1 := MSS;
417 ("info: reverse bit order in machine " &
418 "scalar of length^?", First_Bit (CC));
419 Error_Msg_Uint_1 := NFB;
420 Error_Msg_Uint_2 := NLB;
422 if Bytes_Big_Endian then
424 ("?\info: big-endian range for "
425 & "component & is ^ .. ^",
426 First_Bit (CC), Comp);
429 ("?\info: little-endian range "
430 & "for component & is ^ .. ^",
431 First_Bit (CC), Comp);
435 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
436 Set_Normalized_First_Bit (Comp, NFB mod SSU);
441 end Adjust_Record_For_Reverse_Bit_Order;
443 --------------------------------------
444 -- Alignment_Check_For_Esize_Change --
445 --------------------------------------
447 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id) is
449 -- If the alignment is known, and not set by a rep clause, and is
450 -- inconsistent with the size being set, then reset it to unknown,
451 -- we assume in this case that the size overrides the inherited
452 -- alignment, and that the alignment must be recomputed.
454 if Known_Alignment (Typ)
455 and then not Has_Alignment_Clause (Typ)
456 and then Esize (Typ) mod (Alignment (Typ) * SSU) /= 0
458 Init_Alignment (Typ);
460 end Alignment_Check_For_Esize_Change;
462 -----------------------
463 -- Analyze_At_Clause --
464 -----------------------
466 -- An at clause is replaced by the corresponding Address attribute
467 -- definition clause that is the preferred approach in Ada 95.
469 procedure Analyze_At_Clause (N : Node_Id) is
470 CS : constant Boolean := Comes_From_Source (N);
473 -- This is an obsolescent feature
475 Check_Restriction (No_Obsolescent_Features, N);
477 if Warn_On_Obsolescent_Feature then
479 ("at clause is an obsolescent feature (RM J.7(2))?", N);
481 ("\use address attribute definition clause instead?", N);
484 -- Rewrite as address clause
487 Make_Attribute_Definition_Clause (Sloc (N),
488 Name => Identifier (N),
489 Chars => Name_Address,
490 Expression => Expression (N)));
492 -- We preserve Comes_From_Source, since logically the clause still
493 -- comes from the source program even though it is changed in form.
495 Set_Comes_From_Source (N, CS);
497 -- Analyze rewritten clause
499 Analyze_Attribute_Definition_Clause (N);
500 end Analyze_At_Clause;
502 -----------------------------------------
503 -- Analyze_Attribute_Definition_Clause --
504 -----------------------------------------
506 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
507 Loc : constant Source_Ptr := Sloc (N);
508 Nam : constant Node_Id := Name (N);
509 Attr : constant Name_Id := Chars (N);
510 Expr : constant Node_Id := Expression (N);
511 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
515 FOnly : Boolean := False;
516 -- Reset to True for subtype specific attribute (Alignment, Size)
517 -- and for stream attributes, i.e. those cases where in the call
518 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
519 -- rules are checked. Note that the case of stream attributes is not
520 -- clear from the RM, but see AI95-00137. Also, the RM seems to
521 -- disallow Storage_Size for derived task types, but that is also
522 -- clearly unintentional.
524 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
525 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
526 -- definition clauses.
528 -----------------------------------
529 -- Analyze_Stream_TSS_Definition --
530 -----------------------------------
532 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
533 Subp : Entity_Id := Empty;
538 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
540 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
541 -- Return true if the entity is a subprogram with an appropriate
542 -- profile for the attribute being defined.
544 ----------------------
545 -- Has_Good_Profile --
546 ----------------------
548 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
550 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
551 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
552 (False => E_Procedure, True => E_Function);
556 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
560 F := First_Formal (Subp);
563 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
564 or else Designated_Type (Etype (F)) /=
565 Class_Wide_Type (RTE (RE_Root_Stream_Type))
570 if not Is_Function then
574 Expected_Mode : constant array (Boolean) of Entity_Kind :=
575 (False => E_In_Parameter,
576 True => E_Out_Parameter);
578 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
589 return Base_Type (Typ) = Base_Type (Ent)
590 and then No (Next_Formal (F));
591 end Has_Good_Profile;
593 -- Start of processing for Analyze_Stream_TSS_Definition
598 if not Is_Type (U_Ent) then
599 Error_Msg_N ("local name must be a subtype", Nam);
603 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
605 -- If Pnam is present, it can be either inherited from an ancestor
606 -- type (in which case it is legal to redefine it for this type), or
607 -- be a previous definition of the attribute for the same type (in
608 -- which case it is illegal).
610 -- In the first case, it will have been analyzed already, and we
611 -- can check that its profile does not match the expected profile
612 -- for a stream attribute of U_Ent. In the second case, either Pnam
613 -- has been analyzed (and has the expected profile), or it has not
614 -- been analyzed yet (case of a type that has not been frozen yet
615 -- and for which the stream attribute has been set using Set_TSS).
618 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
620 Error_Msg_Sloc := Sloc (Pnam);
621 Error_Msg_Name_1 := Attr;
622 Error_Msg_N ("% attribute already defined #", Nam);
628 if Is_Entity_Name (Expr) then
629 if not Is_Overloaded (Expr) then
630 if Has_Good_Profile (Entity (Expr)) then
631 Subp := Entity (Expr);
635 Get_First_Interp (Expr, I, It);
636 while Present (It.Nam) loop
637 if Has_Good_Profile (It.Nam) then
642 Get_Next_Interp (I, It);
647 if Present (Subp) then
648 if Is_Abstract_Subprogram (Subp) then
649 Error_Msg_N ("stream subprogram must not be abstract", Expr);
653 Set_Entity (Expr, Subp);
654 Set_Etype (Expr, Etype (Subp));
656 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
659 Error_Msg_Name_1 := Attr;
660 Error_Msg_N ("incorrect expression for% attribute", Expr);
662 end Analyze_Stream_TSS_Definition;
664 -- Start of processing for Analyze_Attribute_Definition_Clause
667 -- Process Ignore_Rep_Clauses option
669 if Ignore_Rep_Clauses then
672 -- The following should be ignored. They do not affect legality
673 -- and may be target dependent. The basic idea of -gnatI is to
674 -- ignore any rep clauses that may be target dependent but do not
675 -- affect legality (except possibly to be rejected because they
676 -- are incompatible with the compilation target).
678 when Attribute_Alignment |
679 Attribute_Bit_Order |
680 Attribute_Component_Size |
681 Attribute_Machine_Radix |
682 Attribute_Object_Size |
685 Attribute_Stream_Size |
686 Attribute_Value_Size =>
688 Rewrite (N, Make_Null_Statement (Sloc (N)));
691 -- The following should not be ignored, because in the first place
692 -- they are reasonably portable, and should not cause problems in
693 -- compiling code from another target, and also they do affect
694 -- legality, e.g. failing to provide a stream attribute for a
695 -- type may make a program illegal.
697 when Attribute_External_Tag |
701 Attribute_Storage_Pool |
702 Attribute_Storage_Size |
706 -- Other cases are errors, which will be caught below
716 if Rep_Item_Too_Early (Ent, N) then
720 -- Rep clause applies to full view of incomplete type or private type if
721 -- we have one (if not, this is a premature use of the type). However,
722 -- certain semantic checks need to be done on the specified entity (i.e.
723 -- the private view), so we save it in Ent.
725 if Is_Private_Type (Ent)
726 and then Is_Derived_Type (Ent)
727 and then not Is_Tagged_Type (Ent)
728 and then No (Full_View (Ent))
730 -- If this is a private type whose completion is a derivation from
731 -- another private type, there is no full view, and the attribute
732 -- belongs to the type itself, not its underlying parent.
736 elsif Ekind (Ent) = E_Incomplete_Type then
738 -- The attribute applies to the full view, set the entity of the
739 -- attribute definition accordingly.
741 Ent := Underlying_Type (Ent);
743 Set_Entity (Nam, Ent);
746 U_Ent := Underlying_Type (Ent);
749 -- Complete other routine error checks
751 if Etype (Nam) = Any_Type then
754 elsif Scope (Ent) /= Current_Scope then
755 Error_Msg_N ("entity must be declared in this scope", Nam);
758 elsif No (U_Ent) then
761 elsif Is_Type (U_Ent)
762 and then not Is_First_Subtype (U_Ent)
763 and then Id /= Attribute_Object_Size
764 and then Id /= Attribute_Value_Size
765 and then not From_At_Mod (N)
767 Error_Msg_N ("cannot specify attribute for subtype", Nam);
771 -- Switch on particular attribute
779 -- Address attribute definition clause
781 when Attribute_Address => Address : begin
783 -- A little error check, catch for X'Address use X'Address;
785 if Nkind (Nam) = N_Identifier
786 and then Nkind (Expr) = N_Attribute_Reference
787 and then Attribute_Name (Expr) = Name_Address
788 and then Nkind (Prefix (Expr)) = N_Identifier
789 and then Chars (Nam) = Chars (Prefix (Expr))
792 ("address for & is self-referencing", Prefix (Expr), Ent);
796 -- Not that special case, carry on with analysis of expression
798 Analyze_And_Resolve (Expr, RTE (RE_Address));
800 -- Even when ignoring rep clauses we need to indicate that the
801 -- entity has an address clause and thus it is legal to declare
804 if Ignore_Rep_Clauses then
805 if Ekind (U_Ent) = E_Variable
806 or else Ekind (U_Ent) = E_Constant
808 Record_Rep_Item (U_Ent, N);
814 if Present (Address_Clause (U_Ent)) then
815 Error_Msg_N ("address already given for &", Nam);
817 -- Case of address clause for subprogram
819 elsif Is_Subprogram (U_Ent) then
820 if Has_Homonym (U_Ent) then
822 ("address clause cannot be given " &
823 "for overloaded subprogram",
828 -- For subprograms, all address clauses are permitted, and we
829 -- mark the subprogram as having a deferred freeze so that Gigi
830 -- will not elaborate it too soon.
832 -- Above needs more comments, what is too soon about???
834 Set_Has_Delayed_Freeze (U_Ent);
836 -- Case of address clause for entry
838 elsif Ekind (U_Ent) = E_Entry then
839 if Nkind (Parent (N)) = N_Task_Body then
841 ("entry address must be specified in task spec", Nam);
845 -- For entries, we require a constant address
847 Check_Constant_Address_Clause (Expr, U_Ent);
849 -- Special checks for task types
851 if Is_Task_Type (Scope (U_Ent))
852 and then Comes_From_Source (Scope (U_Ent))
855 ("?entry address declared for entry in task type", N);
857 ("\?only one task can be declared of this type", N);
860 -- Entry address clauses are obsolescent
862 Check_Restriction (No_Obsolescent_Features, N);
864 if Warn_On_Obsolescent_Feature then
866 ("attaching interrupt to task entry is an " &
867 "obsolescent feature (RM J.7.1)?", N);
869 ("\use interrupt procedure instead?", N);
872 -- Case of an address clause for a controlled object which we
873 -- consider to be erroneous.
875 elsif Is_Controlled (Etype (U_Ent))
876 or else Has_Controlled_Component (Etype (U_Ent))
879 ("?controlled object& must not be overlaid", Nam, U_Ent);
881 ("\?Program_Error will be raised at run time", Nam);
882 Insert_Action (Declaration_Node (U_Ent),
883 Make_Raise_Program_Error (Loc,
884 Reason => PE_Overlaid_Controlled_Object));
887 -- Case of address clause for a (non-controlled) object
890 Ekind (U_Ent) = E_Variable
892 Ekind (U_Ent) = E_Constant
895 Expr : constant Node_Id := Expression (N);
900 -- Exported variables cannot have an address clause, because
901 -- this cancels the effect of the pragma Export.
903 if Is_Exported (U_Ent) then
905 ("cannot export object with address clause", Nam);
909 Find_Overlaid_Entity (N, O_Ent, Off);
911 -- Overlaying controlled objects is erroneous
914 and then (Has_Controlled_Component (Etype (O_Ent))
915 or else Is_Controlled (Etype (O_Ent)))
918 ("?cannot overlay with controlled object", Expr);
920 ("\?Program_Error will be raised at run time", Expr);
921 Insert_Action (Declaration_Node (U_Ent),
922 Make_Raise_Program_Error (Loc,
923 Reason => PE_Overlaid_Controlled_Object));
926 elsif Present (O_Ent)
927 and then Ekind (U_Ent) = E_Constant
928 and then not Is_Constant_Object (O_Ent)
930 Error_Msg_N ("constant overlays a variable?", Expr);
932 elsif Present (Renamed_Object (U_Ent)) then
934 ("address clause not allowed"
935 & " for a renaming declaration (RM 13.1(6))", Nam);
938 -- Imported variables can have an address clause, but then
939 -- the import is pretty meaningless except to suppress
940 -- initializations, so we do not need such variables to
941 -- be statically allocated (and in fact it causes trouble
942 -- if the address clause is a local value).
944 elsif Is_Imported (U_Ent) then
945 Set_Is_Statically_Allocated (U_Ent, False);
948 -- We mark a possible modification of a variable with an
949 -- address clause, since it is likely aliasing is occurring.
951 Note_Possible_Modification (Nam, Sure => False);
953 -- Here we are checking for explicit overlap of one variable
954 -- by another, and if we find this then mark the overlapped
955 -- variable as also being volatile to prevent unwanted
956 -- optimizations. This is a significant pessimization so
957 -- avoid it when there is an offset, i.e. when the object
958 -- is composite; they cannot be optimized easily anyway.
961 and then Is_Object (O_Ent)
964 Set_Treat_As_Volatile (O_Ent);
967 -- Legality checks on the address clause for initialized
968 -- objects is deferred until the freeze point, because
969 -- a subsequent pragma might indicate that the object is
970 -- imported and thus not initialized.
972 Set_Has_Delayed_Freeze (U_Ent);
974 -- If an initialization call has been generated for this
975 -- object, it needs to be deferred to after the freeze node
976 -- we have just now added, otherwise GIGI will see a
977 -- reference to the variable (as actual to the IP call)
978 -- before its definition.
981 Init_Call : constant Node_Id := Find_Init_Call (U_Ent, N);
983 if Present (Init_Call) then
985 Append_Freeze_Action (U_Ent, Init_Call);
989 if Is_Exported (U_Ent) then
991 ("& cannot be exported if an address clause is given",
994 ("\define and export a variable " &
995 "that holds its address instead",
999 -- Entity has delayed freeze, so we will generate an
1000 -- alignment check at the freeze point unless suppressed.
1002 if not Range_Checks_Suppressed (U_Ent)
1003 and then not Alignment_Checks_Suppressed (U_Ent)
1005 Set_Check_Address_Alignment (N);
1008 -- Kill the size check code, since we are not allocating
1009 -- the variable, it is somewhere else.
1011 Kill_Size_Check_Code (U_Ent);
1013 -- If the address clause is of the form:
1015 -- for Y'Address use X'Address
1019 -- Const : constant Address := X'Address;
1021 -- for Y'Address use Const;
1023 -- then we make an entry in the table for checking the size
1024 -- and alignment of the overlaying variable. We defer this
1025 -- check till after code generation to take full advantage
1026 -- of the annotation done by the back end. This entry is
1027 -- only made if the address clause comes from source.
1029 if Address_Clause_Overlay_Warnings
1030 and then Comes_From_Source (N)
1031 and then Present (O_Ent)
1032 and then Is_Object (O_Ent)
1034 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
1036 -- If variable overlays a constant view, and we are
1037 -- warning on overlays, then mark the variable as
1038 -- overlaying a constant (we will give warnings later
1039 -- if this variable is assigned).
1041 if Is_Constant_Object (O_Ent)
1042 and then Ekind (U_Ent) = E_Variable
1044 Set_Overlays_Constant (U_Ent);
1049 -- Not a valid entity for an address clause
1052 Error_Msg_N ("address cannot be given for &", Nam);
1060 -- Alignment attribute definition clause
1062 when Attribute_Alignment => Alignment_Block : declare
1063 Align : constant Uint := Get_Alignment_Value (Expr);
1068 if not Is_Type (U_Ent)
1069 and then Ekind (U_Ent) /= E_Variable
1070 and then Ekind (U_Ent) /= E_Constant
1072 Error_Msg_N ("alignment cannot be given for &", Nam);
1074 elsif Has_Alignment_Clause (U_Ent) then
1075 Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
1076 Error_Msg_N ("alignment clause previously given#", N);
1078 elsif Align /= No_Uint then
1079 Set_Has_Alignment_Clause (U_Ent);
1080 Set_Alignment (U_Ent, Align);
1082 end Alignment_Block;
1088 -- Bit_Order attribute definition clause
1090 when Attribute_Bit_Order => Bit_Order : declare
1092 if not Is_Record_Type (U_Ent) then
1094 ("Bit_Order can only be defined for record type", Nam);
1097 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
1099 if Etype (Expr) = Any_Type then
1102 elsif not Is_Static_Expression (Expr) then
1103 Flag_Non_Static_Expr
1104 ("Bit_Order requires static expression!", Expr);
1107 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
1108 Set_Reverse_Bit_Order (U_Ent, True);
1114 --------------------
1115 -- Component_Size --
1116 --------------------
1118 -- Component_Size attribute definition clause
1120 when Attribute_Component_Size => Component_Size_Case : declare
1121 Csize : constant Uint := Static_Integer (Expr);
1124 New_Ctyp : Entity_Id;
1128 if not Is_Array_Type (U_Ent) then
1129 Error_Msg_N ("component size requires array type", Nam);
1133 Btype := Base_Type (U_Ent);
1135 if Has_Component_Size_Clause (Btype) then
1137 ("component size clause for& previously given", Nam);
1139 elsif Csize /= No_Uint then
1140 Check_Size (Expr, Component_Type (Btype), Csize, Biased);
1142 if Has_Aliased_Components (Btype)
1145 and then Csize /= 16
1148 ("component size incorrect for aliased components", N);
1152 -- For the biased case, build a declaration for a subtype
1153 -- that will be used to represent the biased subtype that
1154 -- reflects the biased representation of components. We need
1155 -- this subtype to get proper conversions on referencing
1156 -- elements of the array. Note that component size clauses
1157 -- are ignored in VM mode.
1159 if VM_Target = No_VM then
1162 Make_Defining_Identifier (Loc,
1164 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
1167 Make_Subtype_Declaration (Loc,
1168 Defining_Identifier => New_Ctyp,
1169 Subtype_Indication =>
1170 New_Occurrence_Of (Component_Type (Btype), Loc));
1172 Set_Parent (Decl, N);
1173 Analyze (Decl, Suppress => All_Checks);
1175 Set_Has_Delayed_Freeze (New_Ctyp, False);
1176 Set_Esize (New_Ctyp, Csize);
1177 Set_RM_Size (New_Ctyp, Csize);
1178 Init_Alignment (New_Ctyp);
1179 Set_Has_Biased_Representation (New_Ctyp, True);
1180 Set_Is_Itype (New_Ctyp, True);
1181 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
1183 Set_Component_Type (Btype, New_Ctyp);
1185 if Warn_On_Biased_Representation then
1187 ("?component size clause forces biased "
1188 & "representation", N);
1192 Set_Component_Size (Btype, Csize);
1194 -- For VM case, we ignore component size clauses
1197 -- Give a warning unless we are in GNAT mode, in which case
1198 -- the warning is suppressed since it is not useful.
1200 if not GNAT_Mode then
1202 ("?component size ignored in this configuration", N);
1206 Set_Has_Component_Size_Clause (Btype, True);
1207 Set_Has_Non_Standard_Rep (Btype, True);
1209 end Component_Size_Case;
1215 when Attribute_External_Tag => External_Tag :
1217 if not Is_Tagged_Type (U_Ent) then
1218 Error_Msg_N ("should be a tagged type", Nam);
1221 Analyze_And_Resolve (Expr, Standard_String);
1223 if not Is_Static_Expression (Expr) then
1224 Flag_Non_Static_Expr
1225 ("static string required for tag name!", Nam);
1228 if VM_Target = No_VM then
1229 Set_Has_External_Tag_Rep_Clause (U_Ent);
1231 Error_Msg_Name_1 := Attr;
1233 ("% attribute unsupported in this configuration", Nam);
1236 if not Is_Library_Level_Entity (U_Ent) then
1238 ("?non-unique external tag supplied for &", N, U_Ent);
1240 ("?\same external tag applies to all subprogram calls", N);
1242 ("?\corresponding internal tag cannot be obtained", N);
1250 when Attribute_Input =>
1251 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
1252 Set_Has_Specified_Stream_Input (Ent);
1258 -- Machine radix attribute definition clause
1260 when Attribute_Machine_Radix => Machine_Radix : declare
1261 Radix : constant Uint := Static_Integer (Expr);
1264 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
1265 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
1267 elsif Has_Machine_Radix_Clause (U_Ent) then
1268 Error_Msg_Sloc := Sloc (Alignment_Clause (U_Ent));
1269 Error_Msg_N ("machine radix clause previously given#", N);
1271 elsif Radix /= No_Uint then
1272 Set_Has_Machine_Radix_Clause (U_Ent);
1273 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
1277 elsif Radix = 10 then
1278 Set_Machine_Radix_10 (U_Ent);
1280 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
1289 -- Object_Size attribute definition clause
1291 when Attribute_Object_Size => Object_Size : declare
1292 Size : constant Uint := Static_Integer (Expr);
1295 pragma Warnings (Off, Biased);
1298 if not Is_Type (U_Ent) then
1299 Error_Msg_N ("Object_Size cannot be given for &", Nam);
1301 elsif Has_Object_Size_Clause (U_Ent) then
1302 Error_Msg_N ("Object_Size already given for &", Nam);
1305 Check_Size (Expr, U_Ent, Size, Biased);
1313 UI_Mod (Size, 64) /= 0
1316 ("Object_Size must be 8, 16, 32, or multiple of 64",
1320 Set_Esize (U_Ent, Size);
1321 Set_Has_Object_Size_Clause (U_Ent);
1322 Alignment_Check_For_Esize_Change (U_Ent);
1330 when Attribute_Output =>
1331 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
1332 Set_Has_Specified_Stream_Output (Ent);
1338 when Attribute_Read =>
1339 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
1340 Set_Has_Specified_Stream_Read (Ent);
1346 -- Size attribute definition clause
1348 when Attribute_Size => Size : declare
1349 Size : constant Uint := Static_Integer (Expr);
1356 if Has_Size_Clause (U_Ent) then
1357 Error_Msg_N ("size already given for &", Nam);
1359 elsif not Is_Type (U_Ent)
1360 and then Ekind (U_Ent) /= E_Variable
1361 and then Ekind (U_Ent) /= E_Constant
1363 Error_Msg_N ("size cannot be given for &", Nam);
1365 elsif Is_Array_Type (U_Ent)
1366 and then not Is_Constrained (U_Ent)
1369 ("size cannot be given for unconstrained array", Nam);
1371 elsif Size /= No_Uint then
1372 if Is_Type (U_Ent) then
1375 Etyp := Etype (U_Ent);
1378 -- Check size, note that Gigi is in charge of checking that the
1379 -- size of an array or record type is OK. Also we do not check
1380 -- the size in the ordinary fixed-point case, since it is too
1381 -- early to do so (there may be subsequent small clause that
1382 -- affects the size). We can check the size if a small clause
1383 -- has already been given.
1385 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
1386 or else Has_Small_Clause (U_Ent)
1388 Check_Size (Expr, Etyp, Size, Biased);
1389 Set_Has_Biased_Representation (U_Ent, Biased);
1391 if Biased and Warn_On_Biased_Representation then
1393 ("?size clause forces biased representation", N);
1397 -- For types set RM_Size and Esize if possible
1399 if Is_Type (U_Ent) then
1400 Set_RM_Size (U_Ent, Size);
1402 -- For scalar types, increase Object_Size to power of 2, but
1403 -- not less than a storage unit in any case (i.e., normally
1404 -- this means it will be byte addressable).
1406 if Is_Scalar_Type (U_Ent) then
1407 if Size <= System_Storage_Unit then
1408 Init_Esize (U_Ent, System_Storage_Unit);
1409 elsif Size <= 16 then
1410 Init_Esize (U_Ent, 16);
1411 elsif Size <= 32 then
1412 Init_Esize (U_Ent, 32);
1414 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
1417 -- For all other types, object size = value size. The
1418 -- backend will adjust as needed.
1421 Set_Esize (U_Ent, Size);
1424 Alignment_Check_For_Esize_Change (U_Ent);
1426 -- For objects, set Esize only
1429 if Is_Elementary_Type (Etyp) then
1430 if Size /= System_Storage_Unit
1432 Size /= System_Storage_Unit * 2
1434 Size /= System_Storage_Unit * 4
1436 Size /= System_Storage_Unit * 8
1438 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
1439 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
1441 ("size for primitive object must be a power of 2"
1442 & " in the range ^-^", N);
1446 Set_Esize (U_Ent, Size);
1449 Set_Has_Size_Clause (U_Ent);
1457 -- Small attribute definition clause
1459 when Attribute_Small => Small : declare
1460 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
1464 Analyze_And_Resolve (Expr, Any_Real);
1466 if Etype (Expr) = Any_Type then
1469 elsif not Is_Static_Expression (Expr) then
1470 Flag_Non_Static_Expr
1471 ("small requires static expression!", Expr);
1475 Small := Expr_Value_R (Expr);
1477 if Small <= Ureal_0 then
1478 Error_Msg_N ("small value must be greater than zero", Expr);
1484 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
1486 ("small requires an ordinary fixed point type", Nam);
1488 elsif Has_Small_Clause (U_Ent) then
1489 Error_Msg_N ("small already given for &", Nam);
1491 elsif Small > Delta_Value (U_Ent) then
1493 ("small value must not be greater then delta value", Nam);
1496 Set_Small_Value (U_Ent, Small);
1497 Set_Small_Value (Implicit_Base, Small);
1498 Set_Has_Small_Clause (U_Ent);
1499 Set_Has_Small_Clause (Implicit_Base);
1500 Set_Has_Non_Standard_Rep (Implicit_Base);
1508 -- Storage_Pool attribute definition clause
1510 when Attribute_Storage_Pool => Storage_Pool : declare
1515 if Ekind (U_Ent) = E_Access_Subprogram_Type then
1517 ("storage pool cannot be given for access-to-subprogram type",
1521 elsif Ekind (U_Ent) /= E_Access_Type
1522 and then Ekind (U_Ent) /= E_General_Access_Type
1525 ("storage pool can only be given for access types", Nam);
1528 elsif Is_Derived_Type (U_Ent) then
1530 ("storage pool cannot be given for a derived access type",
1533 elsif Has_Storage_Size_Clause (U_Ent) then
1534 Error_Msg_N ("storage size already given for &", Nam);
1537 elsif Present (Associated_Storage_Pool (U_Ent)) then
1538 Error_Msg_N ("storage pool already given for &", Nam);
1543 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
1545 if not Denotes_Variable (Expr) then
1546 Error_Msg_N ("storage pool must be a variable", Expr);
1550 if Nkind (Expr) = N_Type_Conversion then
1551 T := Etype (Expression (Expr));
1556 -- The Stack_Bounded_Pool is used internally for implementing
1557 -- access types with a Storage_Size. Since it only work
1558 -- properly when used on one specific type, we need to check
1559 -- that it is not hijacked improperly:
1560 -- type T is access Integer;
1561 -- for T'Storage_Size use n;
1562 -- type Q is access Float;
1563 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
1565 if RTE_Available (RE_Stack_Bounded_Pool)
1566 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
1568 Error_Msg_N ("non-shareable internal Pool", Expr);
1572 -- If the argument is a name that is not an entity name, then
1573 -- we construct a renaming operation to define an entity of
1574 -- type storage pool.
1576 if not Is_Entity_Name (Expr)
1577 and then Is_Object_Reference (Expr)
1580 Make_Defining_Identifier (Loc,
1581 Chars => New_Internal_Name ('P'));
1584 Rnode : constant Node_Id :=
1585 Make_Object_Renaming_Declaration (Loc,
1586 Defining_Identifier => Pool,
1588 New_Occurrence_Of (Etype (Expr), Loc),
1592 Insert_Before (N, Rnode);
1594 Set_Associated_Storage_Pool (U_Ent, Pool);
1597 elsif Is_Entity_Name (Expr) then
1598 Pool := Entity (Expr);
1600 -- If pool is a renamed object, get original one. This can
1601 -- happen with an explicit renaming, and within instances.
1603 while Present (Renamed_Object (Pool))
1604 and then Is_Entity_Name (Renamed_Object (Pool))
1606 Pool := Entity (Renamed_Object (Pool));
1609 if Present (Renamed_Object (Pool))
1610 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
1611 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
1613 Pool := Entity (Expression (Renamed_Object (Pool)));
1616 Set_Associated_Storage_Pool (U_Ent, Pool);
1618 elsif Nkind (Expr) = N_Type_Conversion
1619 and then Is_Entity_Name (Expression (Expr))
1620 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
1622 Pool := Entity (Expression (Expr));
1623 Set_Associated_Storage_Pool (U_Ent, Pool);
1626 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
1635 -- Storage_Size attribute definition clause
1637 when Attribute_Storage_Size => Storage_Size : declare
1638 Btype : constant Entity_Id := Base_Type (U_Ent);
1642 if Is_Task_Type (U_Ent) then
1643 Check_Restriction (No_Obsolescent_Features, N);
1645 if Warn_On_Obsolescent_Feature then
1647 ("storage size clause for task is an " &
1648 "obsolescent feature (RM J.9)?", N);
1650 ("\use Storage_Size pragma instead?", N);
1656 if not Is_Access_Type (U_Ent)
1657 and then Ekind (U_Ent) /= E_Task_Type
1659 Error_Msg_N ("storage size cannot be given for &", Nam);
1661 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
1663 ("storage size cannot be given for a derived access type",
1666 elsif Has_Storage_Size_Clause (Btype) then
1667 Error_Msg_N ("storage size already given for &", Nam);
1670 Analyze_And_Resolve (Expr, Any_Integer);
1672 if Is_Access_Type (U_Ent) then
1673 if Present (Associated_Storage_Pool (U_Ent)) then
1674 Error_Msg_N ("storage pool already given for &", Nam);
1678 if Compile_Time_Known_Value (Expr)
1679 and then Expr_Value (Expr) = 0
1681 Set_No_Pool_Assigned (Btype);
1684 else -- Is_Task_Type (U_Ent)
1685 Sprag := Get_Rep_Pragma (Btype, Name_Storage_Size);
1687 if Present (Sprag) then
1688 Error_Msg_Sloc := Sloc (Sprag);
1690 ("Storage_Size already specified#", Nam);
1695 Set_Has_Storage_Size_Clause (Btype);
1703 when Attribute_Stream_Size => Stream_Size : declare
1704 Size : constant Uint := Static_Integer (Expr);
1707 if Ada_Version <= Ada_95 then
1708 Check_Restriction (No_Implementation_Attributes, N);
1711 if Has_Stream_Size_Clause (U_Ent) then
1712 Error_Msg_N ("Stream_Size already given for &", Nam);
1714 elsif Is_Elementary_Type (U_Ent) then
1715 if Size /= System_Storage_Unit
1717 Size /= System_Storage_Unit * 2
1719 Size /= System_Storage_Unit * 4
1721 Size /= System_Storage_Unit * 8
1723 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
1725 ("stream size for elementary type must be a"
1726 & " power of 2 and at least ^", N);
1728 elsif RM_Size (U_Ent) > Size then
1729 Error_Msg_Uint_1 := RM_Size (U_Ent);
1731 ("stream size for elementary type must be a"
1732 & " power of 2 and at least ^", N);
1735 Set_Has_Stream_Size_Clause (U_Ent);
1738 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
1746 -- Value_Size attribute definition clause
1748 when Attribute_Value_Size => Value_Size : declare
1749 Size : constant Uint := Static_Integer (Expr);
1753 if not Is_Type (U_Ent) then
1754 Error_Msg_N ("Value_Size cannot be given for &", Nam);
1757 (Get_Attribute_Definition_Clause
1758 (U_Ent, Attribute_Value_Size))
1760 Error_Msg_N ("Value_Size already given for &", Nam);
1762 elsif Is_Array_Type (U_Ent)
1763 and then not Is_Constrained (U_Ent)
1766 ("Value_Size cannot be given for unconstrained array", Nam);
1769 if Is_Elementary_Type (U_Ent) then
1770 Check_Size (Expr, U_Ent, Size, Biased);
1771 Set_Has_Biased_Representation (U_Ent, Biased);
1773 if Biased and Warn_On_Biased_Representation then
1775 ("?value size clause forces biased representation", N);
1779 Set_RM_Size (U_Ent, Size);
1787 when Attribute_Write =>
1788 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
1789 Set_Has_Specified_Stream_Write (Ent);
1791 -- All other attributes cannot be set
1795 ("attribute& cannot be set with definition clause", N);
1798 -- The test for the type being frozen must be performed after
1799 -- any expression the clause has been analyzed since the expression
1800 -- itself might cause freezing that makes the clause illegal.
1802 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
1805 end Analyze_Attribute_Definition_Clause;
1807 ----------------------------
1808 -- Analyze_Code_Statement --
1809 ----------------------------
1811 procedure Analyze_Code_Statement (N : Node_Id) is
1812 HSS : constant Node_Id := Parent (N);
1813 SBody : constant Node_Id := Parent (HSS);
1814 Subp : constant Entity_Id := Current_Scope;
1821 -- Analyze and check we get right type, note that this implements the
1822 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1823 -- is the only way that Asm_Insn could possibly be visible.
1825 Analyze_And_Resolve (Expression (N));
1827 if Etype (Expression (N)) = Any_Type then
1829 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
1830 Error_Msg_N ("incorrect type for code statement", N);
1834 Check_Code_Statement (N);
1836 -- Make sure we appear in the handled statement sequence of a
1837 -- subprogram (RM 13.8(3)).
1839 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
1840 or else Nkind (SBody) /= N_Subprogram_Body
1843 ("code statement can only appear in body of subprogram", N);
1847 -- Do remaining checks (RM 13.8(3)) if not already done
1849 if not Is_Machine_Code_Subprogram (Subp) then
1850 Set_Is_Machine_Code_Subprogram (Subp);
1852 -- No exception handlers allowed
1854 if Present (Exception_Handlers (HSS)) then
1856 ("exception handlers not permitted in machine code subprogram",
1857 First (Exception_Handlers (HSS)));
1860 -- No declarations other than use clauses and pragmas (we allow
1861 -- certain internally generated declarations as well).
1863 Decl := First (Declarations (SBody));
1864 while Present (Decl) loop
1865 DeclO := Original_Node (Decl);
1866 if Comes_From_Source (DeclO)
1867 and not Nkind_In (DeclO, N_Pragma,
1868 N_Use_Package_Clause,
1870 N_Implicit_Label_Declaration)
1873 ("this declaration not allowed in machine code subprogram",
1880 -- No statements other than code statements, pragmas, and labels.
1881 -- Again we allow certain internally generated statements.
1883 Stmt := First (Statements (HSS));
1884 while Present (Stmt) loop
1885 StmtO := Original_Node (Stmt);
1886 if Comes_From_Source (StmtO)
1887 and then not Nkind_In (StmtO, N_Pragma,
1892 ("this statement is not allowed in machine code subprogram",
1899 end Analyze_Code_Statement;
1901 -----------------------------------------------
1902 -- Analyze_Enumeration_Representation_Clause --
1903 -----------------------------------------------
1905 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
1906 Ident : constant Node_Id := Identifier (N);
1907 Aggr : constant Node_Id := Array_Aggregate (N);
1908 Enumtype : Entity_Id;
1914 Err : Boolean := False;
1916 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
1917 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
1922 if Ignore_Rep_Clauses then
1926 -- First some basic error checks
1929 Enumtype := Entity (Ident);
1931 if Enumtype = Any_Type
1932 or else Rep_Item_Too_Early (Enumtype, N)
1936 Enumtype := Underlying_Type (Enumtype);
1939 if not Is_Enumeration_Type (Enumtype) then
1941 ("enumeration type required, found}",
1942 Ident, First_Subtype (Enumtype));
1946 -- Ignore rep clause on generic actual type. This will already have
1947 -- been flagged on the template as an error, and this is the safest
1948 -- way to ensure we don't get a junk cascaded message in the instance.
1950 if Is_Generic_Actual_Type (Enumtype) then
1953 -- Type must be in current scope
1955 elsif Scope (Enumtype) /= Current_Scope then
1956 Error_Msg_N ("type must be declared in this scope", Ident);
1959 -- Type must be a first subtype
1961 elsif not Is_First_Subtype (Enumtype) then
1962 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
1965 -- Ignore duplicate rep clause
1967 elsif Has_Enumeration_Rep_Clause (Enumtype) then
1968 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
1971 -- Don't allow rep clause for standard [wide_[wide_]]character
1973 elsif Is_Standard_Character_Type (Enumtype) then
1974 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
1977 -- Check that the expression is a proper aggregate (no parentheses)
1979 elsif Paren_Count (Aggr) /= 0 then
1981 ("extra parentheses surrounding aggregate not allowed",
1985 -- All tests passed, so set rep clause in place
1988 Set_Has_Enumeration_Rep_Clause (Enumtype);
1989 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
1992 -- Now we process the aggregate. Note that we don't use the normal
1993 -- aggregate code for this purpose, because we don't want any of the
1994 -- normal expansion activities, and a number of special semantic
1995 -- rules apply (including the component type being any integer type)
1997 Elit := First_Literal (Enumtype);
1999 -- First the positional entries if any
2001 if Present (Expressions (Aggr)) then
2002 Expr := First (Expressions (Aggr));
2003 while Present (Expr) loop
2005 Error_Msg_N ("too many entries in aggregate", Expr);
2009 Val := Static_Integer (Expr);
2011 -- Err signals that we found some incorrect entries processing
2012 -- the list. The final checks for completeness and ordering are
2013 -- skipped in this case.
2015 if Val = No_Uint then
2017 elsif Val < Lo or else Hi < Val then
2018 Error_Msg_N ("value outside permitted range", Expr);
2022 Set_Enumeration_Rep (Elit, Val);
2023 Set_Enumeration_Rep_Expr (Elit, Expr);
2029 -- Now process the named entries if present
2031 if Present (Component_Associations (Aggr)) then
2032 Assoc := First (Component_Associations (Aggr));
2033 while Present (Assoc) loop
2034 Choice := First (Choices (Assoc));
2036 if Present (Next (Choice)) then
2038 ("multiple choice not allowed here", Next (Choice));
2042 if Nkind (Choice) = N_Others_Choice then
2043 Error_Msg_N ("others choice not allowed here", Choice);
2046 elsif Nkind (Choice) = N_Range then
2047 -- ??? should allow zero/one element range here
2048 Error_Msg_N ("range not allowed here", Choice);
2052 Analyze_And_Resolve (Choice, Enumtype);
2054 if Is_Entity_Name (Choice)
2055 and then Is_Type (Entity (Choice))
2057 Error_Msg_N ("subtype name not allowed here", Choice);
2059 -- ??? should allow static subtype with zero/one entry
2061 elsif Etype (Choice) = Base_Type (Enumtype) then
2062 if not Is_Static_Expression (Choice) then
2063 Flag_Non_Static_Expr
2064 ("non-static expression used for choice!", Choice);
2068 Elit := Expr_Value_E (Choice);
2070 if Present (Enumeration_Rep_Expr (Elit)) then
2071 Error_Msg_Sloc := Sloc (Enumeration_Rep_Expr (Elit));
2073 ("representation for& previously given#",
2078 Set_Enumeration_Rep_Expr (Elit, Choice);
2080 Expr := Expression (Assoc);
2081 Val := Static_Integer (Expr);
2083 if Val = No_Uint then
2086 elsif Val < Lo or else Hi < Val then
2087 Error_Msg_N ("value outside permitted range", Expr);
2091 Set_Enumeration_Rep (Elit, Val);
2100 -- Aggregate is fully processed. Now we check that a full set of
2101 -- representations was given, and that they are in range and in order.
2102 -- These checks are only done if no other errors occurred.
2108 Elit := First_Literal (Enumtype);
2109 while Present (Elit) loop
2110 if No (Enumeration_Rep_Expr (Elit)) then
2111 Error_Msg_NE ("missing representation for&!", N, Elit);
2114 Val := Enumeration_Rep (Elit);
2116 if Min = No_Uint then
2120 if Val /= No_Uint then
2121 if Max /= No_Uint and then Val <= Max then
2123 ("enumeration value for& not ordered!",
2124 Enumeration_Rep_Expr (Elit), Elit);
2130 -- If there is at least one literal whose representation
2131 -- is not equal to the Pos value, then note that this
2132 -- enumeration type has a non-standard representation.
2134 if Val /= Enumeration_Pos (Elit) then
2135 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
2142 -- Now set proper size information
2145 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
2148 if Has_Size_Clause (Enumtype) then
2149 if Esize (Enumtype) >= Minsize then
2154 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
2156 if Esize (Enumtype) < Minsize then
2157 Error_Msg_N ("previously given size is too small", N);
2160 Set_Has_Biased_Representation (Enumtype);
2165 Set_RM_Size (Enumtype, Minsize);
2166 Set_Enum_Esize (Enumtype);
2169 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
2170 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
2171 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
2175 -- We repeat the too late test in case it froze itself!
2177 if Rep_Item_Too_Late (Enumtype, N) then
2180 end Analyze_Enumeration_Representation_Clause;
2182 ----------------------------
2183 -- Analyze_Free_Statement --
2184 ----------------------------
2186 procedure Analyze_Free_Statement (N : Node_Id) is
2188 Analyze (Expression (N));
2189 end Analyze_Free_Statement;
2191 ------------------------------------------
2192 -- Analyze_Record_Representation_Clause --
2193 ------------------------------------------
2195 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
2196 Loc : constant Source_Ptr := Sloc (N);
2197 Ident : constant Node_Id := Identifier (N);
2198 Rectype : Entity_Id;
2204 Hbit : Uint := Uint_0;
2210 Max_Bit_So_Far : Uint;
2211 -- Records the maximum bit position so far. If all field positions
2212 -- are monotonically increasing, then we can skip the circuit for
2213 -- checking for overlap, since no overlap is possible.
2215 Tagged_Parent : Entity_Id := Empty;
2216 -- This is set in the case of a derived tagged type for which we have
2217 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
2218 -- positioned by record representation clauses). In this case we must
2219 -- check for overlap between components of this tagged type, and the
2220 -- components of its parent. Tagged_Parent will point to this parent
2221 -- type. For all other cases Tagged_Parent is left set to Empty.
2223 Parent_Last_Bit : Uint;
2224 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
2225 -- last bit position for any field in the parent type. We only need to
2226 -- check overlap for fields starting below this point.
2228 Overlap_Check_Required : Boolean;
2229 -- Used to keep track of whether or not an overlap check is required
2231 Ccount : Natural := 0;
2232 -- Number of component clauses in record rep clause
2234 CR_Pragma : Node_Id := Empty;
2235 -- Points to N_Pragma node if Complete_Representation pragma present
2238 if Ignore_Rep_Clauses then
2243 Rectype := Entity (Ident);
2245 if Rectype = Any_Type
2246 or else Rep_Item_Too_Early (Rectype, N)
2250 Rectype := Underlying_Type (Rectype);
2253 -- First some basic error checks
2255 if not Is_Record_Type (Rectype) then
2257 ("record type required, found}", Ident, First_Subtype (Rectype));
2260 elsif Is_Unchecked_Union (Rectype) then
2262 ("record rep clause not allowed for Unchecked_Union", N);
2264 elsif Scope (Rectype) /= Current_Scope then
2265 Error_Msg_N ("type must be declared in this scope", N);
2268 elsif not Is_First_Subtype (Rectype) then
2269 Error_Msg_N ("cannot give record rep clause for subtype", N);
2272 elsif Has_Record_Rep_Clause (Rectype) then
2273 Error_Msg_N ("duplicate record rep clause ignored", N);
2276 elsif Rep_Item_Too_Late (Rectype, N) then
2280 if Present (Mod_Clause (N)) then
2282 Loc : constant Source_Ptr := Sloc (N);
2283 M : constant Node_Id := Mod_Clause (N);
2284 P : constant List_Id := Pragmas_Before (M);
2288 pragma Warnings (Off, Mod_Val);
2291 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
2293 if Warn_On_Obsolescent_Feature then
2295 ("mod clause is an obsolescent feature (RM J.8)?", N);
2297 ("\use alignment attribute definition clause instead?", N);
2304 -- In ASIS_Mode mode, expansion is disabled, but we must convert
2305 -- the Mod clause into an alignment clause anyway, so that the
2306 -- back-end can compute and back-annotate properly the size and
2307 -- alignment of types that may include this record.
2309 -- This seems dubious, this destroys the source tree in a manner
2310 -- not detectable by ASIS ???
2312 if Operating_Mode = Check_Semantics
2316 Make_Attribute_Definition_Clause (Loc,
2317 Name => New_Reference_To (Base_Type (Rectype), Loc),
2318 Chars => Name_Alignment,
2319 Expression => Relocate_Node (Expression (M)));
2321 Set_From_At_Mod (AtM_Nod);
2322 Insert_After (N, AtM_Nod);
2323 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
2324 Set_Mod_Clause (N, Empty);
2327 -- Get the alignment value to perform error checking
2329 Mod_Val := Get_Alignment_Value (Expression (M));
2335 -- For untagged types, clear any existing component clauses for the
2336 -- type. If the type is derived, this is what allows us to override
2337 -- a rep clause for the parent. For type extensions, the representation
2338 -- of the inherited components is inherited, so we want to keep previous
2339 -- component clauses for completeness.
2341 if not Is_Tagged_Type (Rectype) then
2342 Comp := First_Component_Or_Discriminant (Rectype);
2343 while Present (Comp) loop
2344 Set_Component_Clause (Comp, Empty);
2345 Next_Component_Or_Discriminant (Comp);
2349 -- See if we have a fully repped derived tagged type
2352 PS : constant Entity_Id := Parent_Subtype (Rectype);
2355 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
2356 Tagged_Parent := PS;
2358 -- Find maximum bit of any component of the parent type
2360 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
2361 Pcomp := First_Entity (Tagged_Parent);
2362 while Present (Pcomp) loop
2363 if Ekind (Pcomp) = E_Discriminant
2365 Ekind (Pcomp) = E_Component
2367 if Component_Bit_Offset (Pcomp) /= No_Uint
2368 and then Known_Static_Esize (Pcomp)
2373 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
2376 Next_Entity (Pcomp);
2382 -- All done if no component clauses
2384 CC := First (Component_Clauses (N));
2390 -- If a tag is present, then create a component clause that places it
2391 -- at the start of the record (otherwise gigi may place it after other
2392 -- fields that have rep clauses).
2394 Fent := First_Entity (Rectype);
2396 if Nkind (Fent) = N_Defining_Identifier
2397 and then Chars (Fent) = Name_uTag
2399 Set_Component_Bit_Offset (Fent, Uint_0);
2400 Set_Normalized_Position (Fent, Uint_0);
2401 Set_Normalized_First_Bit (Fent, Uint_0);
2402 Set_Normalized_Position_Max (Fent, Uint_0);
2403 Init_Esize (Fent, System_Address_Size);
2405 Set_Component_Clause (Fent,
2406 Make_Component_Clause (Loc,
2408 Make_Identifier (Loc,
2409 Chars => Name_uTag),
2412 Make_Integer_Literal (Loc,
2416 Make_Integer_Literal (Loc,
2420 Make_Integer_Literal (Loc,
2421 UI_From_Int (System_Address_Size))));
2423 Ccount := Ccount + 1;
2426 -- A representation like this applies to the base type
2428 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
2429 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
2430 Set_Has_Specified_Layout (Base_Type (Rectype));
2432 Max_Bit_So_Far := Uint_Minus_1;
2433 Overlap_Check_Required := False;
2435 -- Process the component clauses
2437 while Present (CC) loop
2441 if Nkind (CC) = N_Pragma then
2444 -- The only pragma of interest is Complete_Representation
2446 if Pragma_Name (CC) = Name_Complete_Representation then
2450 -- Processing for real component clause
2453 Ccount := Ccount + 1;
2454 Posit := Static_Integer (Position (CC));
2455 Fbit := Static_Integer (First_Bit (CC));
2456 Lbit := Static_Integer (Last_Bit (CC));
2459 and then Fbit /= No_Uint
2460 and then Lbit /= No_Uint
2464 ("position cannot be negative", Position (CC));
2468 ("first bit cannot be negative", First_Bit (CC));
2470 -- The Last_Bit specified in a component clause must not be
2471 -- less than the First_Bit minus one (RM-13.5.1(10)).
2473 elsif Lbit < Fbit - 1 then
2475 ("last bit cannot be less than first bit minus one",
2478 -- Values look OK, so find the corresponding record component
2479 -- Even though the syntax allows an attribute reference for
2480 -- implementation-defined components, GNAT does not allow the
2481 -- tag to get an explicit position.
2483 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
2484 if Attribute_Name (Component_Name (CC)) = Name_Tag then
2485 Error_Msg_N ("position of tag cannot be specified", CC);
2487 Error_Msg_N ("illegal component name", CC);
2491 Comp := First_Entity (Rectype);
2492 while Present (Comp) loop
2493 exit when Chars (Comp) = Chars (Component_Name (CC));
2499 -- Maybe component of base type that is absent from
2500 -- statically constrained first subtype.
2502 Comp := First_Entity (Base_Type (Rectype));
2503 while Present (Comp) loop
2504 exit when Chars (Comp) = Chars (Component_Name (CC));
2511 ("component clause is for non-existent field", CC);
2513 elsif Present (Component_Clause (Comp)) then
2515 -- Diagnose duplicate rep clause, or check consistency
2516 -- if this is an inherited component. In a double fault,
2517 -- there may be a duplicate inconsistent clause for an
2518 -- inherited component.
2520 if Scope (Original_Record_Component (Comp)) = Rectype
2521 or else Parent (Component_Clause (Comp)) = N
2523 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
2524 Error_Msg_N ("component clause previously given#", CC);
2528 Rep1 : constant Node_Id := Component_Clause (Comp);
2530 if Intval (Position (Rep1)) /=
2531 Intval (Position (CC))
2532 or else Intval (First_Bit (Rep1)) /=
2533 Intval (First_Bit (CC))
2534 or else Intval (Last_Bit (Rep1)) /=
2535 Intval (Last_Bit (CC))
2537 Error_Msg_N ("component clause inconsistent "
2538 & "with representation of ancestor", CC);
2539 elsif Warn_On_Redundant_Constructs then
2540 Error_Msg_N ("?redundant component clause "
2541 & "for inherited component!", CC);
2546 -- Normal case where this is the first component clause we
2547 -- have seen for this entity, so set it up properly.
2550 -- Make reference for field in record rep clause and set
2551 -- appropriate entity field in the field identifier.
2554 (Comp, Component_Name (CC), Set_Ref => False);
2555 Set_Entity (Component_Name (CC), Comp);
2557 -- Update Fbit and Lbit to the actual bit number
2559 Fbit := Fbit + UI_From_Int (SSU) * Posit;
2560 Lbit := Lbit + UI_From_Int (SSU) * Posit;
2562 if Fbit <= Max_Bit_So_Far then
2563 Overlap_Check_Required := True;
2565 Max_Bit_So_Far := Lbit;
2568 if Has_Size_Clause (Rectype)
2569 and then Esize (Rectype) <= Lbit
2572 ("bit number out of range of specified size",
2575 Set_Component_Clause (Comp, CC);
2576 Set_Component_Bit_Offset (Comp, Fbit);
2577 Set_Esize (Comp, 1 + (Lbit - Fbit));
2578 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
2579 Set_Normalized_Position (Comp, Fbit / SSU);
2581 Set_Normalized_Position_Max
2582 (Fent, Normalized_Position (Fent));
2584 if Is_Tagged_Type (Rectype)
2585 and then Fbit < System_Address_Size
2588 ("component overlaps tag field of&",
2589 Component_Name (CC), Rectype);
2592 -- This information is also set in the corresponding
2593 -- component of the base type, found by accessing the
2594 -- Original_Record_Component link if it is present.
2596 Ocomp := Original_Record_Component (Comp);
2603 (Component_Name (CC),
2608 Set_Has_Biased_Representation (Comp, Biased);
2610 if Biased and Warn_On_Biased_Representation then
2612 ("?component clause forces biased "
2613 & "representation", CC);
2616 if Present (Ocomp) then
2617 Set_Component_Clause (Ocomp, CC);
2618 Set_Component_Bit_Offset (Ocomp, Fbit);
2619 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
2620 Set_Normalized_Position (Ocomp, Fbit / SSU);
2621 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
2623 Set_Normalized_Position_Max
2624 (Ocomp, Normalized_Position (Ocomp));
2626 Set_Has_Biased_Representation
2627 (Ocomp, Has_Biased_Representation (Comp));
2630 if Esize (Comp) < 0 then
2631 Error_Msg_N ("component size is negative", CC);
2635 -- If OK component size, check parent type overlap if
2636 -- this component might overlap a parent field.
2638 if Present (Tagged_Parent)
2639 and then Fbit <= Parent_Last_Bit
2641 Pcomp := First_Entity (Tagged_Parent);
2642 while Present (Pcomp) loop
2643 if (Ekind (Pcomp) = E_Discriminant
2645 Ekind (Pcomp) = E_Component)
2646 and then not Is_Tag (Pcomp)
2647 and then Chars (Pcomp) /= Name_uParent
2649 Check_Component_Overlap (Comp, Pcomp);
2652 Next_Entity (Pcomp);
2663 -- Now that we have processed all the component clauses, check for
2664 -- overlap. We have to leave this till last, since the components can
2665 -- appear in any arbitrary order in the representation clause.
2667 -- We do not need this check if all specified ranges were monotonic,
2668 -- as recorded by Overlap_Check_Required being False at this stage.
2670 -- This first section checks if there are any overlapping entries at
2671 -- all. It does this by sorting all entries and then seeing if there are
2672 -- any overlaps. If there are none, then that is decisive, but if there
2673 -- are overlaps, they may still be OK (they may result from fields in
2674 -- different variants).
2676 if Overlap_Check_Required then
2677 Overlap_Check1 : declare
2679 OC_Fbit : array (0 .. Ccount) of Uint;
2680 -- First-bit values for component clauses, the value is the offset
2681 -- of the first bit of the field from start of record. The zero
2682 -- entry is for use in sorting.
2684 OC_Lbit : array (0 .. Ccount) of Uint;
2685 -- Last-bit values for component clauses, the value is the offset
2686 -- of the last bit of the field from start of record. The zero
2687 -- entry is for use in sorting.
2689 OC_Count : Natural := 0;
2690 -- Count of entries in OC_Fbit and OC_Lbit
2692 function OC_Lt (Op1, Op2 : Natural) return Boolean;
2693 -- Compare routine for Sort
2695 procedure OC_Move (From : Natural; To : Natural);
2696 -- Move routine for Sort
2698 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
2704 function OC_Lt (Op1, Op2 : Natural) return Boolean is
2706 return OC_Fbit (Op1) < OC_Fbit (Op2);
2713 procedure OC_Move (From : Natural; To : Natural) is
2715 OC_Fbit (To) := OC_Fbit (From);
2716 OC_Lbit (To) := OC_Lbit (From);
2719 -- Start of processing for Overlap_Check
2722 CC := First (Component_Clauses (N));
2723 while Present (CC) loop
2724 if Nkind (CC) /= N_Pragma then
2725 Posit := Static_Integer (Position (CC));
2726 Fbit := Static_Integer (First_Bit (CC));
2727 Lbit := Static_Integer (Last_Bit (CC));
2730 and then Fbit /= No_Uint
2731 and then Lbit /= No_Uint
2733 OC_Count := OC_Count + 1;
2734 Posit := Posit * SSU;
2735 OC_Fbit (OC_Count) := Fbit + Posit;
2736 OC_Lbit (OC_Count) := Lbit + Posit;
2743 Sorting.Sort (OC_Count);
2745 Overlap_Check_Required := False;
2746 for J in 1 .. OC_Count - 1 loop
2747 if OC_Lbit (J) >= OC_Fbit (J + 1) then
2748 Overlap_Check_Required := True;
2755 -- If Overlap_Check_Required is still True, then we have to do the full
2756 -- scale overlap check, since we have at least two fields that do
2757 -- overlap, and we need to know if that is OK since they are in
2758 -- different variant, or whether we have a definite problem.
2760 if Overlap_Check_Required then
2761 Overlap_Check2 : declare
2762 C1_Ent, C2_Ent : Entity_Id;
2763 -- Entities of components being checked for overlap
2766 -- Component_List node whose Component_Items are being checked
2769 -- Component declaration for component being checked
2772 C1_Ent := First_Entity (Base_Type (Rectype));
2774 -- Loop through all components in record. For each component check
2775 -- for overlap with any of the preceding elements on the component
2776 -- list containing the component and also, if the component is in
2777 -- a variant, check against components outside the case structure.
2778 -- This latter test is repeated recursively up the variant tree.
2780 Main_Component_Loop : while Present (C1_Ent) loop
2781 if Ekind (C1_Ent) /= E_Component
2782 and then Ekind (C1_Ent) /= E_Discriminant
2784 goto Continue_Main_Component_Loop;
2787 -- Skip overlap check if entity has no declaration node. This
2788 -- happens with discriminants in constrained derived types.
2789 -- Probably we are missing some checks as a result, but that
2790 -- does not seem terribly serious ???
2792 if No (Declaration_Node (C1_Ent)) then
2793 goto Continue_Main_Component_Loop;
2796 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
2798 -- Loop through component lists that need checking. Check the
2799 -- current component list and all lists in variants above us.
2801 Component_List_Loop : loop
2803 -- If derived type definition, go to full declaration
2804 -- If at outer level, check discriminants if there are any.
2806 if Nkind (Clist) = N_Derived_Type_Definition then
2807 Clist := Parent (Clist);
2810 -- Outer level of record definition, check discriminants
2812 if Nkind_In (Clist, N_Full_Type_Declaration,
2813 N_Private_Type_Declaration)
2815 if Has_Discriminants (Defining_Identifier (Clist)) then
2817 First_Discriminant (Defining_Identifier (Clist));
2818 while Present (C2_Ent) loop
2819 exit when C1_Ent = C2_Ent;
2820 Check_Component_Overlap (C1_Ent, C2_Ent);
2821 Next_Discriminant (C2_Ent);
2825 -- Record extension case
2827 elsif Nkind (Clist) = N_Derived_Type_Definition then
2830 -- Otherwise check one component list
2833 Citem := First (Component_Items (Clist));
2835 while Present (Citem) loop
2836 if Nkind (Citem) = N_Component_Declaration then
2837 C2_Ent := Defining_Identifier (Citem);
2838 exit when C1_Ent = C2_Ent;
2839 Check_Component_Overlap (C1_Ent, C2_Ent);
2846 -- Check for variants above us (the parent of the Clist can
2847 -- be a variant, in which case its parent is a variant part,
2848 -- and the parent of the variant part is a component list
2849 -- whose components must all be checked against the current
2850 -- component for overlap).
2852 if Nkind (Parent (Clist)) = N_Variant then
2853 Clist := Parent (Parent (Parent (Clist)));
2855 -- Check for possible discriminant part in record, this is
2856 -- treated essentially as another level in the recursion.
2857 -- For this case the parent of the component list is the
2858 -- record definition, and its parent is the full type
2859 -- declaration containing the discriminant specifications.
2861 elsif Nkind (Parent (Clist)) = N_Record_Definition then
2862 Clist := Parent (Parent ((Clist)));
2864 -- If neither of these two cases, we are at the top of
2868 exit Component_List_Loop;
2870 end loop Component_List_Loop;
2872 <<Continue_Main_Component_Loop>>
2873 Next_Entity (C1_Ent);
2875 end loop Main_Component_Loop;
2879 -- For records that have component clauses for all components, and whose
2880 -- size is less than or equal to 32, we need to know the size in the
2881 -- front end to activate possible packed array processing where the
2882 -- component type is a record.
2884 -- At this stage Hbit + 1 represents the first unused bit from all the
2885 -- component clauses processed, so if the component clauses are
2886 -- complete, then this is the length of the record.
2888 -- For records longer than System.Storage_Unit, and for those where not
2889 -- all components have component clauses, the back end determines the
2890 -- length (it may for example be appropriate to round up the size
2891 -- to some convenient boundary, based on alignment considerations, etc).
2893 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
2895 -- Nothing to do if at least one component has no component clause
2897 Comp := First_Component_Or_Discriminant (Rectype);
2898 while Present (Comp) loop
2899 exit when No (Component_Clause (Comp));
2900 Next_Component_Or_Discriminant (Comp);
2903 -- If we fall out of loop, all components have component clauses
2904 -- and so we can set the size to the maximum value.
2907 Set_RM_Size (Rectype, Hbit + 1);
2911 -- Check missing components if Complete_Representation pragma appeared
2913 if Present (CR_Pragma) then
2914 Comp := First_Component_Or_Discriminant (Rectype);
2915 while Present (Comp) loop
2916 if No (Component_Clause (Comp)) then
2918 ("missing component clause for &", CR_Pragma, Comp);
2921 Next_Component_Or_Discriminant (Comp);
2924 -- If no Complete_Representation pragma, warn if missing components
2926 elsif Warn_On_Unrepped_Components then
2928 Num_Repped_Components : Nat := 0;
2929 Num_Unrepped_Components : Nat := 0;
2932 -- First count number of repped and unrepped components
2934 Comp := First_Component_Or_Discriminant (Rectype);
2935 while Present (Comp) loop
2936 if Present (Component_Clause (Comp)) then
2937 Num_Repped_Components := Num_Repped_Components + 1;
2939 Num_Unrepped_Components := Num_Unrepped_Components + 1;
2942 Next_Component_Or_Discriminant (Comp);
2945 -- We are only interested in the case where there is at least one
2946 -- unrepped component, and at least half the components have rep
2947 -- clauses. We figure that if less than half have them, then the
2948 -- partial rep clause is really intentional. If the component
2949 -- type has no underlying type set at this point (as for a generic
2950 -- formal type), we don't know enough to give a warning on the
2953 if Num_Unrepped_Components > 0
2954 and then Num_Unrepped_Components < Num_Repped_Components
2956 Comp := First_Component_Or_Discriminant (Rectype);
2957 while Present (Comp) loop
2958 if No (Component_Clause (Comp))
2959 and then Comes_From_Source (Comp)
2960 and then Present (Underlying_Type (Etype (Comp)))
2961 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
2962 or else Size_Known_At_Compile_Time
2963 (Underlying_Type (Etype (Comp))))
2964 and then not Has_Warnings_Off (Rectype)
2966 Error_Msg_Sloc := Sloc (Comp);
2968 ("?no component clause given for & declared #",
2972 Next_Component_Or_Discriminant (Comp);
2977 end Analyze_Record_Representation_Clause;
2979 -----------------------------
2980 -- Check_Component_Overlap --
2981 -----------------------------
2983 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
2985 if Present (Component_Clause (C1_Ent))
2986 and then Present (Component_Clause (C2_Ent))
2988 -- Exclude odd case where we have two tag fields in the same record,
2989 -- both at location zero. This seems a bit strange, but it seems to
2990 -- happen in some circumstances ???
2992 if Chars (C1_Ent) = Name_uTag
2993 and then Chars (C2_Ent) = Name_uTag
2998 -- Here we check if the two fields overlap
3001 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
3002 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
3003 E1 : constant Uint := S1 + Esize (C1_Ent);
3004 E2 : constant Uint := S2 + Esize (C2_Ent);
3007 if E2 <= S1 or else E1 <= S2 then
3011 Component_Name (Component_Clause (C2_Ent));
3012 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
3014 Component_Name (Component_Clause (C1_Ent));
3016 ("component& overlaps & #",
3017 Component_Name (Component_Clause (C1_Ent)));
3021 end Check_Component_Overlap;
3023 -----------------------------------
3024 -- Check_Constant_Address_Clause --
3025 -----------------------------------
3027 procedure Check_Constant_Address_Clause
3031 procedure Check_At_Constant_Address (Nod : Node_Id);
3032 -- Checks that the given node N represents a name whose 'Address is
3033 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
3034 -- address value is the same at the point of declaration of U_Ent and at
3035 -- the time of elaboration of the address clause.
3037 procedure Check_Expr_Constants (Nod : Node_Id);
3038 -- Checks that Nod meets the requirements for a constant address clause
3039 -- in the sense of the enclosing procedure.
3041 procedure Check_List_Constants (Lst : List_Id);
3042 -- Check that all elements of list Lst meet the requirements for a
3043 -- constant address clause in the sense of the enclosing procedure.
3045 -------------------------------
3046 -- Check_At_Constant_Address --
3047 -------------------------------
3049 procedure Check_At_Constant_Address (Nod : Node_Id) is
3051 if Is_Entity_Name (Nod) then
3052 if Present (Address_Clause (Entity ((Nod)))) then
3054 ("invalid address clause for initialized object &!",
3057 ("address for& cannot" &
3058 " depend on another address clause! (RM 13.1(22))!",
3061 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
3062 and then Sloc (U_Ent) < Sloc (Entity (Nod))
3065 ("invalid address clause for initialized object &!",
3067 Error_Msg_Node_2 := U_Ent;
3069 ("\& must be defined before & (RM 13.1(22))!",
3073 elsif Nkind (Nod) = N_Selected_Component then
3075 T : constant Entity_Id := Etype (Prefix (Nod));
3078 if (Is_Record_Type (T)
3079 and then Has_Discriminants (T))
3082 and then Is_Record_Type (Designated_Type (T))
3083 and then Has_Discriminants (Designated_Type (T)))
3086 ("invalid address clause for initialized object &!",
3089 ("\address cannot depend on component" &
3090 " of discriminated record (RM 13.1(22))!",
3093 Check_At_Constant_Address (Prefix (Nod));
3097 elsif Nkind (Nod) = N_Indexed_Component then
3098 Check_At_Constant_Address (Prefix (Nod));
3099 Check_List_Constants (Expressions (Nod));
3102 Check_Expr_Constants (Nod);
3104 end Check_At_Constant_Address;
3106 --------------------------
3107 -- Check_Expr_Constants --
3108 --------------------------
3110 procedure Check_Expr_Constants (Nod : Node_Id) is
3111 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
3112 Ent : Entity_Id := Empty;
3115 if Nkind (Nod) in N_Has_Etype
3116 and then Etype (Nod) = Any_Type
3122 when N_Empty | N_Error =>
3125 when N_Identifier | N_Expanded_Name =>
3126 Ent := Entity (Nod);
3128 -- We need to look at the original node if it is different
3129 -- from the node, since we may have rewritten things and
3130 -- substituted an identifier representing the rewrite.
3132 if Original_Node (Nod) /= Nod then
3133 Check_Expr_Constants (Original_Node (Nod));
3135 -- If the node is an object declaration without initial
3136 -- value, some code has been expanded, and the expression
3137 -- is not constant, even if the constituents might be
3138 -- acceptable, as in A'Address + offset.
3140 if Ekind (Ent) = E_Variable
3142 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
3144 No (Expression (Declaration_Node (Ent)))
3147 ("invalid address clause for initialized object &!",
3150 -- If entity is constant, it may be the result of expanding
3151 -- a check. We must verify that its declaration appears
3152 -- before the object in question, else we also reject the
3155 elsif Ekind (Ent) = E_Constant
3156 and then In_Same_Source_Unit (Ent, U_Ent)
3157 and then Sloc (Ent) > Loc_U_Ent
3160 ("invalid address clause for initialized object &!",
3167 -- Otherwise look at the identifier and see if it is OK
3169 if Ekind (Ent) = E_Named_Integer
3171 Ekind (Ent) = E_Named_Real
3178 Ekind (Ent) = E_Constant
3180 Ekind (Ent) = E_In_Parameter
3182 -- This is the case where we must have Ent defined before
3183 -- U_Ent. Clearly if they are in different units this
3184 -- requirement is met since the unit containing Ent is
3185 -- already processed.
3187 if not In_Same_Source_Unit (Ent, U_Ent) then
3190 -- Otherwise location of Ent must be before the location
3191 -- of U_Ent, that's what prior defined means.
3193 elsif Sloc (Ent) < Loc_U_Ent then
3198 ("invalid address clause for initialized object &!",
3200 Error_Msg_Node_2 := U_Ent;
3202 ("\& must be defined before & (RM 13.1(22))!",
3206 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
3207 Check_Expr_Constants (Original_Node (Nod));
3211 ("invalid address clause for initialized object &!",
3214 if Comes_From_Source (Ent) then
3216 ("\reference to variable& not allowed"
3217 & " (RM 13.1(22))!", Nod, Ent);
3220 ("non-static expression not allowed"
3221 & " (RM 13.1(22))!", Nod);
3225 when N_Integer_Literal =>
3227 -- If this is a rewritten unchecked conversion, in a system
3228 -- where Address is an integer type, always use the base type
3229 -- for a literal value. This is user-friendly and prevents
3230 -- order-of-elaboration issues with instances of unchecked
3233 if Nkind (Original_Node (Nod)) = N_Function_Call then
3234 Set_Etype (Nod, Base_Type (Etype (Nod)));
3237 when N_Real_Literal |
3239 N_Character_Literal =>
3243 Check_Expr_Constants (Low_Bound (Nod));
3244 Check_Expr_Constants (High_Bound (Nod));
3246 when N_Explicit_Dereference =>
3247 Check_Expr_Constants (Prefix (Nod));
3249 when N_Indexed_Component =>
3250 Check_Expr_Constants (Prefix (Nod));
3251 Check_List_Constants (Expressions (Nod));
3254 Check_Expr_Constants (Prefix (Nod));
3255 Check_Expr_Constants (Discrete_Range (Nod));
3257 when N_Selected_Component =>
3258 Check_Expr_Constants (Prefix (Nod));
3260 when N_Attribute_Reference =>
3261 if Attribute_Name (Nod) = Name_Address
3263 Attribute_Name (Nod) = Name_Access
3265 Attribute_Name (Nod) = Name_Unchecked_Access
3267 Attribute_Name (Nod) = Name_Unrestricted_Access
3269 Check_At_Constant_Address (Prefix (Nod));
3272 Check_Expr_Constants (Prefix (Nod));
3273 Check_List_Constants (Expressions (Nod));
3277 Check_List_Constants (Component_Associations (Nod));
3278 Check_List_Constants (Expressions (Nod));
3280 when N_Component_Association =>
3281 Check_Expr_Constants (Expression (Nod));
3283 when N_Extension_Aggregate =>
3284 Check_Expr_Constants (Ancestor_Part (Nod));
3285 Check_List_Constants (Component_Associations (Nod));
3286 Check_List_Constants (Expressions (Nod));
3291 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
3292 Check_Expr_Constants (Left_Opnd (Nod));
3293 Check_Expr_Constants (Right_Opnd (Nod));
3296 Check_Expr_Constants (Right_Opnd (Nod));
3298 when N_Type_Conversion |
3299 N_Qualified_Expression |
3301 Check_Expr_Constants (Expression (Nod));
3303 when N_Unchecked_Type_Conversion =>
3304 Check_Expr_Constants (Expression (Nod));
3306 -- If this is a rewritten unchecked conversion, subtypes in
3307 -- this node are those created within the instance. To avoid
3308 -- order of elaboration issues, replace them with their base
3309 -- types. Note that address clauses can cause order of
3310 -- elaboration problems because they are elaborated by the
3311 -- back-end at the point of definition, and may mention
3312 -- entities declared in between (as long as everything is
3313 -- static). It is user-friendly to allow unchecked conversions
3316 if Nkind (Original_Node (Nod)) = N_Function_Call then
3317 Set_Etype (Expression (Nod),
3318 Base_Type (Etype (Expression (Nod))));
3319 Set_Etype (Nod, Base_Type (Etype (Nod)));
3322 when N_Function_Call =>
3323 if not Is_Pure (Entity (Name (Nod))) then
3325 ("invalid address clause for initialized object &!",
3329 ("\function & is not pure (RM 13.1(22))!",
3330 Nod, Entity (Name (Nod)));
3333 Check_List_Constants (Parameter_Associations (Nod));
3336 when N_Parameter_Association =>
3337 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
3341 ("invalid address clause for initialized object &!",
3344 ("\must be constant defined before& (RM 13.1(22))!",
3347 end Check_Expr_Constants;
3349 --------------------------
3350 -- Check_List_Constants --
3351 --------------------------
3353 procedure Check_List_Constants (Lst : List_Id) is
3357 if Present (Lst) then
3358 Nod1 := First (Lst);
3359 while Present (Nod1) loop
3360 Check_Expr_Constants (Nod1);
3364 end Check_List_Constants;
3366 -- Start of processing for Check_Constant_Address_Clause
3369 Check_Expr_Constants (Expr);
3370 end Check_Constant_Address_Clause;
3376 procedure Check_Size
3380 Biased : out Boolean)
3382 UT : constant Entity_Id := Underlying_Type (T);
3388 -- Dismiss cases for generic types or types with previous errors
3391 or else UT = Any_Type
3392 or else Is_Generic_Type (UT)
3393 or else Is_Generic_Type (Root_Type (UT))
3397 -- Check case of bit packed array
3399 elsif Is_Array_Type (UT)
3400 and then Known_Static_Component_Size (UT)
3401 and then Is_Bit_Packed_Array (UT)
3409 Asiz := Component_Size (UT);
3410 Indx := First_Index (UT);
3412 Ityp := Etype (Indx);
3414 -- If non-static bound, then we are not in the business of
3415 -- trying to check the length, and indeed an error will be
3416 -- issued elsewhere, since sizes of non-static array types
3417 -- cannot be set implicitly or explicitly.
3419 if not Is_Static_Subtype (Ityp) then
3423 -- Otherwise accumulate next dimension
3425 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
3426 Expr_Value (Type_Low_Bound (Ityp)) +
3430 exit when No (Indx);
3436 Error_Msg_Uint_1 := Asiz;
3438 ("size for& too small, minimum allowed is ^", N, T);
3439 Set_Esize (T, Asiz);
3440 Set_RM_Size (T, Asiz);
3444 -- All other composite types are ignored
3446 elsif Is_Composite_Type (UT) then
3449 -- For fixed-point types, don't check minimum if type is not frozen,
3450 -- since we don't know all the characteristics of the type that can
3451 -- affect the size (e.g. a specified small) till freeze time.
3453 elsif Is_Fixed_Point_Type (UT)
3454 and then not Is_Frozen (UT)
3458 -- Cases for which a minimum check is required
3461 -- Ignore if specified size is correct for the type
3463 if Known_Esize (UT) and then Siz = Esize (UT) then
3467 -- Otherwise get minimum size
3469 M := UI_From_Int (Minimum_Size (UT));
3473 -- Size is less than minimum size, but one possibility remains
3474 -- that we can manage with the new size if we bias the type.
3476 M := UI_From_Int (Minimum_Size (UT, Biased => True));
3479 Error_Msg_Uint_1 := M;
3481 ("size for& too small, minimum allowed is ^", N, T);
3491 -------------------------
3492 -- Get_Alignment_Value --
3493 -------------------------
3495 function Get_Alignment_Value (Expr : Node_Id) return Uint is
3496 Align : constant Uint := Static_Integer (Expr);
3499 if Align = No_Uint then
3502 elsif Align <= 0 then
3503 Error_Msg_N ("alignment value must be positive", Expr);
3507 for J in Int range 0 .. 64 loop
3509 M : constant Uint := Uint_2 ** J;
3512 exit when M = Align;
3516 ("alignment value must be power of 2", Expr);
3524 end Get_Alignment_Value;
3530 procedure Initialize is
3532 Unchecked_Conversions.Init;
3535 -------------------------
3536 -- Is_Operational_Item --
3537 -------------------------
3539 function Is_Operational_Item (N : Node_Id) return Boolean is
3541 if Nkind (N) /= N_Attribute_Definition_Clause then
3545 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
3547 return Id = Attribute_Input
3548 or else Id = Attribute_Output
3549 or else Id = Attribute_Read
3550 or else Id = Attribute_Write
3551 or else Id = Attribute_External_Tag;
3554 end Is_Operational_Item;
3560 function Minimum_Size
3562 Biased : Boolean := False) return Nat
3564 Lo : Uint := No_Uint;
3565 Hi : Uint := No_Uint;
3566 LoR : Ureal := No_Ureal;
3567 HiR : Ureal := No_Ureal;
3568 LoSet : Boolean := False;
3569 HiSet : Boolean := False;
3573 R_Typ : constant Entity_Id := Root_Type (T);
3576 -- If bad type, return 0
3578 if T = Any_Type then
3581 -- For generic types, just return zero. There cannot be any legitimate
3582 -- need to know such a size, but this routine may be called with a
3583 -- generic type as part of normal processing.
3585 elsif Is_Generic_Type (R_Typ)
3586 or else R_Typ = Any_Type
3590 -- Access types. Normally an access type cannot have a size smaller
3591 -- than the size of System.Address. The exception is on VMS, where
3592 -- we have short and long addresses, and it is possible for an access
3593 -- type to have a short address size (and thus be less than the size
3594 -- of System.Address itself). We simply skip the check for VMS, and
3595 -- leave it to the back end to do the check.
3597 elsif Is_Access_Type (T) then
3598 if OpenVMS_On_Target then
3601 return System_Address_Size;
3604 -- Floating-point types
3606 elsif Is_Floating_Point_Type (T) then
3607 return UI_To_Int (Esize (R_Typ));
3611 elsif Is_Discrete_Type (T) then
3613 -- The following loop is looking for the nearest compile time known
3614 -- bounds following the ancestor subtype chain. The idea is to find
3615 -- the most restrictive known bounds information.
3619 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
3624 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
3625 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
3632 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
3633 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
3639 Ancest := Ancestor_Subtype (Ancest);
3642 Ancest := Base_Type (T);
3644 if Is_Generic_Type (Ancest) then
3650 -- Fixed-point types. We can't simply use Expr_Value to get the
3651 -- Corresponding_Integer_Value values of the bounds, since these do not
3652 -- get set till the type is frozen, and this routine can be called
3653 -- before the type is frozen. Similarly the test for bounds being static
3654 -- needs to include the case where we have unanalyzed real literals for
3657 elsif Is_Fixed_Point_Type (T) then
3659 -- The following loop is looking for the nearest compile time known
3660 -- bounds following the ancestor subtype chain. The idea is to find
3661 -- the most restrictive known bounds information.
3665 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
3669 -- Note: In the following two tests for LoSet and HiSet, it may
3670 -- seem redundant to test for N_Real_Literal here since normally
3671 -- one would assume that the test for the value being known at
3672 -- compile time includes this case. However, there is a glitch.
3673 -- If the real literal comes from folding a non-static expression,
3674 -- then we don't consider any non- static expression to be known
3675 -- at compile time if we are in configurable run time mode (needed
3676 -- in some cases to give a clearer definition of what is and what
3677 -- is not accepted). So the test is indeed needed. Without it, we
3678 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
3681 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
3682 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
3684 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
3691 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
3692 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
3694 HiR := Expr_Value_R (Type_High_Bound (Ancest));
3700 Ancest := Ancestor_Subtype (Ancest);
3703 Ancest := Base_Type (T);
3705 if Is_Generic_Type (Ancest) then
3711 Lo := UR_To_Uint (LoR / Small_Value (T));
3712 Hi := UR_To_Uint (HiR / Small_Value (T));
3714 -- No other types allowed
3717 raise Program_Error;
3720 -- Fall through with Hi and Lo set. Deal with biased case
3723 and then not Is_Fixed_Point_Type (T)
3724 and then not (Is_Enumeration_Type (T)
3725 and then Has_Non_Standard_Rep (T)))
3726 or else Has_Biased_Representation (T)
3732 -- Signed case. Note that we consider types like range 1 .. -1 to be
3733 -- signed for the purpose of computing the size, since the bounds have
3734 -- to be accommodated in the base type.
3736 if Lo < 0 or else Hi < 0 then
3740 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3741 -- Note that we accommodate the case where the bounds cross. This
3742 -- can happen either because of the way the bounds are declared
3743 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3757 -- If both bounds are positive, make sure that both are represen-
3758 -- table in the case where the bounds are crossed. This can happen
3759 -- either because of the way the bounds are declared, or because of
3760 -- the algorithm in Freeze_Fixed_Point_Type.
3766 -- S = size, (can accommodate 0 .. (2**size - 1))
3769 while Hi >= Uint_2 ** S loop
3777 ---------------------------
3778 -- New_Stream_Subprogram --
3779 ---------------------------
3781 procedure New_Stream_Subprogram
3785 Nam : TSS_Name_Type)
3787 Loc : constant Source_Ptr := Sloc (N);
3788 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
3789 Subp_Id : Entity_Id;
3790 Subp_Decl : Node_Id;
3794 Defer_Declaration : constant Boolean :=
3795 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
3796 -- For a tagged type, there is a declaration for each stream attribute
3797 -- at the freeze point, and we must generate only a completion of this
3798 -- declaration. We do the same for private types, because the full view
3799 -- might be tagged. Otherwise we generate a declaration at the point of
3800 -- the attribute definition clause.
3802 function Build_Spec return Node_Id;
3803 -- Used for declaration and renaming declaration, so that this is
3804 -- treated as a renaming_as_body.
3810 function Build_Spec return Node_Id is
3811 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
3814 T_Ref : constant Node_Id := New_Reference_To (Etyp, Loc);
3817 Subp_Id := Make_Defining_Identifier (Loc, Sname);
3819 -- S : access Root_Stream_Type'Class
3821 Formals := New_List (
3822 Make_Parameter_Specification (Loc,
3823 Defining_Identifier =>
3824 Make_Defining_Identifier (Loc, Name_S),
3826 Make_Access_Definition (Loc,
3829 Designated_Type (Etype (F)), Loc))));
3831 if Nam = TSS_Stream_Input then
3832 Spec := Make_Function_Specification (Loc,
3833 Defining_Unit_Name => Subp_Id,
3834 Parameter_Specifications => Formals,
3835 Result_Definition => T_Ref);
3840 Make_Parameter_Specification (Loc,
3841 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
3842 Out_Present => Out_P,
3843 Parameter_Type => T_Ref));
3845 Spec := Make_Procedure_Specification (Loc,
3846 Defining_Unit_Name => Subp_Id,
3847 Parameter_Specifications => Formals);
3853 -- Start of processing for New_Stream_Subprogram
3856 F := First_Formal (Subp);
3858 if Ekind (Subp) = E_Procedure then
3859 Etyp := Etype (Next_Formal (F));
3861 Etyp := Etype (Subp);
3864 -- Prepare subprogram declaration and insert it as an action on the
3865 -- clause node. The visibility for this entity is used to test for
3866 -- visibility of the attribute definition clause (in the sense of
3867 -- 8.3(23) as amended by AI-195).
3869 if not Defer_Declaration then
3871 Make_Subprogram_Declaration (Loc,
3872 Specification => Build_Spec);
3874 -- For a tagged type, there is always a visible declaration for each
3875 -- stream TSS (it is a predefined primitive operation), and the
3876 -- completion of this declaration occurs at the freeze point, which is
3877 -- not always visible at places where the attribute definition clause is
3878 -- visible. So, we create a dummy entity here for the purpose of
3879 -- tracking the visibility of the attribute definition clause itself.
3883 Make_Defining_Identifier (Loc,
3884 Chars => New_External_Name (Sname, 'V'));
3886 Make_Object_Declaration (Loc,
3887 Defining_Identifier => Subp_Id,
3888 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
3891 Insert_Action (N, Subp_Decl);
3892 Set_Entity (N, Subp_Id);
3895 Make_Subprogram_Renaming_Declaration (Loc,
3896 Specification => Build_Spec,
3897 Name => New_Reference_To (Subp, Loc));
3899 if Defer_Declaration then
3900 Set_TSS (Base_Type (Ent), Subp_Id);
3902 Insert_Action (N, Subp_Decl);
3903 Copy_TSS (Subp_Id, Base_Type (Ent));
3905 end New_Stream_Subprogram;
3907 ------------------------
3908 -- Rep_Item_Too_Early --
3909 ------------------------
3911 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
3913 -- Cannot apply non-operational rep items to generic types
3915 if Is_Operational_Item (N) then
3919 and then Is_Generic_Type (Root_Type (T))
3922 ("representation item not allowed for generic type", N);
3926 -- Otherwise check for incomplete type
3928 if Is_Incomplete_Or_Private_Type (T)
3929 and then No (Underlying_Type (T))
3932 ("representation item must be after full type declaration", N);
3935 -- If the type has incomplete components, a representation clause is
3936 -- illegal but stream attributes and Convention pragmas are correct.
3938 elsif Has_Private_Component (T) then
3939 if Nkind (N) = N_Pragma then
3943 ("representation item must appear after type is fully defined",
3950 end Rep_Item_Too_Early;
3952 -----------------------
3953 -- Rep_Item_Too_Late --
3954 -----------------------
3956 function Rep_Item_Too_Late
3959 FOnly : Boolean := False) return Boolean
3962 Parent_Type : Entity_Id;
3965 -- Output the too late message. Note that this is not considered a
3966 -- serious error, since the effect is simply that we ignore the
3967 -- representation clause in this case.
3973 procedure Too_Late is
3975 Error_Msg_N ("|representation item appears too late!", N);
3978 -- Start of processing for Rep_Item_Too_Late
3981 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3982 -- types, which may be frozen if they appear in a representation clause
3983 -- for a local type.
3986 and then not From_With_Type (T)
3989 S := First_Subtype (T);
3991 if Present (Freeze_Node (S)) then
3993 ("?no more representation items for }", Freeze_Node (S), S);
3998 -- Check for case of non-tagged derived type whose parent either has
3999 -- primitive operations, or is a by reference type (RM 13.1(10)).
4003 and then Is_Derived_Type (T)
4004 and then not Is_Tagged_Type (T)
4006 Parent_Type := Etype (Base_Type (T));
4008 if Has_Primitive_Operations (Parent_Type) then
4011 ("primitive operations already defined for&!", N, Parent_Type);
4014 elsif Is_By_Reference_Type (Parent_Type) then
4017 ("parent type & is a by reference type!", N, Parent_Type);
4022 -- No error, link item into head of chain of rep items for the entity,
4023 -- but avoid chaining if we have an overloadable entity, and the pragma
4024 -- is one that can apply to multiple overloaded entities.
4026 if Is_Overloadable (T)
4027 and then Nkind (N) = N_Pragma
4030 Pname : constant Name_Id := Pragma_Name (N);
4032 if Pname = Name_Convention or else
4033 Pname = Name_Import or else
4034 Pname = Name_Export or else
4035 Pname = Name_External or else
4036 Pname = Name_Interface
4043 Record_Rep_Item (T, N);
4045 end Rep_Item_Too_Late;
4047 -------------------------
4048 -- Same_Representation --
4049 -------------------------
4051 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
4052 T1 : constant Entity_Id := Underlying_Type (Typ1);
4053 T2 : constant Entity_Id := Underlying_Type (Typ2);
4056 -- A quick check, if base types are the same, then we definitely have
4057 -- the same representation, because the subtype specific representation
4058 -- attributes (Size and Alignment) do not affect representation from
4059 -- the point of view of this test.
4061 if Base_Type (T1) = Base_Type (T2) then
4064 elsif Is_Private_Type (Base_Type (T2))
4065 and then Base_Type (T1) = Full_View (Base_Type (T2))
4070 -- Tagged types never have differing representations
4072 if Is_Tagged_Type (T1) then
4076 -- Representations are definitely different if conventions differ
4078 if Convention (T1) /= Convention (T2) then
4082 -- Representations are different if component alignments differ
4084 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
4086 (Is_Record_Type (T2) or else Is_Array_Type (T2))
4087 and then Component_Alignment (T1) /= Component_Alignment (T2)
4092 -- For arrays, the only real issue is component size. If we know the
4093 -- component size for both arrays, and it is the same, then that's
4094 -- good enough to know we don't have a change of representation.
4096 if Is_Array_Type (T1) then
4097 if Known_Component_Size (T1)
4098 and then Known_Component_Size (T2)
4099 and then Component_Size (T1) = Component_Size (T2)
4105 -- Types definitely have same representation if neither has non-standard
4106 -- representation since default representations are always consistent.
4107 -- If only one has non-standard representation, and the other does not,
4108 -- then we consider that they do not have the same representation. They
4109 -- might, but there is no way of telling early enough.
4111 if Has_Non_Standard_Rep (T1) then
4112 if not Has_Non_Standard_Rep (T2) then
4116 return not Has_Non_Standard_Rep (T2);
4119 -- Here the two types both have non-standard representation, and we need
4120 -- to determine if they have the same non-standard representation.
4122 -- For arrays, we simply need to test if the component sizes are the
4123 -- same. Pragma Pack is reflected in modified component sizes, so this
4124 -- check also deals with pragma Pack.
4126 if Is_Array_Type (T1) then
4127 return Component_Size (T1) = Component_Size (T2);
4129 -- Tagged types always have the same representation, because it is not
4130 -- possible to specify different representations for common fields.
4132 elsif Is_Tagged_Type (T1) then
4135 -- Case of record types
4137 elsif Is_Record_Type (T1) then
4139 -- Packed status must conform
4141 if Is_Packed (T1) /= Is_Packed (T2) then
4144 -- Otherwise we must check components. Typ2 maybe a constrained
4145 -- subtype with fewer components, so we compare the components
4146 -- of the base types.
4149 Record_Case : declare
4150 CD1, CD2 : Entity_Id;
4152 function Same_Rep return Boolean;
4153 -- CD1 and CD2 are either components or discriminants. This
4154 -- function tests whether the two have the same representation
4160 function Same_Rep return Boolean is
4162 if No (Component_Clause (CD1)) then
4163 return No (Component_Clause (CD2));
4167 Present (Component_Clause (CD2))
4169 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
4171 Esize (CD1) = Esize (CD2);
4175 -- Start of processing for Record_Case
4178 if Has_Discriminants (T1) then
4179 CD1 := First_Discriminant (T1);
4180 CD2 := First_Discriminant (T2);
4182 -- The number of discriminants may be different if the
4183 -- derived type has fewer (constrained by values). The
4184 -- invisible discriminants retain the representation of
4185 -- the original, so the discrepancy does not per se
4186 -- indicate a different representation.
4189 and then Present (CD2)
4191 if not Same_Rep then
4194 Next_Discriminant (CD1);
4195 Next_Discriminant (CD2);
4200 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
4201 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
4203 while Present (CD1) loop
4204 if not Same_Rep then
4207 Next_Component (CD1);
4208 Next_Component (CD2);
4216 -- For enumeration types, we must check each literal to see if the
4217 -- representation is the same. Note that we do not permit enumeration
4218 -- representation clauses for Character and Wide_Character, so these
4219 -- cases were already dealt with.
4221 elsif Is_Enumeration_Type (T1) then
4223 Enumeration_Case : declare
4227 L1 := First_Literal (T1);
4228 L2 := First_Literal (T2);
4230 while Present (L1) loop
4231 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
4241 end Enumeration_Case;
4243 -- Any other types have the same representation for these purposes
4248 end Same_Representation;
4250 --------------------
4251 -- Set_Enum_Esize --
4252 --------------------
4254 procedure Set_Enum_Esize (T : Entity_Id) is
4262 -- Find the minimum standard size (8,16,32,64) that fits
4264 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
4265 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
4268 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
4269 Sz := Standard_Character_Size; -- May be > 8 on some targets
4271 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
4274 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
4277 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
4282 if Hi < Uint_2**08 then
4283 Sz := Standard_Character_Size; -- May be > 8 on some targets
4285 elsif Hi < Uint_2**16 then
4288 elsif Hi < Uint_2**32 then
4291 else pragma Assert (Hi < Uint_2**63);
4296 -- That minimum is the proper size unless we have a foreign convention
4297 -- and the size required is 32 or less, in which case we bump the size
4298 -- up to 32. This is required for C and C++ and seems reasonable for
4299 -- all other foreign conventions.
4301 if Has_Foreign_Convention (T)
4302 and then Esize (T) < Standard_Integer_Size
4304 Init_Esize (T, Standard_Integer_Size);
4310 ------------------------------
4311 -- Validate_Address_Clauses --
4312 ------------------------------
4314 procedure Validate_Address_Clauses is
4316 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
4318 ACCR : Address_Clause_Check_Record
4319 renames Address_Clause_Checks.Table (J);
4330 -- Skip processing of this entry if warning already posted
4332 if not Address_Warning_Posted (ACCR.N) then
4334 Expr := Original_Node (Expression (ACCR.N));
4338 X_Alignment := Alignment (ACCR.X);
4339 Y_Alignment := Alignment (ACCR.Y);
4341 -- Similarly obtain sizes
4343 X_Size := Esize (ACCR.X);
4344 Y_Size := Esize (ACCR.Y);
4346 -- Check for large object overlaying smaller one
4349 and then X_Size > Uint_0
4350 and then X_Size > Y_Size
4353 ("?& overlays smaller object", ACCR.N, ACCR.X);
4355 ("\?program execution may be erroneous", ACCR.N);
4356 Error_Msg_Uint_1 := X_Size;
4358 ("\?size of & is ^", ACCR.N, ACCR.X);
4359 Error_Msg_Uint_1 := Y_Size;
4361 ("\?size of & is ^", ACCR.N, ACCR.Y);
4363 -- Check for inadequate alignment, both of the base object
4364 -- and of the offset, if any.
4366 -- Note: we do not check the alignment if we gave a size
4367 -- warning, since it would likely be redundant.
4369 elsif Y_Alignment /= Uint_0
4370 and then (Y_Alignment < X_Alignment
4373 Nkind (Expr) = N_Attribute_Reference
4375 Attribute_Name (Expr) = Name_Address
4377 Has_Compatible_Alignment
4378 (ACCR.X, Prefix (Expr))
4379 /= Known_Compatible))
4382 ("?specified address for& may be inconsistent "
4386 ("\?program execution may be erroneous (RM 13.3(27))",
4388 Error_Msg_Uint_1 := X_Alignment;
4390 ("\?alignment of & is ^",
4392 Error_Msg_Uint_1 := Y_Alignment;
4394 ("\?alignment of & is ^",
4396 if Y_Alignment >= X_Alignment then
4398 ("\?but offset is not multiple of alignment",
4405 end Validate_Address_Clauses;
4407 -----------------------------------
4408 -- Validate_Unchecked_Conversion --
4409 -----------------------------------
4411 procedure Validate_Unchecked_Conversion
4413 Act_Unit : Entity_Id)
4420 -- Obtain source and target types. Note that we call Ancestor_Subtype
4421 -- here because the processing for generic instantiation always makes
4422 -- subtypes, and we want the original frozen actual types.
4424 -- If we are dealing with private types, then do the check on their
4425 -- fully declared counterparts if the full declarations have been
4426 -- encountered (they don't have to be visible, but they must exist!)
4428 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
4430 if Is_Private_Type (Source)
4431 and then Present (Underlying_Type (Source))
4433 Source := Underlying_Type (Source);
4436 Target := Ancestor_Subtype (Etype (Act_Unit));
4438 -- If either type is generic, the instantiation happens within a generic
4439 -- unit, and there is nothing to check. The proper check
4440 -- will happen when the enclosing generic is instantiated.
4442 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
4446 if Is_Private_Type (Target)
4447 and then Present (Underlying_Type (Target))
4449 Target := Underlying_Type (Target);
4452 -- Source may be unconstrained array, but not target
4454 if Is_Array_Type (Target)
4455 and then not Is_Constrained (Target)
4458 ("unchecked conversion to unconstrained array not allowed", N);
4462 -- Warn if conversion between two different convention pointers
4464 if Is_Access_Type (Target)
4465 and then Is_Access_Type (Source)
4466 and then Convention (Target) /= Convention (Source)
4467 and then Warn_On_Unchecked_Conversion
4469 -- Give warnings for subprogram pointers only on most targets. The
4470 -- exception is VMS, where data pointers can have different lengths
4471 -- depending on the pointer convention.
4473 if Is_Access_Subprogram_Type (Target)
4474 or else Is_Access_Subprogram_Type (Source)
4475 or else OpenVMS_On_Target
4478 ("?conversion between pointers with different conventions!", N);
4482 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
4483 -- warning when compiling GNAT-related sources.
4485 if Warn_On_Unchecked_Conversion
4486 and then not In_Predefined_Unit (N)
4487 and then RTU_Loaded (Ada_Calendar)
4489 (Chars (Source) = Name_Time
4491 Chars (Target) = Name_Time)
4493 -- If Ada.Calendar is loaded and the name of one of the operands is
4494 -- Time, there is a good chance that this is Ada.Calendar.Time.
4497 Calendar_Time : constant Entity_Id :=
4498 Full_View (RTE (RO_CA_Time));
4500 pragma Assert (Present (Calendar_Time));
4502 if Source = Calendar_Time
4503 or else Target = Calendar_Time
4506 ("?representation of 'Time values may change between " &
4507 "'G'N'A'T versions", N);
4512 -- Make entry in unchecked conversion table for later processing by
4513 -- Validate_Unchecked_Conversions, which will check sizes and alignments
4514 -- (using values set by the back-end where possible). This is only done
4515 -- if the appropriate warning is active.
4517 if Warn_On_Unchecked_Conversion then
4518 Unchecked_Conversions.Append
4519 (New_Val => UC_Entry'
4524 -- If both sizes are known statically now, then back end annotation
4525 -- is not required to do a proper check but if either size is not
4526 -- known statically, then we need the annotation.
4528 if Known_Static_RM_Size (Source)
4529 and then Known_Static_RM_Size (Target)
4533 Back_Annotate_Rep_Info := True;
4537 -- If unchecked conversion to access type, and access type is declared
4538 -- in the same unit as the unchecked conversion, then set the
4539 -- No_Strict_Aliasing flag (no strict aliasing is implicit in this
4542 if Is_Access_Type (Target) and then
4543 In_Same_Source_Unit (Target, N)
4545 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
4548 -- Generate N_Validate_Unchecked_Conversion node for back end in
4549 -- case the back end needs to perform special validation checks.
4551 -- Shouldn't this be in Exp_Ch13, since the check only gets done
4552 -- if we have full expansion and the back end is called ???
4555 Make_Validate_Unchecked_Conversion (Sloc (N));
4556 Set_Source_Type (Vnode, Source);
4557 Set_Target_Type (Vnode, Target);
4559 -- If the unchecked conversion node is in a list, just insert before it.
4560 -- If not we have some strange case, not worth bothering about.
4562 if Is_List_Member (N) then
4563 Insert_After (N, Vnode);
4565 end Validate_Unchecked_Conversion;
4567 ------------------------------------
4568 -- Validate_Unchecked_Conversions --
4569 ------------------------------------
4571 procedure Validate_Unchecked_Conversions is
4573 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
4575 T : UC_Entry renames Unchecked_Conversions.Table (N);
4577 Eloc : constant Source_Ptr := T.Eloc;
4578 Source : constant Entity_Id := T.Source;
4579 Target : constant Entity_Id := T.Target;
4585 -- This validation check, which warns if we have unequal sizes for
4586 -- unchecked conversion, and thus potentially implementation
4587 -- dependent semantics, is one of the few occasions on which we
4588 -- use the official RM size instead of Esize. See description in
4589 -- Einfo "Handling of Type'Size Values" for details.
4591 if Serious_Errors_Detected = 0
4592 and then Known_Static_RM_Size (Source)
4593 and then Known_Static_RM_Size (Target)
4595 -- Don't do the check if warnings off for either type, note the
4596 -- deliberate use of OR here instead of OR ELSE to get the flag
4597 -- Warnings_Off_Used set for both types if appropriate.
4599 and then not (Has_Warnings_Off (Source)
4601 Has_Warnings_Off (Target))
4603 Source_Siz := RM_Size (Source);
4604 Target_Siz := RM_Size (Target);
4606 if Source_Siz /= Target_Siz then
4608 ("?types for unchecked conversion have different sizes!",
4611 if All_Errors_Mode then
4612 Error_Msg_Name_1 := Chars (Source);
4613 Error_Msg_Uint_1 := Source_Siz;
4614 Error_Msg_Name_2 := Chars (Target);
4615 Error_Msg_Uint_2 := Target_Siz;
4616 Error_Msg ("\size of % is ^, size of % is ^?", Eloc);
4618 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
4620 if Is_Discrete_Type (Source)
4621 and then Is_Discrete_Type (Target)
4623 if Source_Siz > Target_Siz then
4625 ("\?^ high order bits of source will be ignored!",
4628 elsif Is_Unsigned_Type (Source) then
4630 ("\?source will be extended with ^ high order " &
4631 "zero bits?!", Eloc);
4635 ("\?source will be extended with ^ high order " &
4640 elsif Source_Siz < Target_Siz then
4641 if Is_Discrete_Type (Target) then
4642 if Bytes_Big_Endian then
4644 ("\?target value will include ^ undefined " &
4649 ("\?target value will include ^ undefined " &
4656 ("\?^ trailing bits of target value will be " &
4657 "undefined!", Eloc);
4660 else pragma Assert (Source_Siz > Target_Siz);
4662 ("\?^ trailing bits of source will be ignored!",
4669 -- If both types are access types, we need to check the alignment.
4670 -- If the alignment of both is specified, we can do it here.
4672 if Serious_Errors_Detected = 0
4673 and then Ekind (Source) in Access_Kind
4674 and then Ekind (Target) in Access_Kind
4675 and then Target_Strict_Alignment
4676 and then Present (Designated_Type (Source))
4677 and then Present (Designated_Type (Target))
4680 D_Source : constant Entity_Id := Designated_Type (Source);
4681 D_Target : constant Entity_Id := Designated_Type (Target);
4684 if Known_Alignment (D_Source)
4685 and then Known_Alignment (D_Target)
4688 Source_Align : constant Uint := Alignment (D_Source);
4689 Target_Align : constant Uint := Alignment (D_Target);
4692 if Source_Align < Target_Align
4693 and then not Is_Tagged_Type (D_Source)
4695 -- Suppress warning if warnings suppressed on either
4696 -- type or either designated type. Note the use of
4697 -- OR here instead of OR ELSE. That is intentional,
4698 -- we would like to set flag Warnings_Off_Used in
4699 -- all types for which warnings are suppressed.
4701 and then not (Has_Warnings_Off (D_Source)
4703 Has_Warnings_Off (D_Target)
4705 Has_Warnings_Off (Source)
4707 Has_Warnings_Off (Target))
4709 Error_Msg_Uint_1 := Target_Align;
4710 Error_Msg_Uint_2 := Source_Align;
4711 Error_Msg_Node_1 := D_Target;
4712 Error_Msg_Node_2 := D_Source;
4714 ("?alignment of & (^) is stricter than " &
4715 "alignment of & (^)!", Eloc);
4717 ("\?resulting access value may have invalid " &
4718 "alignment!", Eloc);
4726 end Validate_Unchecked_Conversions;