1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Disp; use Exp_Disp;
33 with Exp_Tss; use Exp_Tss;
34 with Exp_Util; use Exp_Util;
36 with Lib.Xref; use Lib.Xref;
37 with Namet; use Namet;
38 with Nlists; use Nlists;
39 with Nmake; use Nmake;
41 with Restrict; use Restrict;
42 with Rident; use Rident;
43 with Rtsfind; use Rtsfind;
45 with Sem_Aux; use Sem_Aux;
46 with Sem_Ch3; use Sem_Ch3;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Eval; use Sem_Eval;
49 with Sem_Res; use Sem_Res;
50 with Sem_Type; use Sem_Type;
51 with Sem_Util; use Sem_Util;
52 with Sem_Warn; use Sem_Warn;
53 with Sinput; use Sinput;
54 with Snames; use Snames;
55 with Stand; use Stand;
56 with Sinfo; use Sinfo;
57 with Targparm; use Targparm;
58 with Ttypes; use Ttypes;
59 with Tbuild; use Tbuild;
60 with Urealp; use Urealp;
62 with GNAT.Heap_Sort_G;
64 package body Sem_Ch13 is
66 SSU : constant Pos := System_Storage_Unit;
67 -- Convenient short hand for commonly used constant
69 -----------------------
70 -- Local Subprograms --
71 -----------------------
73 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id);
74 -- This routine is called after setting the Esize of type entity Typ.
75 -- The purpose is to deal with the situation where an alignment has been
76 -- inherited from a derived type that is no longer appropriate for the
77 -- new Esize value. In this case, we reset the Alignment to unknown.
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 type
86 -- is declared, as explained in AI-00137 and the corrigendum. Attributes
87 -- that do not specify a representation characteristic are operational
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
114 Biased : Boolean := True);
115 -- If Biased is True, sets Has_Biased_Representation flag for E, and
116 -- outputs a warning message at node N if Warn_On_Biased_Representation is
117 -- is True. This warning inserts the string Msg to describe the construct
120 ----------------------------------------------
121 -- Table for Validate_Unchecked_Conversions --
122 ----------------------------------------------
124 -- The following table collects unchecked conversions for validation.
125 -- Entries are made by Validate_Unchecked_Conversion and then the
126 -- call to Validate_Unchecked_Conversions does the actual error
127 -- checking and posting of warnings. The reason for this delayed
128 -- processing is to take advantage of back-annotations of size and
129 -- alignment values performed by the back end.
131 -- Note: the reason we store a Source_Ptr value instead of a Node_Id
132 -- is that by the time Validate_Unchecked_Conversions is called, Sprint
133 -- will already have modified all Sloc values if the -gnatD option is set.
135 type UC_Entry is record
136 Eloc : Source_Ptr; -- node used for posting warnings
137 Source : Entity_Id; -- source type for unchecked conversion
138 Target : Entity_Id; -- target type for unchecked conversion
141 package Unchecked_Conversions is new Table.Table (
142 Table_Component_Type => UC_Entry,
143 Table_Index_Type => Int,
144 Table_Low_Bound => 1,
146 Table_Increment => 200,
147 Table_Name => "Unchecked_Conversions");
149 ----------------------------------------
150 -- Table for Validate_Address_Clauses --
151 ----------------------------------------
153 -- If an address clause has the form
155 -- for X'Address use Expr
157 -- where Expr is of the form Y'Address or recursively is a reference
158 -- to a constant of either of these forms, and X and Y are entities of
159 -- objects, then if Y has a smaller alignment than X, that merits a
160 -- warning about possible bad alignment. The following table collects
161 -- address clauses of this kind. We put these in a table so that they
162 -- can be checked after the back end has completed annotation of the
163 -- alignments of objects, since we can catch more cases that way.
165 type Address_Clause_Check_Record is record
167 -- The address clause
170 -- The entity of the object overlaying Y
173 -- The entity of the object being overlaid
176 -- Whether the address is offseted within Y
179 package Address_Clause_Checks is new Table.Table (
180 Table_Component_Type => Address_Clause_Check_Record,
181 Table_Index_Type => Int,
182 Table_Low_Bound => 1,
184 Table_Increment => 200,
185 Table_Name => "Address_Clause_Checks");
187 -----------------------------------------
188 -- Adjust_Record_For_Reverse_Bit_Order --
189 -----------------------------------------
191 procedure Adjust_Record_For_Reverse_Bit_Order (R : Entity_Id) is
196 -- Processing depends on version of Ada
198 -- For Ada 95, we just renumber bits within a storage unit. We do the
199 -- same for Ada 83 mode, since we recognize pragma Bit_Order in Ada 83,
200 -- and are free to add this extension.
202 if Ada_Version < Ada_2005 then
203 Comp := First_Component_Or_Discriminant (R);
204 while Present (Comp) loop
205 CC := Component_Clause (Comp);
207 -- If component clause is present, then deal with the non-default
208 -- bit order case for Ada 95 mode.
210 -- We only do this processing for the base type, and in fact that
211 -- is important, since otherwise if there are record subtypes, we
212 -- could reverse the bits once for each subtype, which is wrong.
215 and then Ekind (R) = E_Record_Type
218 CFB : constant Uint := Component_Bit_Offset (Comp);
219 CSZ : constant Uint := Esize (Comp);
220 CLC : constant Node_Id := Component_Clause (Comp);
221 Pos : constant Node_Id := Position (CLC);
222 FB : constant Node_Id := First_Bit (CLC);
224 Storage_Unit_Offset : constant Uint :=
225 CFB / System_Storage_Unit;
227 Start_Bit : constant Uint :=
228 CFB mod System_Storage_Unit;
231 -- Cases where field goes over storage unit boundary
233 if Start_Bit + CSZ > System_Storage_Unit then
235 -- Allow multi-byte field but generate warning
237 if Start_Bit mod System_Storage_Unit = 0
238 and then CSZ mod System_Storage_Unit = 0
241 ("multi-byte field specified with non-standard"
242 & " Bit_Order?", CLC);
244 if Bytes_Big_Endian then
246 ("bytes are not reversed "
247 & "(component is big-endian)?", CLC);
250 ("bytes are not reversed "
251 & "(component is little-endian)?", CLC);
254 -- Do not allow non-contiguous field
258 ("attempt to specify non-contiguous field "
259 & "not permitted", CLC);
261 ("\caused by non-standard Bit_Order "
264 ("\consider possibility of using "
265 & "Ada 2005 mode here", CLC);
268 -- Case where field fits in one storage unit
271 -- Give warning if suspicious component clause
273 if Intval (FB) >= System_Storage_Unit
274 and then Warn_On_Reverse_Bit_Order
277 ("?Bit_Order clause does not affect " &
278 "byte ordering", Pos);
280 Intval (Pos) + Intval (FB) /
283 ("?position normalized to ^ before bit " &
284 "order interpreted", Pos);
287 -- Here is where we fix up the Component_Bit_Offset value
288 -- to account for the reverse bit order. Some examples of
289 -- what needs to be done are:
291 -- First_Bit .. Last_Bit Component_Bit_Offset
303 -- The rule is that the first bit is is obtained by
304 -- subtracting the old ending bit from storage_unit - 1.
306 Set_Component_Bit_Offset
308 (Storage_Unit_Offset * System_Storage_Unit) +
309 (System_Storage_Unit - 1) -
310 (Start_Bit + CSZ - 1));
312 Set_Normalized_First_Bit
314 Component_Bit_Offset (Comp) mod
315 System_Storage_Unit);
320 Next_Component_Or_Discriminant (Comp);
323 -- For Ada 2005, we do machine scalar processing, as fully described In
324 -- AI-133. This involves gathering all components which start at the
325 -- same byte offset and processing them together. Same approach is still
326 -- valid in later versions including Ada 2012.
330 Max_Machine_Scalar_Size : constant Uint :=
332 (Standard_Long_Long_Integer_Size);
333 -- We use this as the maximum machine scalar size
336 SSU : constant Uint := UI_From_Int (System_Storage_Unit);
339 -- This first loop through components does two things. First it
340 -- deals with the case of components with component clauses whose
341 -- length is greater than the maximum machine scalar size (either
342 -- accepting them or rejecting as needed). Second, it counts the
343 -- number of components with component clauses whose length does
344 -- not exceed this maximum for later processing.
347 Comp := First_Component_Or_Discriminant (R);
348 while Present (Comp) loop
349 CC := Component_Clause (Comp);
353 Fbit : constant Uint :=
354 Static_Integer (First_Bit (CC));
357 -- Case of component with size > max machine scalar
359 if Esize (Comp) > Max_Machine_Scalar_Size then
361 -- Must begin on byte boundary
363 if Fbit mod SSU /= 0 then
365 ("illegal first bit value for "
366 & "reverse bit order",
368 Error_Msg_Uint_1 := SSU;
369 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
372 ("\must be a multiple of ^ "
373 & "if size greater than ^",
376 -- Must end on byte boundary
378 elsif Esize (Comp) mod SSU /= 0 then
380 ("illegal last bit value for "
381 & "reverse bit order",
383 Error_Msg_Uint_1 := SSU;
384 Error_Msg_Uint_2 := Max_Machine_Scalar_Size;
387 ("\must be a multiple of ^ if size "
391 -- OK, give warning if enabled
393 elsif Warn_On_Reverse_Bit_Order then
395 ("multi-byte field specified with "
396 & " non-standard Bit_Order?", CC);
398 if Bytes_Big_Endian then
400 ("\bytes are not reversed "
401 & "(component is big-endian)?", CC);
404 ("\bytes are not reversed "
405 & "(component is little-endian)?", CC);
409 -- Case where size is not greater than max machine
410 -- scalar. For now, we just count these.
413 Num_CC := Num_CC + 1;
418 Next_Component_Or_Discriminant (Comp);
421 -- We need to sort the component clauses on the basis of the
422 -- Position values in the clause, so we can group clauses with
423 -- the same Position. together to determine the relevant machine
427 Comps : array (0 .. Num_CC) of Entity_Id;
428 -- Array to collect component and discriminant entities. The
429 -- data starts at index 1, the 0'th entry is for the sort
432 function CP_Lt (Op1, Op2 : Natural) return Boolean;
433 -- Compare routine for Sort
435 procedure CP_Move (From : Natural; To : Natural);
436 -- Move routine for Sort
438 package Sorting is new GNAT.Heap_Sort_G (CP_Move, CP_Lt);
442 -- Start and stop positions in the component list of the set of
443 -- components with the same starting position (that constitute
444 -- components in a single machine scalar).
447 -- Maximum last bit value of any component in this set
450 -- Corresponding machine scalar size
456 function CP_Lt (Op1, Op2 : Natural) return Boolean is
458 return Position (Component_Clause (Comps (Op1))) <
459 Position (Component_Clause (Comps (Op2)));
466 procedure CP_Move (From : Natural; To : Natural) is
468 Comps (To) := Comps (From);
471 -- Start of processing for Sort_CC
474 -- Collect the component clauses
477 Comp := First_Component_Or_Discriminant (R);
478 while Present (Comp) loop
479 if Present (Component_Clause (Comp))
480 and then Esize (Comp) <= Max_Machine_Scalar_Size
482 Num_CC := Num_CC + 1;
483 Comps (Num_CC) := Comp;
486 Next_Component_Or_Discriminant (Comp);
489 -- Sort by ascending position number
491 Sorting.Sort (Num_CC);
493 -- We now have all the components whose size does not exceed
494 -- the max machine scalar value, sorted by starting position.
495 -- In this loop we gather groups of clauses starting at the
496 -- same position, to process them in accordance with AI-133.
499 while Stop < Num_CC loop
504 (Last_Bit (Component_Clause (Comps (Start))));
505 while Stop < Num_CC loop
507 (Position (Component_Clause (Comps (Stop + 1)))) =
509 (Position (Component_Clause (Comps (Stop))))
517 (Component_Clause (Comps (Stop)))));
523 -- Now we have a group of component clauses from Start to
524 -- Stop whose positions are identical, and MaxL is the
525 -- maximum last bit value of any of these components.
527 -- We need to determine the corresponding machine scalar
528 -- size. This loop assumes that machine scalar sizes are
529 -- even, and that each possible machine scalar has twice
530 -- as many bits as the next smaller one.
532 MSS := Max_Machine_Scalar_Size;
534 and then (MSS / 2) >= SSU
535 and then (MSS / 2) > MaxL
540 -- Here is where we fix up the Component_Bit_Offset value
541 -- to account for the reverse bit order. Some examples of
542 -- what needs to be done for the case of a machine scalar
545 -- First_Bit .. Last_Bit Component_Bit_Offset
557 -- The rule is that the first bit is obtained by subtracting
558 -- the old ending bit from machine scalar size - 1.
560 for C in Start .. Stop loop
562 Comp : constant Entity_Id := Comps (C);
563 CC : constant Node_Id :=
564 Component_Clause (Comp);
565 LB : constant Uint :=
566 Static_Integer (Last_Bit (CC));
567 NFB : constant Uint := MSS - Uint_1 - LB;
568 NLB : constant Uint := NFB + Esize (Comp) - 1;
569 Pos : constant Uint :=
570 Static_Integer (Position (CC));
573 if Warn_On_Reverse_Bit_Order then
574 Error_Msg_Uint_1 := MSS;
576 ("info: reverse bit order in machine " &
577 "scalar of length^?", First_Bit (CC));
578 Error_Msg_Uint_1 := NFB;
579 Error_Msg_Uint_2 := NLB;
581 if Bytes_Big_Endian then
583 ("?\info: big-endian range for "
584 & "component & is ^ .. ^",
585 First_Bit (CC), Comp);
588 ("?\info: little-endian range "
589 & "for component & is ^ .. ^",
590 First_Bit (CC), Comp);
594 Set_Component_Bit_Offset (Comp, Pos * SSU + NFB);
595 Set_Normalized_First_Bit (Comp, NFB mod SSU);
602 end Adjust_Record_For_Reverse_Bit_Order;
604 --------------------------------------
605 -- Alignment_Check_For_Esize_Change --
606 --------------------------------------
608 procedure Alignment_Check_For_Esize_Change (Typ : Entity_Id) is
610 -- If the alignment is known, and not set by a rep clause, and is
611 -- inconsistent with the size being set, then reset it to unknown,
612 -- we assume in this case that the size overrides the inherited
613 -- alignment, and that the alignment must be recomputed.
615 if Known_Alignment (Typ)
616 and then not Has_Alignment_Clause (Typ)
617 and then Esize (Typ) mod (Alignment (Typ) * SSU) /= 0
619 Init_Alignment (Typ);
621 end Alignment_Check_For_Esize_Change;
623 -----------------------------------
624 -- Analyze_Aspect_Specifications --
625 -----------------------------------
627 procedure Analyze_Aspect_Specifications
636 Ins_Node : Node_Id := N;
637 -- Insert pragmas (other than Pre/Post) after this node
639 -- The general processing involves building an attribute definition
640 -- clause or a pragma node that corresponds to the access type. Then
641 -- one of two things happens:
643 -- If we are required to delay the evaluation of this aspect to the
644 -- freeze point, we preanalyze the relevant argument, and then attach
645 -- the corresponding pragma/attribute definition clause to the aspect
646 -- specification node, which is then placed in the Rep Item chain.
647 -- In this case we mark the entity with the Has_Delayed_Aspects flag,
648 -- and we evaluate the rep item at the freeze point.
650 -- If no delay is required, we just insert the pragma or attribute
651 -- after the declaration, and it will get processed by the normal
652 -- circuit. The From_Aspect_Specification flag is set on the pragma
653 -- or attribute definition node in either case to activate special
654 -- processing (e.g. not traversing the list of homonyms for inline).
656 Delay_Required : Boolean;
657 -- Set True if delay is required
665 while Present (Aspect) loop
667 Loc : constant Source_Ptr := Sloc (Aspect);
668 Id : constant Node_Id := Identifier (Aspect);
669 Expr : constant Node_Id := Expression (Aspect);
670 Nam : constant Name_Id := Chars (Id);
671 A_Id : constant Aspect_Id := Get_Aspect_Id (Nam);
675 Eloc : Source_Ptr := Sloc (Expr);
676 -- Source location of expression, modified when we split PPC's
679 Set_Entity (Aspect, E);
680 Ent := New_Occurrence_Of (E, Sloc (Id));
682 -- Check for duplicate aspect. Note that the Comes_From_Source
683 -- test allows duplicate Pre/Post's that we generate internally
684 -- to escape being flagged here.
687 while Anod /= Aspect loop
688 if Nam = Chars (Identifier (Anod))
689 and then Comes_From_Source (Aspect)
691 Error_Msg_Name_1 := Nam;
692 Error_Msg_Sloc := Sloc (Anod);
694 -- Case of same aspect specified twice
696 if Class_Present (Anod) = Class_Present (Aspect) then
697 if not Class_Present (Anod) then
699 ("aspect% for & previously given#",
703 ("aspect `%''Class` for & previously given#",
707 -- Case of Pre and Pre'Class both specified
709 elsif Nam = Name_Pre then
710 if Class_Present (Aspect) then
712 ("aspect `Pre''Class` for & is not allowed here",
715 ("\since aspect `Pre` previously given#",
720 ("aspect `Pre` for & is not allowed here",
723 ("\since aspect `Pre''Class` previously given#",
734 -- Processing based on specific aspect
738 -- No_Aspect should be impossible
743 -- Aspects taking an optional boolean argument. For all of
744 -- these we just create a matching pragma and insert it,
745 -- setting flag Cancel_Aspect if the expression is False.
747 when Aspect_Ada_2005 |
750 Aspect_Atomic_Components |
751 Aspect_Discard_Names |
752 Aspect_Favor_Top_Level |
754 Aspect_Inline_Always |
757 Aspect_Persistent_BSS |
758 Aspect_Preelaborable_Initialization |
759 Aspect_Pure_Function |
761 Aspect_Suppress_Debug_Info |
762 Aspect_Unchecked_Union |
763 Aspect_Universal_Aliasing |
765 Aspect_Unreferenced |
766 Aspect_Unreferenced_Objects |
768 Aspect_Volatile_Components =>
770 -- Build corresponding pragma node
774 Pragma_Argument_Associations => New_List (Ent),
776 Make_Identifier (Sloc (Id), Chars (Id)));
778 -- Deal with missing expression case, delay never needed
781 Delay_Required := False;
783 -- Expression is present
786 Preanalyze_Spec_Expression (Expr, Standard_Boolean);
788 -- If preanalysis gives a static expression, we don't
789 -- need to delay (this will happen often in practice).
791 if Is_OK_Static_Expression (Expr) then
792 Delay_Required := False;
794 if Is_False (Expr_Value (Expr)) then
795 Set_Aspect_Cancel (Aitem);
798 -- If we don't get a static expression, then delay, the
799 -- expression may turn out static by freeze time.
802 Delay_Required := True;
806 -- Aspects corresponding to attribute definition clauses with
807 -- the exception of Address which is treated specially.
809 when Aspect_Address |
812 Aspect_Component_Size |
813 Aspect_External_Tag |
814 Aspect_Machine_Radix |
817 Aspect_Storage_Pool |
818 Aspect_Storage_Size |
822 -- Preanalyze the expression with the appropriate type
825 when Aspect_Address =>
826 T := RTE (RE_Address);
827 when Aspect_Bit_Order =>
828 T := RTE (RE_Bit_Order);
829 when Aspect_External_Tag =>
830 T := Standard_String;
831 when Aspect_Storage_Pool =>
832 T := Class_Wide_Type (RTE (RE_Root_Storage_Pool));
837 Preanalyze_Spec_Expression (Expr, T);
839 -- Construct the attribute definition clause
842 Make_Attribute_Definition_Clause (Loc,
845 Expression => Relocate_Node (Expr));
847 -- We do not need a delay if we have a static expression
849 if Is_OK_Static_Expression (Expression (Aitem)) then
850 Delay_Required := False;
852 -- Here a delay is required
855 Delay_Required := True;
858 -- Aspects corresponding to pragmas with two arguments, where
859 -- the first argument is a local name referring to the entity,
860 -- and the second argument is the aspect definition expression.
862 when Aspect_Suppress |
865 -- Construct the pragma
869 Pragma_Argument_Associations => New_List (
870 New_Occurrence_Of (E, Eloc),
871 Relocate_Node (Expr)),
873 Make_Identifier (Sloc (Id), Chars (Id)));
875 -- We don't have to play the delay game here, since the only
876 -- values are check names which don't get analyzed anyway.
878 Delay_Required := False;
880 -- Aspects corresponding to stream routines
887 -- Construct the attribute definition clause
890 Make_Attribute_Definition_Clause (Loc,
893 Expression => Relocate_Node (Expr));
895 -- These are always delayed (typically the subprogram that
896 -- is referenced cannot have been declared yet, since it has
897 -- a reference to the type for which this aspect is defined.
899 Delay_Required := True;
901 -- Aspects corresponding to pragmas with two arguments, where
902 -- the second argument is a local name referring to the entity,
903 -- and the first argument is the aspect definition expression.
905 when Aspect_Warnings =>
907 -- Construct the pragma
911 Pragma_Argument_Associations => New_List (
912 Relocate_Node (Expr),
913 New_Occurrence_Of (E, Eloc)),
915 Make_Identifier (Sloc (Id), Chars (Id)),
916 Class_Present => Class_Present (Aspect));
918 -- We don't have to play the delay game here, since the only
919 -- values are check names which don't get analyzed anyway.
921 Delay_Required := False;
923 -- Aspects Pre/Post generate Precondition/Postcondition pragmas
924 -- with a first argument that is the expression, and a second
925 -- argument that is an informative message if the test fails.
926 -- This is inserted right after the declaration, to get the
927 -- required pragma placement.
929 when Aspect_Pre | Aspect_Post => declare
933 if A_Id = Aspect_Pre then
934 Pname := Name_Precondition;
936 Pname := Name_Postcondition;
939 -- If the expressions is of the form A and then B, then
940 -- we generate separate Pre/Post aspects for the separate
941 -- clauses. Since we allow multiple pragmas, there is no
942 -- problem in allowing multiple Pre/Post aspects internally.
944 -- We do not do this for Pre'Class, since we have to put
945 -- these conditions together in a complex OR expression
947 if Pname = Name_Postcondition
948 or else not Class_Present (Aspect)
950 while Nkind (Expr) = N_And_Then loop
951 Insert_After (Aspect,
952 Make_Aspect_Specification (Sloc (Right_Opnd (Expr)),
953 Identifier => Identifier (Aspect),
954 Expression => Relocate_Node (Right_Opnd (Expr)),
955 Class_Present => Class_Present (Aspect),
957 Rewrite (Expr, Relocate_Node (Left_Opnd (Expr)));
962 -- Build the precondition/postcondition pragma
967 Make_Identifier (Sloc (Id),
969 Class_Present => Class_Present (Aspect),
970 Split_PPC => Split_PPC (Aspect),
971 Pragma_Argument_Associations => New_List (
972 Make_Pragma_Argument_Association (Eloc,
974 Expression => Relocate_Node (Expr))));
976 -- Add message unless exception messages are suppressed
978 if not Opt.Exception_Locations_Suppressed then
979 Append_To (Pragma_Argument_Associations (Aitem),
980 Make_Pragma_Argument_Association (Eloc,
981 Chars => Name_Message,
983 Make_String_Literal (Eloc,
985 & Get_Name_String (Pname)
987 & Build_Location_String (Eloc))));
990 Set_From_Aspect_Specification (Aitem, True);
992 -- For Pre/Post cases, insert immediately after the entity
993 -- declaration, since that is the required pragma placement.
994 -- Note that for these aspects, we do not have to worry
995 -- about delay issues, since the pragmas themselves deal
996 -- with delay of visibility for the expression analysis.
998 -- If the entity is a library-level subprogram, the pre/
999 -- postconditions must be treated as late pragmas.
1001 if Nkind (Parent (N)) = N_Compilation_Unit then
1002 Add_Global_Declaration (Aitem);
1004 Insert_After (N, Aitem);
1010 -- Aspects currently unimplemented
1012 when Aspect_Invariant |
1015 Error_Msg_N ("aspect& not implemented", Identifier (Aspect));
1019 Set_From_Aspect_Specification (Aitem, True);
1021 -- If a delay is required, we delay the freeze (not much point in
1022 -- delaying the aspect if we don't delay the freeze!). The pragma
1023 -- or clause is then attached to the aspect specification which
1024 -- is placed in the rep item list.
1026 if Delay_Required then
1027 Ensure_Freeze_Node (E);
1028 Set_Is_Delayed_Aspect (Aitem);
1029 Set_Has_Delayed_Aspects (E);
1030 Set_Aspect_Rep_Item (Aspect, Aitem);
1031 Record_Rep_Item (E, Aspect);
1033 -- If no delay required, insert the pragma/clause in the tree
1036 -- For Pre/Post cases, insert immediately after the entity
1037 -- declaration, since that is the required pragma placement.
1039 if A_Id = Aspect_Pre or else A_Id = Aspect_Post then
1040 Insert_After (N, Aitem);
1042 -- For all other cases, insert in sequence
1045 Insert_After (Ins_Node, Aitem);
1054 end Analyze_Aspect_Specifications;
1056 -----------------------
1057 -- Analyze_At_Clause --
1058 -----------------------
1060 -- An at clause is replaced by the corresponding Address attribute
1061 -- definition clause that is the preferred approach in Ada 95.
1063 procedure Analyze_At_Clause (N : Node_Id) is
1064 CS : constant Boolean := Comes_From_Source (N);
1067 -- This is an obsolescent feature
1069 Check_Restriction (No_Obsolescent_Features, N);
1071 if Warn_On_Obsolescent_Feature then
1073 ("at clause is an obsolescent feature (RM J.7(2))?", N);
1075 ("\use address attribute definition clause instead?", N);
1078 -- Rewrite as address clause
1081 Make_Attribute_Definition_Clause (Sloc (N),
1082 Name => Identifier (N),
1083 Chars => Name_Address,
1084 Expression => Expression (N)));
1086 -- We preserve Comes_From_Source, since logically the clause still
1087 -- comes from the source program even though it is changed in form.
1089 Set_Comes_From_Source (N, CS);
1091 -- Analyze rewritten clause
1093 Analyze_Attribute_Definition_Clause (N);
1094 end Analyze_At_Clause;
1096 -----------------------------------------
1097 -- Analyze_Attribute_Definition_Clause --
1098 -----------------------------------------
1100 procedure Analyze_Attribute_Definition_Clause (N : Node_Id) is
1101 Loc : constant Source_Ptr := Sloc (N);
1102 Nam : constant Node_Id := Name (N);
1103 Attr : constant Name_Id := Chars (N);
1104 Expr : constant Node_Id := Expression (N);
1105 Id : constant Attribute_Id := Get_Attribute_Id (Attr);
1109 FOnly : Boolean := False;
1110 -- Reset to True for subtype specific attribute (Alignment, Size)
1111 -- and for stream attributes, i.e. those cases where in the call
1112 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
1113 -- rules are checked. Note that the case of stream attributes is not
1114 -- clear from the RM, but see AI95-00137. Also, the RM seems to
1115 -- disallow Storage_Size for derived task types, but that is also
1116 -- clearly unintentional.
1118 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type);
1119 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
1120 -- definition clauses.
1122 function Duplicate_Clause return Boolean;
1123 -- This routine checks if the aspect for U_Ent being given by attribute
1124 -- definition clause N is for an aspect that has already been specified,
1125 -- and if so gives an error message. If there is a duplicate, True is
1126 -- returned, otherwise if there is no error, False is returned.
1128 -----------------------------------
1129 -- Analyze_Stream_TSS_Definition --
1130 -----------------------------------
1132 procedure Analyze_Stream_TSS_Definition (TSS_Nam : TSS_Name_Type) is
1133 Subp : Entity_Id := Empty;
1138 Is_Read : constant Boolean := (TSS_Nam = TSS_Stream_Read);
1140 function Has_Good_Profile (Subp : Entity_Id) return Boolean;
1141 -- Return true if the entity is a subprogram with an appropriate
1142 -- profile for the attribute being defined.
1144 ----------------------
1145 -- Has_Good_Profile --
1146 ----------------------
1148 function Has_Good_Profile (Subp : Entity_Id) return Boolean is
1150 Is_Function : constant Boolean := (TSS_Nam = TSS_Stream_Input);
1151 Expected_Ekind : constant array (Boolean) of Entity_Kind :=
1152 (False => E_Procedure, True => E_Function);
1156 if Ekind (Subp) /= Expected_Ekind (Is_Function) then
1160 F := First_Formal (Subp);
1163 or else Ekind (Etype (F)) /= E_Anonymous_Access_Type
1164 or else Designated_Type (Etype (F)) /=
1165 Class_Wide_Type (RTE (RE_Root_Stream_Type))
1170 if not Is_Function then
1174 Expected_Mode : constant array (Boolean) of Entity_Kind :=
1175 (False => E_In_Parameter,
1176 True => E_Out_Parameter);
1178 if Parameter_Mode (F) /= Expected_Mode (Is_Read) then
1186 Typ := Etype (Subp);
1189 return Base_Type (Typ) = Base_Type (Ent)
1190 and then No (Next_Formal (F));
1191 end Has_Good_Profile;
1193 -- Start of processing for Analyze_Stream_TSS_Definition
1198 if not Is_Type (U_Ent) then
1199 Error_Msg_N ("local name must be a subtype", Nam);
1203 Pnam := TSS (Base_Type (U_Ent), TSS_Nam);
1205 -- If Pnam is present, it can be either inherited from an ancestor
1206 -- type (in which case it is legal to redefine it for this type), or
1207 -- be a previous definition of the attribute for the same type (in
1208 -- which case it is illegal).
1210 -- In the first case, it will have been analyzed already, and we
1211 -- can check that its profile does not match the expected profile
1212 -- for a stream attribute of U_Ent. In the second case, either Pnam
1213 -- has been analyzed (and has the expected profile), or it has not
1214 -- been analyzed yet (case of a type that has not been frozen yet
1215 -- and for which the stream attribute has been set using Set_TSS).
1218 and then (No (First_Entity (Pnam)) or else Has_Good_Profile (Pnam))
1220 Error_Msg_Sloc := Sloc (Pnam);
1221 Error_Msg_Name_1 := Attr;
1222 Error_Msg_N ("% attribute already defined #", Nam);
1228 if Is_Entity_Name (Expr) then
1229 if not Is_Overloaded (Expr) then
1230 if Has_Good_Profile (Entity (Expr)) then
1231 Subp := Entity (Expr);
1235 Get_First_Interp (Expr, I, It);
1236 while Present (It.Nam) loop
1237 if Has_Good_Profile (It.Nam) then
1242 Get_Next_Interp (I, It);
1247 if Present (Subp) then
1248 if Is_Abstract_Subprogram (Subp) then
1249 Error_Msg_N ("stream subprogram must not be abstract", Expr);
1253 Set_Entity (Expr, Subp);
1254 Set_Etype (Expr, Etype (Subp));
1256 New_Stream_Subprogram (N, U_Ent, Subp, TSS_Nam);
1259 Error_Msg_Name_1 := Attr;
1260 Error_Msg_N ("incorrect expression for% attribute", Expr);
1262 end Analyze_Stream_TSS_Definition;
1264 ----------------------
1265 -- Duplicate_Clause --
1266 ----------------------
1268 function Duplicate_Clause return Boolean is
1272 -- Nothing to do if this attribute definition clause comes from
1273 -- an aspect specification, since we could not be duplicating an
1274 -- explicit clause, and we dealt with the case of duplicated aspects
1275 -- in Analyze_Aspect_Specifications.
1277 if From_Aspect_Specification (N) then
1281 -- Otherwise current clause may duplicate previous clause or a
1282 -- previously given aspect specification for the same aspect.
1284 A := Get_Rep_Item_For_Entity (U_Ent, Chars (N));
1287 if Entity (A) = U_Ent then
1288 Error_Msg_Name_1 := Chars (N);
1289 Error_Msg_Sloc := Sloc (A);
1290 Error_Msg_NE ("aspect% for & previously given#", N, U_Ent);
1296 end Duplicate_Clause;
1298 -- Start of processing for Analyze_Attribute_Definition_Clause
1301 -- Process Ignore_Rep_Clauses option
1303 if Ignore_Rep_Clauses then
1306 -- The following should be ignored. They do not affect legality
1307 -- and may be target dependent. The basic idea of -gnatI is to
1308 -- ignore any rep clauses that may be target dependent but do not
1309 -- affect legality (except possibly to be rejected because they
1310 -- are incompatible with the compilation target).
1312 when Attribute_Alignment |
1313 Attribute_Bit_Order |
1314 Attribute_Component_Size |
1315 Attribute_Machine_Radix |
1316 Attribute_Object_Size |
1319 Attribute_Stream_Size |
1320 Attribute_Value_Size =>
1322 Rewrite (N, Make_Null_Statement (Sloc (N)));
1325 -- The following should not be ignored, because in the first place
1326 -- they are reasonably portable, and should not cause problems in
1327 -- compiling code from another target, and also they do affect
1328 -- legality, e.g. failing to provide a stream attribute for a
1329 -- type may make a program illegal.
1331 when Attribute_External_Tag |
1335 Attribute_Storage_Pool |
1336 Attribute_Storage_Size |
1340 -- Other cases are errors ("attribute& cannot be set with
1341 -- definition clause"), which will be caught below.
1349 Ent := Entity (Nam);
1351 if Rep_Item_Too_Early (Ent, N) then
1355 -- Rep clause applies to full view of incomplete type or private type if
1356 -- we have one (if not, this is a premature use of the type). However,
1357 -- certain semantic checks need to be done on the specified entity (i.e.
1358 -- the private view), so we save it in Ent.
1360 if Is_Private_Type (Ent)
1361 and then Is_Derived_Type (Ent)
1362 and then not Is_Tagged_Type (Ent)
1363 and then No (Full_View (Ent))
1365 -- If this is a private type whose completion is a derivation from
1366 -- another private type, there is no full view, and the attribute
1367 -- belongs to the type itself, not its underlying parent.
1371 elsif Ekind (Ent) = E_Incomplete_Type then
1373 -- The attribute applies to the full view, set the entity of the
1374 -- attribute definition accordingly.
1376 Ent := Underlying_Type (Ent);
1378 Set_Entity (Nam, Ent);
1381 U_Ent := Underlying_Type (Ent);
1384 -- Complete other routine error checks
1386 if Etype (Nam) = Any_Type then
1389 elsif Scope (Ent) /= Current_Scope then
1390 Error_Msg_N ("entity must be declared in this scope", Nam);
1393 elsif No (U_Ent) then
1396 elsif Is_Type (U_Ent)
1397 and then not Is_First_Subtype (U_Ent)
1398 and then Id /= Attribute_Object_Size
1399 and then Id /= Attribute_Value_Size
1400 and then not From_At_Mod (N)
1402 Error_Msg_N ("cannot specify attribute for subtype", Nam);
1406 Set_Entity (N, U_Ent);
1408 -- Switch on particular attribute
1416 -- Address attribute definition clause
1418 when Attribute_Address => Address : begin
1420 -- A little error check, catch for X'Address use X'Address;
1422 if Nkind (Nam) = N_Identifier
1423 and then Nkind (Expr) = N_Attribute_Reference
1424 and then Attribute_Name (Expr) = Name_Address
1425 and then Nkind (Prefix (Expr)) = N_Identifier
1426 and then Chars (Nam) = Chars (Prefix (Expr))
1429 ("address for & is self-referencing", Prefix (Expr), Ent);
1433 -- Not that special case, carry on with analysis of expression
1435 Analyze_And_Resolve (Expr, RTE (RE_Address));
1437 -- Even when ignoring rep clauses we need to indicate that the
1438 -- entity has an address clause and thus it is legal to declare
1441 if Ignore_Rep_Clauses then
1442 if Ekind_In (U_Ent, E_Variable, E_Constant) then
1443 Record_Rep_Item (U_Ent, N);
1449 if Duplicate_Clause then
1452 -- Case of address clause for subprogram
1454 elsif Is_Subprogram (U_Ent) then
1455 if Has_Homonym (U_Ent) then
1457 ("address clause cannot be given " &
1458 "for overloaded subprogram",
1463 -- For subprograms, all address clauses are permitted, and we
1464 -- mark the subprogram as having a deferred freeze so that Gigi
1465 -- will not elaborate it too soon.
1467 -- Above needs more comments, what is too soon about???
1469 Set_Has_Delayed_Freeze (U_Ent);
1471 -- Case of address clause for entry
1473 elsif Ekind (U_Ent) = E_Entry then
1474 if Nkind (Parent (N)) = N_Task_Body then
1476 ("entry address must be specified in task spec", Nam);
1480 -- For entries, we require a constant address
1482 Check_Constant_Address_Clause (Expr, U_Ent);
1484 -- Special checks for task types
1486 if Is_Task_Type (Scope (U_Ent))
1487 and then Comes_From_Source (Scope (U_Ent))
1490 ("?entry address declared for entry in task type", N);
1492 ("\?only one task can be declared of this type", N);
1495 -- Entry address clauses are obsolescent
1497 Check_Restriction (No_Obsolescent_Features, N);
1499 if Warn_On_Obsolescent_Feature then
1501 ("attaching interrupt to task entry is an " &
1502 "obsolescent feature (RM J.7.1)?", N);
1504 ("\use interrupt procedure instead?", N);
1507 -- Case of an address clause for a controlled object which we
1508 -- consider to be erroneous.
1510 elsif Is_Controlled (Etype (U_Ent))
1511 or else Has_Controlled_Component (Etype (U_Ent))
1514 ("?controlled object& must not be overlaid", Nam, U_Ent);
1516 ("\?Program_Error will be raised at run time", Nam);
1517 Insert_Action (Declaration_Node (U_Ent),
1518 Make_Raise_Program_Error (Loc,
1519 Reason => PE_Overlaid_Controlled_Object));
1522 -- Case of address clause for a (non-controlled) object
1525 Ekind (U_Ent) = E_Variable
1527 Ekind (U_Ent) = E_Constant
1530 Expr : constant Node_Id := Expression (N);
1535 -- Exported variables cannot have an address clause, because
1536 -- this cancels the effect of the pragma Export.
1538 if Is_Exported (U_Ent) then
1540 ("cannot export object with address clause", Nam);
1544 Find_Overlaid_Entity (N, O_Ent, Off);
1546 -- Overlaying controlled objects is erroneous
1549 and then (Has_Controlled_Component (Etype (O_Ent))
1550 or else Is_Controlled (Etype (O_Ent)))
1553 ("?cannot overlay with controlled object", Expr);
1555 ("\?Program_Error will be raised at run time", Expr);
1556 Insert_Action (Declaration_Node (U_Ent),
1557 Make_Raise_Program_Error (Loc,
1558 Reason => PE_Overlaid_Controlled_Object));
1561 elsif Present (O_Ent)
1562 and then Ekind (U_Ent) = E_Constant
1563 and then not Is_Constant_Object (O_Ent)
1565 Error_Msg_N ("constant overlays a variable?", Expr);
1567 elsif Present (Renamed_Object (U_Ent)) then
1569 ("address clause not allowed"
1570 & " for a renaming declaration (RM 13.1(6))", Nam);
1573 -- Imported variables can have an address clause, but then
1574 -- the import is pretty meaningless except to suppress
1575 -- initializations, so we do not need such variables to
1576 -- be statically allocated (and in fact it causes trouble
1577 -- if the address clause is a local value).
1579 elsif Is_Imported (U_Ent) then
1580 Set_Is_Statically_Allocated (U_Ent, False);
1583 -- We mark a possible modification of a variable with an
1584 -- address clause, since it is likely aliasing is occurring.
1586 Note_Possible_Modification (Nam, Sure => False);
1588 -- Here we are checking for explicit overlap of one variable
1589 -- by another, and if we find this then mark the overlapped
1590 -- variable as also being volatile to prevent unwanted
1591 -- optimizations. This is a significant pessimization so
1592 -- avoid it when there is an offset, i.e. when the object
1593 -- is composite; they cannot be optimized easily anyway.
1596 and then Is_Object (O_Ent)
1599 Set_Treat_As_Volatile (O_Ent);
1602 -- Legality checks on the address clause for initialized
1603 -- objects is deferred until the freeze point, because
1604 -- a subsequent pragma might indicate that the object is
1605 -- imported and thus not initialized.
1607 Set_Has_Delayed_Freeze (U_Ent);
1609 -- If an initialization call has been generated for this
1610 -- object, it needs to be deferred to after the freeze node
1611 -- we have just now added, otherwise GIGI will see a
1612 -- reference to the variable (as actual to the IP call)
1613 -- before its definition.
1616 Init_Call : constant Node_Id := Find_Init_Call (U_Ent, N);
1618 if Present (Init_Call) then
1620 Append_Freeze_Action (U_Ent, Init_Call);
1624 if Is_Exported (U_Ent) then
1626 ("& cannot be exported if an address clause is given",
1629 ("\define and export a variable " &
1630 "that holds its address instead",
1634 -- Entity has delayed freeze, so we will generate an
1635 -- alignment check at the freeze point unless suppressed.
1637 if not Range_Checks_Suppressed (U_Ent)
1638 and then not Alignment_Checks_Suppressed (U_Ent)
1640 Set_Check_Address_Alignment (N);
1643 -- Kill the size check code, since we are not allocating
1644 -- the variable, it is somewhere else.
1646 Kill_Size_Check_Code (U_Ent);
1648 -- If the address clause is of the form:
1650 -- for Y'Address use X'Address
1654 -- Const : constant Address := X'Address;
1656 -- for Y'Address use Const;
1658 -- then we make an entry in the table for checking the size
1659 -- and alignment of the overlaying variable. We defer this
1660 -- check till after code generation to take full advantage
1661 -- of the annotation done by the back end. This entry is
1662 -- only made if the address clause comes from source.
1663 -- If the entity has a generic type, the check will be
1664 -- performed in the instance if the actual type justifies
1665 -- it, and we do not insert the clause in the table to
1666 -- prevent spurious warnings.
1668 if Address_Clause_Overlay_Warnings
1669 and then Comes_From_Source (N)
1670 and then Present (O_Ent)
1671 and then Is_Object (O_Ent)
1673 if not Is_Generic_Type (Etype (U_Ent)) then
1674 Address_Clause_Checks.Append ((N, U_Ent, O_Ent, Off));
1677 -- If variable overlays a constant view, and we are
1678 -- warning on overlays, then mark the variable as
1679 -- overlaying a constant (we will give warnings later
1680 -- if this variable is assigned).
1682 if Is_Constant_Object (O_Ent)
1683 and then Ekind (U_Ent) = E_Variable
1685 Set_Overlays_Constant (U_Ent);
1690 -- Not a valid entity for an address clause
1693 Error_Msg_N ("address cannot be given for &", Nam);
1701 -- Alignment attribute definition clause
1703 when Attribute_Alignment => Alignment : declare
1704 Align : constant Uint := Get_Alignment_Value (Expr);
1709 if not Is_Type (U_Ent)
1710 and then Ekind (U_Ent) /= E_Variable
1711 and then Ekind (U_Ent) /= E_Constant
1713 Error_Msg_N ("alignment cannot be given for &", Nam);
1715 elsif Duplicate_Clause then
1718 elsif Align /= No_Uint then
1719 Set_Has_Alignment_Clause (U_Ent);
1720 Set_Alignment (U_Ent, Align);
1722 -- For an array type, U_Ent is the first subtype. In that case,
1723 -- also set the alignment of the anonymous base type so that
1724 -- other subtypes (such as the itypes for aggregates of the
1725 -- type) also receive the expected alignment.
1727 if Is_Array_Type (U_Ent) then
1728 Set_Alignment (Base_Type (U_Ent), Align);
1737 -- Bit_Order attribute definition clause
1739 when Attribute_Bit_Order => Bit_Order : declare
1741 if not Is_Record_Type (U_Ent) then
1743 ("Bit_Order can only be defined for record type", Nam);
1745 elsif Duplicate_Clause then
1749 Analyze_And_Resolve (Expr, RTE (RE_Bit_Order));
1751 if Etype (Expr) = Any_Type then
1754 elsif not Is_Static_Expression (Expr) then
1755 Flag_Non_Static_Expr
1756 ("Bit_Order requires static expression!", Expr);
1759 if (Expr_Value (Expr) = 0) /= Bytes_Big_Endian then
1760 Set_Reverse_Bit_Order (U_Ent, True);
1766 --------------------
1767 -- Component_Size --
1768 --------------------
1770 -- Component_Size attribute definition clause
1772 when Attribute_Component_Size => Component_Size_Case : declare
1773 Csize : constant Uint := Static_Integer (Expr);
1777 New_Ctyp : Entity_Id;
1781 if not Is_Array_Type (U_Ent) then
1782 Error_Msg_N ("component size requires array type", Nam);
1786 Btype := Base_Type (U_Ent);
1787 Ctyp := Component_Type (Btype);
1789 if Duplicate_Clause then
1792 elsif Rep_Item_Too_Early (Btype, N) then
1795 elsif Csize /= No_Uint then
1796 Check_Size (Expr, Ctyp, Csize, Biased);
1798 -- For the biased case, build a declaration for a subtype that
1799 -- will be used to represent the biased subtype that reflects
1800 -- the biased representation of components. We need the subtype
1801 -- to get proper conversions on referencing elements of the
1802 -- array. Note: component size clauses are ignored in VM mode.
1804 if VM_Target = No_VM then
1807 Make_Defining_Identifier (Loc,
1809 New_External_Name (Chars (U_Ent), 'C', 0, 'T'));
1812 Make_Subtype_Declaration (Loc,
1813 Defining_Identifier => New_Ctyp,
1814 Subtype_Indication =>
1815 New_Occurrence_Of (Component_Type (Btype), Loc));
1817 Set_Parent (Decl, N);
1818 Analyze (Decl, Suppress => All_Checks);
1820 Set_Has_Delayed_Freeze (New_Ctyp, False);
1821 Set_Esize (New_Ctyp, Csize);
1822 Set_RM_Size (New_Ctyp, Csize);
1823 Init_Alignment (New_Ctyp);
1824 Set_Is_Itype (New_Ctyp, True);
1825 Set_Associated_Node_For_Itype (New_Ctyp, U_Ent);
1827 Set_Component_Type (Btype, New_Ctyp);
1828 Set_Biased (New_Ctyp, N, "component size clause");
1831 Set_Component_Size (Btype, Csize);
1833 -- For VM case, we ignore component size clauses
1836 -- Give a warning unless we are in GNAT mode, in which case
1837 -- the warning is suppressed since it is not useful.
1839 if not GNAT_Mode then
1841 ("?component size ignored in this configuration", N);
1845 -- Deal with warning on overridden size
1847 if Warn_On_Overridden_Size
1848 and then Has_Size_Clause (Ctyp)
1849 and then RM_Size (Ctyp) /= Csize
1852 ("?component size overrides size clause for&",
1856 Set_Has_Component_Size_Clause (Btype, True);
1857 Set_Has_Non_Standard_Rep (Btype, True);
1859 end Component_Size_Case;
1865 when Attribute_External_Tag => External_Tag :
1867 if not Is_Tagged_Type (U_Ent) then
1868 Error_Msg_N ("should be a tagged type", Nam);
1871 if Duplicate_Clause then
1875 Analyze_And_Resolve (Expr, Standard_String);
1877 if not Is_Static_Expression (Expr) then
1878 Flag_Non_Static_Expr
1879 ("static string required for tag name!", Nam);
1882 if VM_Target = No_VM then
1883 Set_Has_External_Tag_Rep_Clause (U_Ent);
1885 Error_Msg_Name_1 := Attr;
1887 ("% attribute unsupported in this configuration", Nam);
1890 if not Is_Library_Level_Entity (U_Ent) then
1892 ("?non-unique external tag supplied for &", N, U_Ent);
1894 ("?\same external tag applies to all subprogram calls", N);
1896 ("?\corresponding internal tag cannot be obtained", N);
1905 when Attribute_Input =>
1906 Analyze_Stream_TSS_Definition (TSS_Stream_Input);
1907 Set_Has_Specified_Stream_Input (Ent);
1913 -- Machine radix attribute definition clause
1915 when Attribute_Machine_Radix => Machine_Radix : declare
1916 Radix : constant Uint := Static_Integer (Expr);
1919 if not Is_Decimal_Fixed_Point_Type (U_Ent) then
1920 Error_Msg_N ("decimal fixed-point type expected for &", Nam);
1922 elsif Duplicate_Clause then
1925 elsif Radix /= No_Uint then
1926 Set_Has_Machine_Radix_Clause (U_Ent);
1927 Set_Has_Non_Standard_Rep (Base_Type (U_Ent));
1931 elsif Radix = 10 then
1932 Set_Machine_Radix_10 (U_Ent);
1934 Error_Msg_N ("machine radix value must be 2 or 10", Expr);
1943 -- Object_Size attribute definition clause
1945 when Attribute_Object_Size => Object_Size : declare
1946 Size : constant Uint := Static_Integer (Expr);
1949 pragma Warnings (Off, Biased);
1952 if not Is_Type (U_Ent) then
1953 Error_Msg_N ("Object_Size cannot be given for &", Nam);
1955 elsif Duplicate_Clause then
1959 Check_Size (Expr, U_Ent, Size, Biased);
1967 UI_Mod (Size, 64) /= 0
1970 ("Object_Size must be 8, 16, 32, or multiple of 64",
1974 Set_Esize (U_Ent, Size);
1975 Set_Has_Object_Size_Clause (U_Ent);
1976 Alignment_Check_For_Esize_Change (U_Ent);
1984 when Attribute_Output =>
1985 Analyze_Stream_TSS_Definition (TSS_Stream_Output);
1986 Set_Has_Specified_Stream_Output (Ent);
1992 when Attribute_Read =>
1993 Analyze_Stream_TSS_Definition (TSS_Stream_Read);
1994 Set_Has_Specified_Stream_Read (Ent);
2000 -- Size attribute definition clause
2002 when Attribute_Size => Size : declare
2003 Size : constant Uint := Static_Integer (Expr);
2010 if Duplicate_Clause then
2013 elsif not Is_Type (U_Ent)
2014 and then Ekind (U_Ent) /= E_Variable
2015 and then Ekind (U_Ent) /= E_Constant
2017 Error_Msg_N ("size cannot be given for &", Nam);
2019 elsif Is_Array_Type (U_Ent)
2020 and then not Is_Constrained (U_Ent)
2023 ("size cannot be given for unconstrained array", Nam);
2025 elsif Size /= No_Uint then
2027 if VM_Target /= No_VM and then not GNAT_Mode then
2029 -- Size clause is not handled properly on VM targets.
2030 -- Display a warning unless we are in GNAT mode, in which
2031 -- case this is useless.
2034 ("?size clauses are ignored in this configuration", N);
2037 if Is_Type (U_Ent) then
2040 Etyp := Etype (U_Ent);
2043 -- Check size, note that Gigi is in charge of checking that the
2044 -- size of an array or record type is OK. Also we do not check
2045 -- the size in the ordinary fixed-point case, since it is too
2046 -- early to do so (there may be subsequent small clause that
2047 -- affects the size). We can check the size if a small clause
2048 -- has already been given.
2050 if not Is_Ordinary_Fixed_Point_Type (U_Ent)
2051 or else Has_Small_Clause (U_Ent)
2053 Check_Size (Expr, Etyp, Size, Biased);
2054 Set_Biased (U_Ent, N, "size clause", Biased);
2057 -- For types set RM_Size and Esize if possible
2059 if Is_Type (U_Ent) then
2060 Set_RM_Size (U_Ent, Size);
2062 -- For scalar types, increase Object_Size to power of 2, but
2063 -- not less than a storage unit in any case (i.e., normally
2064 -- this means it will be byte addressable).
2066 if Is_Scalar_Type (U_Ent) then
2067 if Size <= System_Storage_Unit then
2068 Init_Esize (U_Ent, System_Storage_Unit);
2069 elsif Size <= 16 then
2070 Init_Esize (U_Ent, 16);
2071 elsif Size <= 32 then
2072 Init_Esize (U_Ent, 32);
2074 Set_Esize (U_Ent, (Size + 63) / 64 * 64);
2077 -- For all other types, object size = value size. The
2078 -- backend will adjust as needed.
2081 Set_Esize (U_Ent, Size);
2084 Alignment_Check_For_Esize_Change (U_Ent);
2086 -- For objects, set Esize only
2089 if Is_Elementary_Type (Etyp) then
2090 if Size /= System_Storage_Unit
2092 Size /= System_Storage_Unit * 2
2094 Size /= System_Storage_Unit * 4
2096 Size /= System_Storage_Unit * 8
2098 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
2099 Error_Msg_Uint_2 := Error_Msg_Uint_1 * 8;
2101 ("size for primitive object must be a power of 2"
2102 & " in the range ^-^", N);
2106 Set_Esize (U_Ent, Size);
2109 Set_Has_Size_Clause (U_Ent);
2117 -- Small attribute definition clause
2119 when Attribute_Small => Small : declare
2120 Implicit_Base : constant Entity_Id := Base_Type (U_Ent);
2124 Analyze_And_Resolve (Expr, Any_Real);
2126 if Etype (Expr) = Any_Type then
2129 elsif not Is_Static_Expression (Expr) then
2130 Flag_Non_Static_Expr
2131 ("small requires static expression!", Expr);
2135 Small := Expr_Value_R (Expr);
2137 if Small <= Ureal_0 then
2138 Error_Msg_N ("small value must be greater than zero", Expr);
2144 if not Is_Ordinary_Fixed_Point_Type (U_Ent) then
2146 ("small requires an ordinary fixed point type", Nam);
2148 elsif Has_Small_Clause (U_Ent) then
2149 Error_Msg_N ("small already given for &", Nam);
2151 elsif Small > Delta_Value (U_Ent) then
2153 ("small value must not be greater then delta value", Nam);
2156 Set_Small_Value (U_Ent, Small);
2157 Set_Small_Value (Implicit_Base, Small);
2158 Set_Has_Small_Clause (U_Ent);
2159 Set_Has_Small_Clause (Implicit_Base);
2160 Set_Has_Non_Standard_Rep (Implicit_Base);
2168 -- Storage_Pool attribute definition clause
2170 when Attribute_Storage_Pool => Storage_Pool : declare
2175 if Ekind (U_Ent) = E_Access_Subprogram_Type then
2177 ("storage pool cannot be given for access-to-subprogram type",
2182 Ekind_In (U_Ent, E_Access_Type, E_General_Access_Type)
2185 ("storage pool can only be given for access types", Nam);
2188 elsif Is_Derived_Type (U_Ent) then
2190 ("storage pool cannot be given for a derived access type",
2193 elsif Duplicate_Clause then
2196 elsif Present (Associated_Storage_Pool (U_Ent)) then
2197 Error_Msg_N ("storage pool already given for &", Nam);
2202 (Expr, Class_Wide_Type (RTE (RE_Root_Storage_Pool)));
2204 if not Denotes_Variable (Expr) then
2205 Error_Msg_N ("storage pool must be a variable", Expr);
2209 if Nkind (Expr) = N_Type_Conversion then
2210 T := Etype (Expression (Expr));
2215 -- The Stack_Bounded_Pool is used internally for implementing
2216 -- access types with a Storage_Size. Since it only work
2217 -- properly when used on one specific type, we need to check
2218 -- that it is not hijacked improperly:
2219 -- type T is access Integer;
2220 -- for T'Storage_Size use n;
2221 -- type Q is access Float;
2222 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
2224 if RTE_Available (RE_Stack_Bounded_Pool)
2225 and then Base_Type (T) = RTE (RE_Stack_Bounded_Pool)
2227 Error_Msg_N ("non-shareable internal Pool", Expr);
2231 -- If the argument is a name that is not an entity name, then
2232 -- we construct a renaming operation to define an entity of
2233 -- type storage pool.
2235 if not Is_Entity_Name (Expr)
2236 and then Is_Object_Reference (Expr)
2238 Pool := Make_Temporary (Loc, 'P', Expr);
2241 Rnode : constant Node_Id :=
2242 Make_Object_Renaming_Declaration (Loc,
2243 Defining_Identifier => Pool,
2245 New_Occurrence_Of (Etype (Expr), Loc),
2249 Insert_Before (N, Rnode);
2251 Set_Associated_Storage_Pool (U_Ent, Pool);
2254 elsif Is_Entity_Name (Expr) then
2255 Pool := Entity (Expr);
2257 -- If pool is a renamed object, get original one. This can
2258 -- happen with an explicit renaming, and within instances.
2260 while Present (Renamed_Object (Pool))
2261 and then Is_Entity_Name (Renamed_Object (Pool))
2263 Pool := Entity (Renamed_Object (Pool));
2266 if Present (Renamed_Object (Pool))
2267 and then Nkind (Renamed_Object (Pool)) = N_Type_Conversion
2268 and then Is_Entity_Name (Expression (Renamed_Object (Pool)))
2270 Pool := Entity (Expression (Renamed_Object (Pool)));
2273 Set_Associated_Storage_Pool (U_Ent, Pool);
2275 elsif Nkind (Expr) = N_Type_Conversion
2276 and then Is_Entity_Name (Expression (Expr))
2277 and then Nkind (Original_Node (Expr)) = N_Attribute_Reference
2279 Pool := Entity (Expression (Expr));
2280 Set_Associated_Storage_Pool (U_Ent, Pool);
2283 Error_Msg_N ("incorrect reference to a Storage Pool", Expr);
2292 -- Storage_Size attribute definition clause
2294 when Attribute_Storage_Size => Storage_Size : declare
2295 Btype : constant Entity_Id := Base_Type (U_Ent);
2299 if Is_Task_Type (U_Ent) then
2300 Check_Restriction (No_Obsolescent_Features, N);
2302 if Warn_On_Obsolescent_Feature then
2304 ("storage size clause for task is an " &
2305 "obsolescent feature (RM J.9)?", N);
2306 Error_Msg_N ("\use Storage_Size pragma instead?", N);
2312 if not Is_Access_Type (U_Ent)
2313 and then Ekind (U_Ent) /= E_Task_Type
2315 Error_Msg_N ("storage size cannot be given for &", Nam);
2317 elsif Is_Access_Type (U_Ent) and Is_Derived_Type (U_Ent) then
2319 ("storage size cannot be given for a derived access type",
2322 elsif Duplicate_Clause then
2326 Analyze_And_Resolve (Expr, Any_Integer);
2328 if Is_Access_Type (U_Ent) then
2329 if Present (Associated_Storage_Pool (U_Ent)) then
2330 Error_Msg_N ("storage pool already given for &", Nam);
2334 if Is_OK_Static_Expression (Expr)
2335 and then Expr_Value (Expr) = 0
2337 Set_No_Pool_Assigned (Btype);
2340 else -- Is_Task_Type (U_Ent)
2341 Sprag := Get_Rep_Pragma (Btype, Name_Storage_Size);
2343 if Present (Sprag) then
2344 Error_Msg_Sloc := Sloc (Sprag);
2346 ("Storage_Size already specified#", Nam);
2351 Set_Has_Storage_Size_Clause (Btype);
2359 when Attribute_Stream_Size => Stream_Size : declare
2360 Size : constant Uint := Static_Integer (Expr);
2363 if Ada_Version <= Ada_95 then
2364 Check_Restriction (No_Implementation_Attributes, N);
2367 if Duplicate_Clause then
2370 elsif Is_Elementary_Type (U_Ent) then
2371 if Size /= System_Storage_Unit
2373 Size /= System_Storage_Unit * 2
2375 Size /= System_Storage_Unit * 4
2377 Size /= System_Storage_Unit * 8
2379 Error_Msg_Uint_1 := UI_From_Int (System_Storage_Unit);
2381 ("stream size for elementary type must be a"
2382 & " power of 2 and at least ^", N);
2384 elsif RM_Size (U_Ent) > Size then
2385 Error_Msg_Uint_1 := RM_Size (U_Ent);
2387 ("stream size for elementary type must be a"
2388 & " power of 2 and at least ^", N);
2391 Set_Has_Stream_Size_Clause (U_Ent);
2394 Error_Msg_N ("Stream_Size cannot be given for &", Nam);
2402 -- Value_Size attribute definition clause
2404 when Attribute_Value_Size => Value_Size : declare
2405 Size : constant Uint := Static_Integer (Expr);
2409 if not Is_Type (U_Ent) then
2410 Error_Msg_N ("Value_Size cannot be given for &", Nam);
2412 elsif Duplicate_Clause then
2415 elsif Is_Array_Type (U_Ent)
2416 and then not Is_Constrained (U_Ent)
2419 ("Value_Size cannot be given for unconstrained array", Nam);
2422 if Is_Elementary_Type (U_Ent) then
2423 Check_Size (Expr, U_Ent, Size, Biased);
2424 Set_Biased (U_Ent, N, "value size clause", Biased);
2427 Set_RM_Size (U_Ent, Size);
2435 when Attribute_Write =>
2436 Analyze_Stream_TSS_Definition (TSS_Stream_Write);
2437 Set_Has_Specified_Stream_Write (Ent);
2439 -- All other attributes cannot be set
2443 ("attribute& cannot be set with definition clause", N);
2446 -- The test for the type being frozen must be performed after
2447 -- any expression the clause has been analyzed since the expression
2448 -- itself might cause freezing that makes the clause illegal.
2450 if Rep_Item_Too_Late (U_Ent, N, FOnly) then
2453 end Analyze_Attribute_Definition_Clause;
2455 ----------------------------
2456 -- Analyze_Code_Statement --
2457 ----------------------------
2459 procedure Analyze_Code_Statement (N : Node_Id) is
2460 HSS : constant Node_Id := Parent (N);
2461 SBody : constant Node_Id := Parent (HSS);
2462 Subp : constant Entity_Id := Current_Scope;
2469 -- Analyze and check we get right type, note that this implements the
2470 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
2471 -- is the only way that Asm_Insn could possibly be visible.
2473 Analyze_And_Resolve (Expression (N));
2475 if Etype (Expression (N)) = Any_Type then
2477 elsif Etype (Expression (N)) /= RTE (RE_Asm_Insn) then
2478 Error_Msg_N ("incorrect type for code statement", N);
2482 Check_Code_Statement (N);
2484 -- Make sure we appear in the handled statement sequence of a
2485 -- subprogram (RM 13.8(3)).
2487 if Nkind (HSS) /= N_Handled_Sequence_Of_Statements
2488 or else Nkind (SBody) /= N_Subprogram_Body
2491 ("code statement can only appear in body of subprogram", N);
2495 -- Do remaining checks (RM 13.8(3)) if not already done
2497 if not Is_Machine_Code_Subprogram (Subp) then
2498 Set_Is_Machine_Code_Subprogram (Subp);
2500 -- No exception handlers allowed
2502 if Present (Exception_Handlers (HSS)) then
2504 ("exception handlers not permitted in machine code subprogram",
2505 First (Exception_Handlers (HSS)));
2508 -- No declarations other than use clauses and pragmas (we allow
2509 -- certain internally generated declarations as well).
2511 Decl := First (Declarations (SBody));
2512 while Present (Decl) loop
2513 DeclO := Original_Node (Decl);
2514 if Comes_From_Source (DeclO)
2515 and not Nkind_In (DeclO, N_Pragma,
2516 N_Use_Package_Clause,
2518 N_Implicit_Label_Declaration)
2521 ("this declaration not allowed in machine code subprogram",
2528 -- No statements other than code statements, pragmas, and labels.
2529 -- Again we allow certain internally generated statements.
2531 Stmt := First (Statements (HSS));
2532 while Present (Stmt) loop
2533 StmtO := Original_Node (Stmt);
2534 if Comes_From_Source (StmtO)
2535 and then not Nkind_In (StmtO, N_Pragma,
2540 ("this statement is not allowed in machine code subprogram",
2547 end Analyze_Code_Statement;
2549 -----------------------------------------------
2550 -- Analyze_Enumeration_Representation_Clause --
2551 -----------------------------------------------
2553 procedure Analyze_Enumeration_Representation_Clause (N : Node_Id) is
2554 Ident : constant Node_Id := Identifier (N);
2555 Aggr : constant Node_Id := Array_Aggregate (N);
2556 Enumtype : Entity_Id;
2562 Err : Boolean := False;
2564 Lo : constant Uint := Expr_Value (Type_Low_Bound (Universal_Integer));
2565 Hi : constant Uint := Expr_Value (Type_High_Bound (Universal_Integer));
2566 -- Allowed range of universal integer (= allowed range of enum lit vals)
2570 -- Minimum and maximum values of entries
2573 -- Pointer to node for literal providing max value
2576 if Ignore_Rep_Clauses then
2580 -- First some basic error checks
2583 Enumtype := Entity (Ident);
2585 if Enumtype = Any_Type
2586 or else Rep_Item_Too_Early (Enumtype, N)
2590 Enumtype := Underlying_Type (Enumtype);
2593 if not Is_Enumeration_Type (Enumtype) then
2595 ("enumeration type required, found}",
2596 Ident, First_Subtype (Enumtype));
2600 -- Ignore rep clause on generic actual type. This will already have
2601 -- been flagged on the template as an error, and this is the safest
2602 -- way to ensure we don't get a junk cascaded message in the instance.
2604 if Is_Generic_Actual_Type (Enumtype) then
2607 -- Type must be in current scope
2609 elsif Scope (Enumtype) /= Current_Scope then
2610 Error_Msg_N ("type must be declared in this scope", Ident);
2613 -- Type must be a first subtype
2615 elsif not Is_First_Subtype (Enumtype) then
2616 Error_Msg_N ("cannot give enumeration rep clause for subtype", N);
2619 -- Ignore duplicate rep clause
2621 elsif Has_Enumeration_Rep_Clause (Enumtype) then
2622 Error_Msg_N ("duplicate enumeration rep clause ignored", N);
2625 -- Don't allow rep clause for standard [wide_[wide_]]character
2627 elsif Is_Standard_Character_Type (Enumtype) then
2628 Error_Msg_N ("enumeration rep clause not allowed for this type", N);
2631 -- Check that the expression is a proper aggregate (no parentheses)
2633 elsif Paren_Count (Aggr) /= 0 then
2635 ("extra parentheses surrounding aggregate not allowed",
2639 -- All tests passed, so set rep clause in place
2642 Set_Has_Enumeration_Rep_Clause (Enumtype);
2643 Set_Has_Enumeration_Rep_Clause (Base_Type (Enumtype));
2646 -- Now we process the aggregate. Note that we don't use the normal
2647 -- aggregate code for this purpose, because we don't want any of the
2648 -- normal expansion activities, and a number of special semantic
2649 -- rules apply (including the component type being any integer type)
2651 Elit := First_Literal (Enumtype);
2653 -- First the positional entries if any
2655 if Present (Expressions (Aggr)) then
2656 Expr := First (Expressions (Aggr));
2657 while Present (Expr) loop
2659 Error_Msg_N ("too many entries in aggregate", Expr);
2663 Val := Static_Integer (Expr);
2665 -- Err signals that we found some incorrect entries processing
2666 -- the list. The final checks for completeness and ordering are
2667 -- skipped in this case.
2669 if Val = No_Uint then
2671 elsif Val < Lo or else Hi < Val then
2672 Error_Msg_N ("value outside permitted range", Expr);
2676 Set_Enumeration_Rep (Elit, Val);
2677 Set_Enumeration_Rep_Expr (Elit, Expr);
2683 -- Now process the named entries if present
2685 if Present (Component_Associations (Aggr)) then
2686 Assoc := First (Component_Associations (Aggr));
2687 while Present (Assoc) loop
2688 Choice := First (Choices (Assoc));
2690 if Present (Next (Choice)) then
2692 ("multiple choice not allowed here", Next (Choice));
2696 if Nkind (Choice) = N_Others_Choice then
2697 Error_Msg_N ("others choice not allowed here", Choice);
2700 elsif Nkind (Choice) = N_Range then
2701 -- ??? should allow zero/one element range here
2702 Error_Msg_N ("range not allowed here", Choice);
2706 Analyze_And_Resolve (Choice, Enumtype);
2708 if Is_Entity_Name (Choice)
2709 and then Is_Type (Entity (Choice))
2711 Error_Msg_N ("subtype name not allowed here", Choice);
2713 -- ??? should allow static subtype with zero/one entry
2715 elsif Etype (Choice) = Base_Type (Enumtype) then
2716 if not Is_Static_Expression (Choice) then
2717 Flag_Non_Static_Expr
2718 ("non-static expression used for choice!", Choice);
2722 Elit := Expr_Value_E (Choice);
2724 if Present (Enumeration_Rep_Expr (Elit)) then
2725 Error_Msg_Sloc := Sloc (Enumeration_Rep_Expr (Elit));
2727 ("representation for& previously given#",
2732 Set_Enumeration_Rep_Expr (Elit, Expression (Assoc));
2734 Expr := Expression (Assoc);
2735 Val := Static_Integer (Expr);
2737 if Val = No_Uint then
2740 elsif Val < Lo or else Hi < Val then
2741 Error_Msg_N ("value outside permitted range", Expr);
2745 Set_Enumeration_Rep (Elit, Val);
2754 -- Aggregate is fully processed. Now we check that a full set of
2755 -- representations was given, and that they are in range and in order.
2756 -- These checks are only done if no other errors occurred.
2762 Elit := First_Literal (Enumtype);
2763 while Present (Elit) loop
2764 if No (Enumeration_Rep_Expr (Elit)) then
2765 Error_Msg_NE ("missing representation for&!", N, Elit);
2768 Val := Enumeration_Rep (Elit);
2770 if Min = No_Uint then
2774 if Val /= No_Uint then
2775 if Max /= No_Uint and then Val <= Max then
2777 ("enumeration value for& not ordered!",
2778 Enumeration_Rep_Expr (Elit), Elit);
2781 Max_Node := Enumeration_Rep_Expr (Elit);
2785 -- If there is at least one literal whose representation is not
2786 -- equal to the Pos value, then note that this enumeration type
2787 -- has a non-standard representation.
2789 if Val /= Enumeration_Pos (Elit) then
2790 Set_Has_Non_Standard_Rep (Base_Type (Enumtype));
2797 -- Now set proper size information
2800 Minsize : Uint := UI_From_Int (Minimum_Size (Enumtype));
2803 if Has_Size_Clause (Enumtype) then
2805 -- All OK, if size is OK now
2807 if RM_Size (Enumtype) >= Minsize then
2811 -- Try if we can get by with biasing
2814 UI_From_Int (Minimum_Size (Enumtype, Biased => True));
2816 -- Error message if even biasing does not work
2818 if RM_Size (Enumtype) < Minsize then
2819 Error_Msg_Uint_1 := RM_Size (Enumtype);
2820 Error_Msg_Uint_2 := Max;
2822 ("previously given size (^) is too small "
2823 & "for this value (^)", Max_Node);
2825 -- If biasing worked, indicate that we now have biased rep
2829 (Enumtype, Size_Clause (Enumtype), "size clause");
2834 Set_RM_Size (Enumtype, Minsize);
2835 Set_Enum_Esize (Enumtype);
2838 Set_RM_Size (Base_Type (Enumtype), RM_Size (Enumtype));
2839 Set_Esize (Base_Type (Enumtype), Esize (Enumtype));
2840 Set_Alignment (Base_Type (Enumtype), Alignment (Enumtype));
2844 -- We repeat the too late test in case it froze itself!
2846 if Rep_Item_Too_Late (Enumtype, N) then
2849 end Analyze_Enumeration_Representation_Clause;
2851 ----------------------------
2852 -- Analyze_Free_Statement --
2853 ----------------------------
2855 procedure Analyze_Free_Statement (N : Node_Id) is
2857 Analyze (Expression (N));
2858 end Analyze_Free_Statement;
2860 ---------------------------
2861 -- Analyze_Freeze_Entity --
2862 ---------------------------
2864 procedure Analyze_Freeze_Entity (N : Node_Id) is
2865 E : constant Entity_Id := Entity (N);
2868 -- Remember that we are processing a freezing entity. Required to
2869 -- ensure correct decoration of internal entities associated with
2870 -- interfaces (see New_Overloaded_Entity).
2872 Inside_Freezing_Actions := Inside_Freezing_Actions + 1;
2874 -- For tagged types covering interfaces add internal entities that link
2875 -- the primitives of the interfaces with the primitives that cover them.
2876 -- Note: These entities were originally generated only when generating
2877 -- code because their main purpose was to provide support to initialize
2878 -- the secondary dispatch tables. They are now generated also when
2879 -- compiling with no code generation to provide ASIS the relationship
2880 -- between interface primitives and tagged type primitives. They are
2881 -- also used to locate primitives covering interfaces when processing
2882 -- generics (see Derive_Subprograms).
2884 if Ada_Version >= Ada_2005
2885 and then Ekind (E) = E_Record_Type
2886 and then Is_Tagged_Type (E)
2887 and then not Is_Interface (E)
2888 and then Has_Interfaces (E)
2890 -- This would be a good common place to call the routine that checks
2891 -- overriding of interface primitives (and thus factorize calls to
2892 -- Check_Abstract_Overriding located at different contexts in the
2893 -- compiler). However, this is not possible because it causes
2894 -- spurious errors in case of late overriding.
2896 Add_Internal_Interface_Entities (E);
2901 if Ekind (E) = E_Record_Type
2902 and then Is_CPP_Class (E)
2903 and then Is_Tagged_Type (E)
2904 and then Tagged_Type_Expansion
2905 and then Expander_Active
2907 if CPP_Num_Prims (E) = 0 then
2909 -- If the CPP type has user defined components then it must import
2910 -- primitives from C++. This is required because if the C++ class
2911 -- has no primitives then the C++ compiler does not added the _tag
2912 -- component to the type.
2914 pragma Assert (Chars (First_Entity (E)) = Name_uTag);
2916 if First_Entity (E) /= Last_Entity (E) then
2918 ("?'C'P'P type must import at least one primitive from C++",
2923 -- Check that all its primitives are abstract or imported from C++.
2924 -- Check also availability of the C++ constructor.
2927 Has_Constructors : constant Boolean := Has_CPP_Constructors (E);
2929 Error_Reported : Boolean := False;
2933 Elmt := First_Elmt (Primitive_Operations (E));
2934 while Present (Elmt) loop
2935 Prim := Node (Elmt);
2937 if Comes_From_Source (Prim) then
2938 if Is_Abstract_Subprogram (Prim) then
2941 elsif not Is_Imported (Prim)
2942 or else Convention (Prim) /= Convention_CPP
2945 ("?primitives of 'C'P'P types must be imported from C++"
2946 & " or abstract", Prim);
2948 elsif not Has_Constructors
2949 and then not Error_Reported
2951 Error_Msg_Name_1 := Chars (E);
2953 ("?'C'P'P constructor required for type %", Prim);
2954 Error_Reported := True;
2963 Inside_Freezing_Actions := Inside_Freezing_Actions - 1;
2964 end Analyze_Freeze_Entity;
2966 ------------------------------------------
2967 -- Analyze_Record_Representation_Clause --
2968 ------------------------------------------
2970 -- Note: we check as much as we can here, but we can't do any checks
2971 -- based on the position values (e.g. overlap checks) until freeze time
2972 -- because especially in Ada 2005 (machine scalar mode), the processing
2973 -- for non-standard bit order can substantially change the positions.
2974 -- See procedure Check_Record_Representation_Clause (called from Freeze)
2975 -- for the remainder of this processing.
2977 procedure Analyze_Record_Representation_Clause (N : Node_Id) is
2978 Ident : constant Node_Id := Identifier (N);
2983 Hbit : Uint := Uint_0;
2987 Rectype : Entity_Id;
2989 CR_Pragma : Node_Id := Empty;
2990 -- Points to N_Pragma node if Complete_Representation pragma present
2993 if Ignore_Rep_Clauses then
2998 Rectype := Entity (Ident);
3000 if Rectype = Any_Type
3001 or else Rep_Item_Too_Early (Rectype, N)
3005 Rectype := Underlying_Type (Rectype);
3008 -- First some basic error checks
3010 if not Is_Record_Type (Rectype) then
3012 ("record type required, found}", Ident, First_Subtype (Rectype));
3015 elsif Scope (Rectype) /= Current_Scope then
3016 Error_Msg_N ("type must be declared in this scope", N);
3019 elsif not Is_First_Subtype (Rectype) then
3020 Error_Msg_N ("cannot give record rep clause for subtype", N);
3023 elsif Has_Record_Rep_Clause (Rectype) then
3024 Error_Msg_N ("duplicate record rep clause ignored", N);
3027 elsif Rep_Item_Too_Late (Rectype, N) then
3031 if Present (Mod_Clause (N)) then
3033 Loc : constant Source_Ptr := Sloc (N);
3034 M : constant Node_Id := Mod_Clause (N);
3035 P : constant List_Id := Pragmas_Before (M);
3039 pragma Warnings (Off, Mod_Val);
3042 Check_Restriction (No_Obsolescent_Features, Mod_Clause (N));
3044 if Warn_On_Obsolescent_Feature then
3046 ("mod clause is an obsolescent feature (RM J.8)?", N);
3048 ("\use alignment attribute definition clause instead?", N);
3055 -- In ASIS_Mode mode, expansion is disabled, but we must convert
3056 -- the Mod clause into an alignment clause anyway, so that the
3057 -- back-end can compute and back-annotate properly the size and
3058 -- alignment of types that may include this record.
3060 -- This seems dubious, this destroys the source tree in a manner
3061 -- not detectable by ASIS ???
3063 if Operating_Mode = Check_Semantics
3067 Make_Attribute_Definition_Clause (Loc,
3068 Name => New_Reference_To (Base_Type (Rectype), Loc),
3069 Chars => Name_Alignment,
3070 Expression => Relocate_Node (Expression (M)));
3072 Set_From_At_Mod (AtM_Nod);
3073 Insert_After (N, AtM_Nod);
3074 Mod_Val := Get_Alignment_Value (Expression (AtM_Nod));
3075 Set_Mod_Clause (N, Empty);
3078 -- Get the alignment value to perform error checking
3080 Mod_Val := Get_Alignment_Value (Expression (M));
3085 -- For untagged types, clear any existing component clauses for the
3086 -- type. If the type is derived, this is what allows us to override
3087 -- a rep clause for the parent. For type extensions, the representation
3088 -- of the inherited components is inherited, so we want to keep previous
3089 -- component clauses for completeness.
3091 if not Is_Tagged_Type (Rectype) then
3092 Comp := First_Component_Or_Discriminant (Rectype);
3093 while Present (Comp) loop
3094 Set_Component_Clause (Comp, Empty);
3095 Next_Component_Or_Discriminant (Comp);
3099 -- All done if no component clauses
3101 CC := First (Component_Clauses (N));
3107 -- A representation like this applies to the base type
3109 Set_Has_Record_Rep_Clause (Base_Type (Rectype));
3110 Set_Has_Non_Standard_Rep (Base_Type (Rectype));
3111 Set_Has_Specified_Layout (Base_Type (Rectype));
3113 -- Process the component clauses
3115 while Present (CC) loop
3119 if Nkind (CC) = N_Pragma then
3122 -- The only pragma of interest is Complete_Representation
3124 if Pragma_Name (CC) = Name_Complete_Representation then
3128 -- Processing for real component clause
3131 Posit := Static_Integer (Position (CC));
3132 Fbit := Static_Integer (First_Bit (CC));
3133 Lbit := Static_Integer (Last_Bit (CC));
3136 and then Fbit /= No_Uint
3137 and then Lbit /= No_Uint
3141 ("position cannot be negative", Position (CC));
3145 ("first bit cannot be negative", First_Bit (CC));
3147 -- The Last_Bit specified in a component clause must not be
3148 -- less than the First_Bit minus one (RM-13.5.1(10)).
3150 elsif Lbit < Fbit - 1 then
3152 ("last bit cannot be less than first bit minus one",
3155 -- Values look OK, so find the corresponding record component
3156 -- Even though the syntax allows an attribute reference for
3157 -- implementation-defined components, GNAT does not allow the
3158 -- tag to get an explicit position.
3160 elsif Nkind (Component_Name (CC)) = N_Attribute_Reference then
3161 if Attribute_Name (Component_Name (CC)) = Name_Tag then
3162 Error_Msg_N ("position of tag cannot be specified", CC);
3164 Error_Msg_N ("illegal component name", CC);
3168 Comp := First_Entity (Rectype);
3169 while Present (Comp) loop
3170 exit when Chars (Comp) = Chars (Component_Name (CC));
3176 -- Maybe component of base type that is absent from
3177 -- statically constrained first subtype.
3179 Comp := First_Entity (Base_Type (Rectype));
3180 while Present (Comp) loop
3181 exit when Chars (Comp) = Chars (Component_Name (CC));
3188 ("component clause is for non-existent field", CC);
3190 -- Ada 2012 (AI05-0026): Any name that denotes a
3191 -- discriminant of an object of an unchecked union type
3192 -- shall not occur within a record_representation_clause.
3194 -- The general restriction of using record rep clauses on
3195 -- Unchecked_Union types has now been lifted. Since it is
3196 -- possible to introduce a record rep clause which mentions
3197 -- the discriminant of an Unchecked_Union in non-Ada 2012
3198 -- code, this check is applied to all versions of the
3201 elsif Ekind (Comp) = E_Discriminant
3202 and then Is_Unchecked_Union (Rectype)
3205 ("cannot reference discriminant of Unchecked_Union",
3206 Component_Name (CC));
3208 elsif Present (Component_Clause (Comp)) then
3210 -- Diagnose duplicate rep clause, or check consistency
3211 -- if this is an inherited component. In a double fault,
3212 -- there may be a duplicate inconsistent clause for an
3213 -- inherited component.
3215 if Scope (Original_Record_Component (Comp)) = Rectype
3216 or else Parent (Component_Clause (Comp)) = N
3218 Error_Msg_Sloc := Sloc (Component_Clause (Comp));
3219 Error_Msg_N ("component clause previously given#", CC);
3223 Rep1 : constant Node_Id := Component_Clause (Comp);
3225 if Intval (Position (Rep1)) /=
3226 Intval (Position (CC))
3227 or else Intval (First_Bit (Rep1)) /=
3228 Intval (First_Bit (CC))
3229 or else Intval (Last_Bit (Rep1)) /=
3230 Intval (Last_Bit (CC))
3232 Error_Msg_N ("component clause inconsistent "
3233 & "with representation of ancestor", CC);
3234 elsif Warn_On_Redundant_Constructs then
3235 Error_Msg_N ("?redundant component clause "
3236 & "for inherited component!", CC);
3241 -- Normal case where this is the first component clause we
3242 -- have seen for this entity, so set it up properly.
3245 -- Make reference for field in record rep clause and set
3246 -- appropriate entity field in the field identifier.
3249 (Comp, Component_Name (CC), Set_Ref => False);
3250 Set_Entity (Component_Name (CC), Comp);
3252 -- Update Fbit and Lbit to the actual bit number
3254 Fbit := Fbit + UI_From_Int (SSU) * Posit;
3255 Lbit := Lbit + UI_From_Int (SSU) * Posit;
3257 if Has_Size_Clause (Rectype)
3258 and then Esize (Rectype) <= Lbit
3261 ("bit number out of range of specified size",
3264 Set_Component_Clause (Comp, CC);
3265 Set_Component_Bit_Offset (Comp, Fbit);
3266 Set_Esize (Comp, 1 + (Lbit - Fbit));
3267 Set_Normalized_First_Bit (Comp, Fbit mod SSU);
3268 Set_Normalized_Position (Comp, Fbit / SSU);
3270 if Warn_On_Overridden_Size
3271 and then Has_Size_Clause (Etype (Comp))
3272 and then RM_Size (Etype (Comp)) /= Esize (Comp)
3275 ("?component size overrides size clause for&",
3276 Component_Name (CC), Etype (Comp));
3279 -- This information is also set in the corresponding
3280 -- component of the base type, found by accessing the
3281 -- Original_Record_Component link if it is present.
3283 Ocomp := Original_Record_Component (Comp);
3290 (Component_Name (CC),
3296 (Comp, First_Node (CC), "component clause", Biased);
3298 if Present (Ocomp) then
3299 Set_Component_Clause (Ocomp, CC);
3300 Set_Component_Bit_Offset (Ocomp, Fbit);
3301 Set_Normalized_First_Bit (Ocomp, Fbit mod SSU);
3302 Set_Normalized_Position (Ocomp, Fbit / SSU);
3303 Set_Esize (Ocomp, 1 + (Lbit - Fbit));
3305 Set_Normalized_Position_Max
3306 (Ocomp, Normalized_Position (Ocomp));
3308 -- Note: we don't use Set_Biased here, because we
3309 -- already gave a warning above if needed, and we
3310 -- would get a duplicate for the same name here.
3312 Set_Has_Biased_Representation
3313 (Ocomp, Has_Biased_Representation (Comp));
3316 if Esize (Comp) < 0 then
3317 Error_Msg_N ("component size is negative", CC);
3328 -- Check missing components if Complete_Representation pragma appeared
3330 if Present (CR_Pragma) then
3331 Comp := First_Component_Or_Discriminant (Rectype);
3332 while Present (Comp) loop
3333 if No (Component_Clause (Comp)) then
3335 ("missing component clause for &", CR_Pragma, Comp);
3338 Next_Component_Or_Discriminant (Comp);
3341 -- If no Complete_Representation pragma, warn if missing components
3343 elsif Warn_On_Unrepped_Components then
3345 Num_Repped_Components : Nat := 0;
3346 Num_Unrepped_Components : Nat := 0;
3349 -- First count number of repped and unrepped components
3351 Comp := First_Component_Or_Discriminant (Rectype);
3352 while Present (Comp) loop
3353 if Present (Component_Clause (Comp)) then
3354 Num_Repped_Components := Num_Repped_Components + 1;
3356 Num_Unrepped_Components := Num_Unrepped_Components + 1;
3359 Next_Component_Or_Discriminant (Comp);
3362 -- We are only interested in the case where there is at least one
3363 -- unrepped component, and at least half the components have rep
3364 -- clauses. We figure that if less than half have them, then the
3365 -- partial rep clause is really intentional. If the component
3366 -- type has no underlying type set at this point (as for a generic
3367 -- formal type), we don't know enough to give a warning on the
3370 if Num_Unrepped_Components > 0
3371 and then Num_Unrepped_Components < Num_Repped_Components
3373 Comp := First_Component_Or_Discriminant (Rectype);
3374 while Present (Comp) loop
3375 if No (Component_Clause (Comp))
3376 and then Comes_From_Source (Comp)
3377 and then Present (Underlying_Type (Etype (Comp)))
3378 and then (Is_Scalar_Type (Underlying_Type (Etype (Comp)))
3379 or else Size_Known_At_Compile_Time
3380 (Underlying_Type (Etype (Comp))))
3381 and then not Has_Warnings_Off (Rectype)
3383 Error_Msg_Sloc := Sloc (Comp);
3385 ("?no component clause given for & declared #",
3389 Next_Component_Or_Discriminant (Comp);
3394 end Analyze_Record_Representation_Clause;
3396 -----------------------------------
3397 -- Check_Constant_Address_Clause --
3398 -----------------------------------
3400 procedure Check_Constant_Address_Clause
3404 procedure Check_At_Constant_Address (Nod : Node_Id);
3405 -- Checks that the given node N represents a name whose 'Address is
3406 -- constant (in the same sense as OK_Constant_Address_Clause, i.e. the
3407 -- address value is the same at the point of declaration of U_Ent and at
3408 -- the time of elaboration of the address clause.
3410 procedure Check_Expr_Constants (Nod : Node_Id);
3411 -- Checks that Nod meets the requirements for a constant address clause
3412 -- in the sense of the enclosing procedure.
3414 procedure Check_List_Constants (Lst : List_Id);
3415 -- Check that all elements of list Lst meet the requirements for a
3416 -- constant address clause in the sense of the enclosing procedure.
3418 -------------------------------
3419 -- Check_At_Constant_Address --
3420 -------------------------------
3422 procedure Check_At_Constant_Address (Nod : Node_Id) is
3424 if Is_Entity_Name (Nod) then
3425 if Present (Address_Clause (Entity ((Nod)))) then
3427 ("invalid address clause for initialized object &!",
3430 ("address for& cannot" &
3431 " depend on another address clause! (RM 13.1(22))!",
3434 elsif In_Same_Source_Unit (Entity (Nod), U_Ent)
3435 and then Sloc (U_Ent) < Sloc (Entity (Nod))
3438 ("invalid address clause for initialized object &!",
3440 Error_Msg_Node_2 := U_Ent;
3442 ("\& must be defined before & (RM 13.1(22))!",
3446 elsif Nkind (Nod) = N_Selected_Component then
3448 T : constant Entity_Id := Etype (Prefix (Nod));
3451 if (Is_Record_Type (T)
3452 and then Has_Discriminants (T))
3455 and then Is_Record_Type (Designated_Type (T))
3456 and then Has_Discriminants (Designated_Type (T)))
3459 ("invalid address clause for initialized object &!",
3462 ("\address cannot depend on component" &
3463 " of discriminated record (RM 13.1(22))!",
3466 Check_At_Constant_Address (Prefix (Nod));
3470 elsif Nkind (Nod) = N_Indexed_Component then
3471 Check_At_Constant_Address (Prefix (Nod));
3472 Check_List_Constants (Expressions (Nod));
3475 Check_Expr_Constants (Nod);
3477 end Check_At_Constant_Address;
3479 --------------------------
3480 -- Check_Expr_Constants --
3481 --------------------------
3483 procedure Check_Expr_Constants (Nod : Node_Id) is
3484 Loc_U_Ent : constant Source_Ptr := Sloc (U_Ent);
3485 Ent : Entity_Id := Empty;
3488 if Nkind (Nod) in N_Has_Etype
3489 and then Etype (Nod) = Any_Type
3495 when N_Empty | N_Error =>
3498 when N_Identifier | N_Expanded_Name =>
3499 Ent := Entity (Nod);
3501 -- We need to look at the original node if it is different
3502 -- from the node, since we may have rewritten things and
3503 -- substituted an identifier representing the rewrite.
3505 if Original_Node (Nod) /= Nod then
3506 Check_Expr_Constants (Original_Node (Nod));
3508 -- If the node is an object declaration without initial
3509 -- value, some code has been expanded, and the expression
3510 -- is not constant, even if the constituents might be
3511 -- acceptable, as in A'Address + offset.
3513 if Ekind (Ent) = E_Variable
3515 Nkind (Declaration_Node (Ent)) = N_Object_Declaration
3517 No (Expression (Declaration_Node (Ent)))
3520 ("invalid address clause for initialized object &!",
3523 -- If entity is constant, it may be the result of expanding
3524 -- a check. We must verify that its declaration appears
3525 -- before the object in question, else we also reject the
3528 elsif Ekind (Ent) = E_Constant
3529 and then In_Same_Source_Unit (Ent, U_Ent)
3530 and then Sloc (Ent) > Loc_U_Ent
3533 ("invalid address clause for initialized object &!",
3540 -- Otherwise look at the identifier and see if it is OK
3542 if Ekind_In (Ent, E_Named_Integer, E_Named_Real)
3543 or else Is_Type (Ent)
3548 Ekind (Ent) = E_Constant
3550 Ekind (Ent) = E_In_Parameter
3552 -- This is the case where we must have Ent defined before
3553 -- U_Ent. Clearly if they are in different units this
3554 -- requirement is met since the unit containing Ent is
3555 -- already processed.
3557 if not In_Same_Source_Unit (Ent, U_Ent) then
3560 -- Otherwise location of Ent must be before the location
3561 -- of U_Ent, that's what prior defined means.
3563 elsif Sloc (Ent) < Loc_U_Ent then
3568 ("invalid address clause for initialized object &!",
3570 Error_Msg_Node_2 := U_Ent;
3572 ("\& must be defined before & (RM 13.1(22))!",
3576 elsif Nkind (Original_Node (Nod)) = N_Function_Call then
3577 Check_Expr_Constants (Original_Node (Nod));
3581 ("invalid address clause for initialized object &!",
3584 if Comes_From_Source (Ent) then
3586 ("\reference to variable& not allowed"
3587 & " (RM 13.1(22))!", Nod, Ent);
3590 ("non-static expression not allowed"
3591 & " (RM 13.1(22))!", Nod);
3595 when N_Integer_Literal =>
3597 -- If this is a rewritten unchecked conversion, in a system
3598 -- where Address is an integer type, always use the base type
3599 -- for a literal value. This is user-friendly and prevents
3600 -- order-of-elaboration issues with instances of unchecked
3603 if Nkind (Original_Node (Nod)) = N_Function_Call then
3604 Set_Etype (Nod, Base_Type (Etype (Nod)));
3607 when N_Real_Literal |
3609 N_Character_Literal =>
3613 Check_Expr_Constants (Low_Bound (Nod));
3614 Check_Expr_Constants (High_Bound (Nod));
3616 when N_Explicit_Dereference =>
3617 Check_Expr_Constants (Prefix (Nod));
3619 when N_Indexed_Component =>
3620 Check_Expr_Constants (Prefix (Nod));
3621 Check_List_Constants (Expressions (Nod));
3624 Check_Expr_Constants (Prefix (Nod));
3625 Check_Expr_Constants (Discrete_Range (Nod));
3627 when N_Selected_Component =>
3628 Check_Expr_Constants (Prefix (Nod));
3630 when N_Attribute_Reference =>
3631 if Attribute_Name (Nod) = Name_Address
3633 Attribute_Name (Nod) = Name_Access
3635 Attribute_Name (Nod) = Name_Unchecked_Access
3637 Attribute_Name (Nod) = Name_Unrestricted_Access
3639 Check_At_Constant_Address (Prefix (Nod));
3642 Check_Expr_Constants (Prefix (Nod));
3643 Check_List_Constants (Expressions (Nod));
3647 Check_List_Constants (Component_Associations (Nod));
3648 Check_List_Constants (Expressions (Nod));
3650 when N_Component_Association =>
3651 Check_Expr_Constants (Expression (Nod));
3653 when N_Extension_Aggregate =>
3654 Check_Expr_Constants (Ancestor_Part (Nod));
3655 Check_List_Constants (Component_Associations (Nod));
3656 Check_List_Constants (Expressions (Nod));
3661 when N_Binary_Op | N_Short_Circuit | N_Membership_Test =>
3662 Check_Expr_Constants (Left_Opnd (Nod));
3663 Check_Expr_Constants (Right_Opnd (Nod));
3666 Check_Expr_Constants (Right_Opnd (Nod));
3668 when N_Type_Conversion |
3669 N_Qualified_Expression |
3671 Check_Expr_Constants (Expression (Nod));
3673 when N_Unchecked_Type_Conversion =>
3674 Check_Expr_Constants (Expression (Nod));
3676 -- If this is a rewritten unchecked conversion, subtypes in
3677 -- this node are those created within the instance. To avoid
3678 -- order of elaboration issues, replace them with their base
3679 -- types. Note that address clauses can cause order of
3680 -- elaboration problems because they are elaborated by the
3681 -- back-end at the point of definition, and may mention
3682 -- entities declared in between (as long as everything is
3683 -- static). It is user-friendly to allow unchecked conversions
3686 if Nkind (Original_Node (Nod)) = N_Function_Call then
3687 Set_Etype (Expression (Nod),
3688 Base_Type (Etype (Expression (Nod))));
3689 Set_Etype (Nod, Base_Type (Etype (Nod)));
3692 when N_Function_Call =>
3693 if not Is_Pure (Entity (Name (Nod))) then
3695 ("invalid address clause for initialized object &!",
3699 ("\function & is not pure (RM 13.1(22))!",
3700 Nod, Entity (Name (Nod)));
3703 Check_List_Constants (Parameter_Associations (Nod));
3706 when N_Parameter_Association =>
3707 Check_Expr_Constants (Explicit_Actual_Parameter (Nod));
3711 ("invalid address clause for initialized object &!",
3714 ("\must be constant defined before& (RM 13.1(22))!",
3717 end Check_Expr_Constants;
3719 --------------------------
3720 -- Check_List_Constants --
3721 --------------------------
3723 procedure Check_List_Constants (Lst : List_Id) is
3727 if Present (Lst) then
3728 Nod1 := First (Lst);
3729 while Present (Nod1) loop
3730 Check_Expr_Constants (Nod1);
3734 end Check_List_Constants;
3736 -- Start of processing for Check_Constant_Address_Clause
3739 -- If rep_clauses are to be ignored, no need for legality checks. In
3740 -- particular, no need to pester user about rep clauses that violate
3741 -- the rule on constant addresses, given that these clauses will be
3742 -- removed by Freeze before they reach the back end.
3744 if not Ignore_Rep_Clauses then
3745 Check_Expr_Constants (Expr);
3747 end Check_Constant_Address_Clause;
3749 ----------------------------------------
3750 -- Check_Record_Representation_Clause --
3751 ----------------------------------------
3753 procedure Check_Record_Representation_Clause (N : Node_Id) is
3754 Loc : constant Source_Ptr := Sloc (N);
3755 Ident : constant Node_Id := Identifier (N);
3756 Rectype : Entity_Id;
3761 Hbit : Uint := Uint_0;
3765 Max_Bit_So_Far : Uint;
3766 -- Records the maximum bit position so far. If all field positions
3767 -- are monotonically increasing, then we can skip the circuit for
3768 -- checking for overlap, since no overlap is possible.
3770 Tagged_Parent : Entity_Id := Empty;
3771 -- This is set in the case of a derived tagged type for which we have
3772 -- Is_Fully_Repped_Tagged_Type True (indicating that all components are
3773 -- positioned by record representation clauses). In this case we must
3774 -- check for overlap between components of this tagged type, and the
3775 -- components of its parent. Tagged_Parent will point to this parent
3776 -- type. For all other cases Tagged_Parent is left set to Empty.
3778 Parent_Last_Bit : Uint;
3779 -- Relevant only if Tagged_Parent is set, Parent_Last_Bit indicates the
3780 -- last bit position for any field in the parent type. We only need to
3781 -- check overlap for fields starting below this point.
3783 Overlap_Check_Required : Boolean;
3784 -- Used to keep track of whether or not an overlap check is required
3786 Overlap_Detected : Boolean := False;
3787 -- Set True if an overlap is detected
3789 Ccount : Natural := 0;
3790 -- Number of component clauses in record rep clause
3792 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id);
3793 -- Given two entities for record components or discriminants, checks
3794 -- if they have overlapping component clauses and issues errors if so.
3796 procedure Find_Component;
3797 -- Finds component entity corresponding to current component clause (in
3798 -- CC), and sets Comp to the entity, and Fbit/Lbit to the zero origin
3799 -- start/stop bits for the field. If there is no matching component or
3800 -- if the matching component does not have a component clause, then
3801 -- that's an error and Comp is set to Empty, but no error message is
3802 -- issued, since the message was already given. Comp is also set to
3803 -- Empty if the current "component clause" is in fact a pragma.
3805 -----------------------------
3806 -- Check_Component_Overlap --
3807 -----------------------------
3809 procedure Check_Component_Overlap (C1_Ent, C2_Ent : Entity_Id) is
3810 CC1 : constant Node_Id := Component_Clause (C1_Ent);
3811 CC2 : constant Node_Id := Component_Clause (C2_Ent);
3814 if Present (CC1) and then Present (CC2) then
3816 -- Exclude odd case where we have two tag fields in the same
3817 -- record, both at location zero. This seems a bit strange, but
3818 -- it seems to happen in some circumstances, perhaps on an error.
3820 if Chars (C1_Ent) = Name_uTag
3822 Chars (C2_Ent) = Name_uTag
3827 -- Here we check if the two fields overlap
3830 S1 : constant Uint := Component_Bit_Offset (C1_Ent);
3831 S2 : constant Uint := Component_Bit_Offset (C2_Ent);
3832 E1 : constant Uint := S1 + Esize (C1_Ent);
3833 E2 : constant Uint := S2 + Esize (C2_Ent);
3836 if E2 <= S1 or else E1 <= S2 then
3839 Error_Msg_Node_2 := Component_Name (CC2);
3840 Error_Msg_Sloc := Sloc (Error_Msg_Node_2);
3841 Error_Msg_Node_1 := Component_Name (CC1);
3843 ("component& overlaps & #", Component_Name (CC1));
3844 Overlap_Detected := True;
3848 end Check_Component_Overlap;
3850 --------------------
3851 -- Find_Component --
3852 --------------------
3854 procedure Find_Component is
3856 procedure Search_Component (R : Entity_Id);
3857 -- Search components of R for a match. If found, Comp is set.
3859 ----------------------
3860 -- Search_Component --
3861 ----------------------
3863 procedure Search_Component (R : Entity_Id) is
3865 Comp := First_Component_Or_Discriminant (R);
3866 while Present (Comp) loop
3868 -- Ignore error of attribute name for component name (we
3869 -- already gave an error message for this, so no need to
3872 if Nkind (Component_Name (CC)) = N_Attribute_Reference then
3875 exit when Chars (Comp) = Chars (Component_Name (CC));
3878 Next_Component_Or_Discriminant (Comp);
3880 end Search_Component;
3882 -- Start of processing for Find_Component
3885 -- Return with Comp set to Empty if we have a pragma
3887 if Nkind (CC) = N_Pragma then
3892 -- Search current record for matching component
3894 Search_Component (Rectype);
3896 -- If not found, maybe component of base type that is absent from
3897 -- statically constrained first subtype.
3900 Search_Component (Base_Type (Rectype));
3903 -- If no component, or the component does not reference the component
3904 -- clause in question, then there was some previous error for which
3905 -- we already gave a message, so just return with Comp Empty.
3908 or else Component_Clause (Comp) /= CC
3912 -- Normal case where we have a component clause
3915 Fbit := Component_Bit_Offset (Comp);
3916 Lbit := Fbit + Esize (Comp) - 1;
3920 -- Start of processing for Check_Record_Representation_Clause
3924 Rectype := Entity (Ident);
3926 if Rectype = Any_Type then
3929 Rectype := Underlying_Type (Rectype);
3932 -- See if we have a fully repped derived tagged type
3935 PS : constant Entity_Id := Parent_Subtype (Rectype);
3938 if Present (PS) and then Is_Fully_Repped_Tagged_Type (PS) then
3939 Tagged_Parent := PS;
3941 -- Find maximum bit of any component of the parent type
3943 Parent_Last_Bit := UI_From_Int (System_Address_Size - 1);
3944 Pcomp := First_Entity (Tagged_Parent);
3945 while Present (Pcomp) loop
3946 if Ekind_In (Pcomp, E_Discriminant, E_Component) then
3947 if Component_Bit_Offset (Pcomp) /= No_Uint
3948 and then Known_Static_Esize (Pcomp)
3953 Component_Bit_Offset (Pcomp) + Esize (Pcomp) - 1);
3956 Next_Entity (Pcomp);
3962 -- All done if no component clauses
3964 CC := First (Component_Clauses (N));
3970 -- If a tag is present, then create a component clause that places it
3971 -- at the start of the record (otherwise gigi may place it after other
3972 -- fields that have rep clauses).
3974 Fent := First_Entity (Rectype);
3976 if Nkind (Fent) = N_Defining_Identifier
3977 and then Chars (Fent) = Name_uTag
3979 Set_Component_Bit_Offset (Fent, Uint_0);
3980 Set_Normalized_Position (Fent, Uint_0);
3981 Set_Normalized_First_Bit (Fent, Uint_0);
3982 Set_Normalized_Position_Max (Fent, Uint_0);
3983 Init_Esize (Fent, System_Address_Size);
3985 Set_Component_Clause (Fent,
3986 Make_Component_Clause (Loc,
3988 Make_Identifier (Loc,
3989 Chars => Name_uTag),
3992 Make_Integer_Literal (Loc,
3996 Make_Integer_Literal (Loc,
4000 Make_Integer_Literal (Loc,
4001 UI_From_Int (System_Address_Size))));
4003 Ccount := Ccount + 1;
4006 Max_Bit_So_Far := Uint_Minus_1;
4007 Overlap_Check_Required := False;
4009 -- Process the component clauses
4011 while Present (CC) loop
4014 if Present (Comp) then
4015 Ccount := Ccount + 1;
4017 -- We need a full overlap check if record positions non-monotonic
4019 if Fbit <= Max_Bit_So_Far then
4020 Overlap_Check_Required := True;
4023 Max_Bit_So_Far := Lbit;
4025 -- Check bit position out of range of specified size
4027 if Has_Size_Clause (Rectype)
4028 and then Esize (Rectype) <= Lbit
4031 ("bit number out of range of specified size",
4034 -- Check for overlap with tag field
4037 if Is_Tagged_Type (Rectype)
4038 and then Fbit < System_Address_Size
4041 ("component overlaps tag field of&",
4042 Component_Name (CC), Rectype);
4043 Overlap_Detected := True;
4051 -- Check parent overlap if component might overlap parent field
4053 if Present (Tagged_Parent)
4054 and then Fbit <= Parent_Last_Bit
4056 Pcomp := First_Component_Or_Discriminant (Tagged_Parent);
4057 while Present (Pcomp) loop
4058 if not Is_Tag (Pcomp)
4059 and then Chars (Pcomp) /= Name_uParent
4061 Check_Component_Overlap (Comp, Pcomp);
4064 Next_Component_Or_Discriminant (Pcomp);
4072 -- Now that we have processed all the component clauses, check for
4073 -- overlap. We have to leave this till last, since the components can
4074 -- appear in any arbitrary order in the representation clause.
4076 -- We do not need this check if all specified ranges were monotonic,
4077 -- as recorded by Overlap_Check_Required being False at this stage.
4079 -- This first section checks if there are any overlapping entries at
4080 -- all. It does this by sorting all entries and then seeing if there are
4081 -- any overlaps. If there are none, then that is decisive, but if there
4082 -- are overlaps, they may still be OK (they may result from fields in
4083 -- different variants).
4085 if Overlap_Check_Required then
4086 Overlap_Check1 : declare
4088 OC_Fbit : array (0 .. Ccount) of Uint;
4089 -- First-bit values for component clauses, the value is the offset
4090 -- of the first bit of the field from start of record. The zero
4091 -- entry is for use in sorting.
4093 OC_Lbit : array (0 .. Ccount) of Uint;
4094 -- Last-bit values for component clauses, the value is the offset
4095 -- of the last bit of the field from start of record. The zero
4096 -- entry is for use in sorting.
4098 OC_Count : Natural := 0;
4099 -- Count of entries in OC_Fbit and OC_Lbit
4101 function OC_Lt (Op1, Op2 : Natural) return Boolean;
4102 -- Compare routine for Sort
4104 procedure OC_Move (From : Natural; To : Natural);
4105 -- Move routine for Sort
4107 package Sorting is new GNAT.Heap_Sort_G (OC_Move, OC_Lt);
4113 function OC_Lt (Op1, Op2 : Natural) return Boolean is
4115 return OC_Fbit (Op1) < OC_Fbit (Op2);
4122 procedure OC_Move (From : Natural; To : Natural) is
4124 OC_Fbit (To) := OC_Fbit (From);
4125 OC_Lbit (To) := OC_Lbit (From);
4128 -- Start of processing for Overlap_Check
4131 CC := First (Component_Clauses (N));
4132 while Present (CC) loop
4134 -- Exclude component clause already marked in error
4136 if not Error_Posted (CC) then
4139 if Present (Comp) then
4140 OC_Count := OC_Count + 1;
4141 OC_Fbit (OC_Count) := Fbit;
4142 OC_Lbit (OC_Count) := Lbit;
4149 Sorting.Sort (OC_Count);
4151 Overlap_Check_Required := False;
4152 for J in 1 .. OC_Count - 1 loop
4153 if OC_Lbit (J) >= OC_Fbit (J + 1) then
4154 Overlap_Check_Required := True;
4161 -- If Overlap_Check_Required is still True, then we have to do the full
4162 -- scale overlap check, since we have at least two fields that do
4163 -- overlap, and we need to know if that is OK since they are in
4164 -- different variant, or whether we have a definite problem.
4166 if Overlap_Check_Required then
4167 Overlap_Check2 : declare
4168 C1_Ent, C2_Ent : Entity_Id;
4169 -- Entities of components being checked for overlap
4172 -- Component_List node whose Component_Items are being checked
4175 -- Component declaration for component being checked
4178 C1_Ent := First_Entity (Base_Type (Rectype));
4180 -- Loop through all components in record. For each component check
4181 -- for overlap with any of the preceding elements on the component
4182 -- list containing the component and also, if the component is in
4183 -- a variant, check against components outside the case structure.
4184 -- This latter test is repeated recursively up the variant tree.
4186 Main_Component_Loop : while Present (C1_Ent) loop
4187 if not Ekind_In (C1_Ent, E_Component, E_Discriminant) then
4188 goto Continue_Main_Component_Loop;
4191 -- Skip overlap check if entity has no declaration node. This
4192 -- happens with discriminants in constrained derived types.
4193 -- Possibly we are missing some checks as a result, but that
4194 -- does not seem terribly serious.
4196 if No (Declaration_Node (C1_Ent)) then
4197 goto Continue_Main_Component_Loop;
4200 Clist := Parent (List_Containing (Declaration_Node (C1_Ent)));
4202 -- Loop through component lists that need checking. Check the
4203 -- current component list and all lists in variants above us.
4205 Component_List_Loop : loop
4207 -- If derived type definition, go to full declaration
4208 -- If at outer level, check discriminants if there are any.
4210 if Nkind (Clist) = N_Derived_Type_Definition then
4211 Clist := Parent (Clist);
4214 -- Outer level of record definition, check discriminants
4216 if Nkind_In (Clist, N_Full_Type_Declaration,
4217 N_Private_Type_Declaration)
4219 if Has_Discriminants (Defining_Identifier (Clist)) then
4221 First_Discriminant (Defining_Identifier (Clist));
4222 while Present (C2_Ent) loop
4223 exit when C1_Ent = C2_Ent;
4224 Check_Component_Overlap (C1_Ent, C2_Ent);
4225 Next_Discriminant (C2_Ent);
4229 -- Record extension case
4231 elsif Nkind (Clist) = N_Derived_Type_Definition then
4234 -- Otherwise check one component list
4237 Citem := First (Component_Items (Clist));
4238 while Present (Citem) loop
4239 if Nkind (Citem) = N_Component_Declaration then
4240 C2_Ent := Defining_Identifier (Citem);
4241 exit when C1_Ent = C2_Ent;
4242 Check_Component_Overlap (C1_Ent, C2_Ent);
4249 -- Check for variants above us (the parent of the Clist can
4250 -- be a variant, in which case its parent is a variant part,
4251 -- and the parent of the variant part is a component list
4252 -- whose components must all be checked against the current
4253 -- component for overlap).
4255 if Nkind (Parent (Clist)) = N_Variant then
4256 Clist := Parent (Parent (Parent (Clist)));
4258 -- Check for possible discriminant part in record, this
4259 -- is treated essentially as another level in the
4260 -- recursion. For this case the parent of the component
4261 -- list is the record definition, and its parent is the
4262 -- full type declaration containing the discriminant
4265 elsif Nkind (Parent (Clist)) = N_Record_Definition then
4266 Clist := Parent (Parent ((Clist)));
4268 -- If neither of these two cases, we are at the top of
4272 exit Component_List_Loop;
4274 end loop Component_List_Loop;
4276 <<Continue_Main_Component_Loop>>
4277 Next_Entity (C1_Ent);
4279 end loop Main_Component_Loop;
4283 -- The following circuit deals with warning on record holes (gaps). We
4284 -- skip this check if overlap was detected, since it makes sense for the
4285 -- programmer to fix this illegality before worrying about warnings.
4287 if not Overlap_Detected and Warn_On_Record_Holes then
4288 Record_Hole_Check : declare
4289 Decl : constant Node_Id := Declaration_Node (Base_Type (Rectype));
4290 -- Full declaration of record type
4292 procedure Check_Component_List
4296 -- Check component list CL for holes. The starting bit should be
4297 -- Sbit. which is zero for the main record component list and set
4298 -- appropriately for recursive calls for variants. DS is set to
4299 -- a list of discriminant specifications to be included in the
4300 -- consideration of components. It is No_List if none to consider.
4302 --------------------------
4303 -- Check_Component_List --
4304 --------------------------
4306 procedure Check_Component_List
4314 Compl := Integer (List_Length (Component_Items (CL)));
4316 if DS /= No_List then
4317 Compl := Compl + Integer (List_Length (DS));
4321 Comps : array (Natural range 0 .. Compl) of Entity_Id;
4322 -- Gather components (zero entry is for sort routine)
4324 Ncomps : Natural := 0;
4325 -- Number of entries stored in Comps (starting at Comps (1))
4328 -- One component item or discriminant specification
4331 -- Starting bit for next component
4339 function Lt (Op1, Op2 : Natural) return Boolean;
4340 -- Compare routine for Sort
4342 procedure Move (From : Natural; To : Natural);
4343 -- Move routine for Sort
4345 package Sorting is new GNAT.Heap_Sort_G (Move, Lt);
4351 function Lt (Op1, Op2 : Natural) return Boolean is
4353 return Component_Bit_Offset (Comps (Op1))
4355 Component_Bit_Offset (Comps (Op2));
4362 procedure Move (From : Natural; To : Natural) is
4364 Comps (To) := Comps (From);
4368 -- Gather discriminants into Comp
4370 if DS /= No_List then
4371 Citem := First (DS);
4372 while Present (Citem) loop
4373 if Nkind (Citem) = N_Discriminant_Specification then
4375 Ent : constant Entity_Id :=
4376 Defining_Identifier (Citem);
4378 if Ekind (Ent) = E_Discriminant then
4379 Ncomps := Ncomps + 1;
4380 Comps (Ncomps) := Ent;
4389 -- Gather component entities into Comp
4391 Citem := First (Component_Items (CL));
4392 while Present (Citem) loop
4393 if Nkind (Citem) = N_Component_Declaration then
4394 Ncomps := Ncomps + 1;
4395 Comps (Ncomps) := Defining_Identifier (Citem);
4401 -- Now sort the component entities based on the first bit.
4402 -- Note we already know there are no overlapping components.
4404 Sorting.Sort (Ncomps);
4406 -- Loop through entries checking for holes
4409 for J in 1 .. Ncomps loop
4411 Error_Msg_Uint_1 := Component_Bit_Offset (CEnt) - Nbit;
4413 if Error_Msg_Uint_1 > 0 then
4415 ("?^-bit gap before component&",
4416 Component_Name (Component_Clause (CEnt)), CEnt);
4419 Nbit := Component_Bit_Offset (CEnt) + Esize (CEnt);
4422 -- Process variant parts recursively if present
4424 if Present (Variant_Part (CL)) then
4425 Variant := First (Variants (Variant_Part (CL)));
4426 while Present (Variant) loop
4427 Check_Component_List
4428 (Component_List (Variant), Nbit, No_List);
4433 end Check_Component_List;
4435 -- Start of processing for Record_Hole_Check
4442 if Is_Tagged_Type (Rectype) then
4443 Sbit := UI_From_Int (System_Address_Size);
4448 if Nkind (Decl) = N_Full_Type_Declaration
4449 and then Nkind (Type_Definition (Decl)) = N_Record_Definition
4451 Check_Component_List
4452 (Component_List (Type_Definition (Decl)),
4454 Discriminant_Specifications (Decl));
4457 end Record_Hole_Check;
4460 -- For records that have component clauses for all components, and whose
4461 -- size is less than or equal to 32, we need to know the size in the
4462 -- front end to activate possible packed array processing where the
4463 -- component type is a record.
4465 -- At this stage Hbit + 1 represents the first unused bit from all the
4466 -- component clauses processed, so if the component clauses are
4467 -- complete, then this is the length of the record.
4469 -- For records longer than System.Storage_Unit, and for those where not
4470 -- all components have component clauses, the back end determines the
4471 -- length (it may for example be appropriate to round up the size
4472 -- to some convenient boundary, based on alignment considerations, etc).
4474 if Unknown_RM_Size (Rectype) and then Hbit + 1 <= 32 then
4476 -- Nothing to do if at least one component has no component clause
4478 Comp := First_Component_Or_Discriminant (Rectype);
4479 while Present (Comp) loop
4480 exit when No (Component_Clause (Comp));
4481 Next_Component_Or_Discriminant (Comp);
4484 -- If we fall out of loop, all components have component clauses
4485 -- and so we can set the size to the maximum value.
4488 Set_RM_Size (Rectype, Hbit + 1);
4491 end Check_Record_Representation_Clause;
4497 procedure Check_Size
4501 Biased : out Boolean)
4503 UT : constant Entity_Id := Underlying_Type (T);
4509 -- Dismiss cases for generic types or types with previous errors
4512 or else UT = Any_Type
4513 or else Is_Generic_Type (UT)
4514 or else Is_Generic_Type (Root_Type (UT))
4518 -- Check case of bit packed array
4520 elsif Is_Array_Type (UT)
4521 and then Known_Static_Component_Size (UT)
4522 and then Is_Bit_Packed_Array (UT)
4530 Asiz := Component_Size (UT);
4531 Indx := First_Index (UT);
4533 Ityp := Etype (Indx);
4535 -- If non-static bound, then we are not in the business of
4536 -- trying to check the length, and indeed an error will be
4537 -- issued elsewhere, since sizes of non-static array types
4538 -- cannot be set implicitly or explicitly.
4540 if not Is_Static_Subtype (Ityp) then
4544 -- Otherwise accumulate next dimension
4546 Asiz := Asiz * (Expr_Value (Type_High_Bound (Ityp)) -
4547 Expr_Value (Type_Low_Bound (Ityp)) +
4551 exit when No (Indx);
4557 Error_Msg_Uint_1 := Asiz;
4559 ("size for& too small, minimum allowed is ^", N, T);
4560 Set_Esize (T, Asiz);
4561 Set_RM_Size (T, Asiz);
4565 -- All other composite types are ignored
4567 elsif Is_Composite_Type (UT) then
4570 -- For fixed-point types, don't check minimum if type is not frozen,
4571 -- since we don't know all the characteristics of the type that can
4572 -- affect the size (e.g. a specified small) till freeze time.
4574 elsif Is_Fixed_Point_Type (UT)
4575 and then not Is_Frozen (UT)
4579 -- Cases for which a minimum check is required
4582 -- Ignore if specified size is correct for the type
4584 if Known_Esize (UT) and then Siz = Esize (UT) then
4588 -- Otherwise get minimum size
4590 M := UI_From_Int (Minimum_Size (UT));
4594 -- Size is less than minimum size, but one possibility remains
4595 -- that we can manage with the new size if we bias the type.
4597 M := UI_From_Int (Minimum_Size (UT, Biased => True));
4600 Error_Msg_Uint_1 := M;
4602 ("size for& too small, minimum allowed is ^", N, T);
4612 -------------------------
4613 -- Get_Alignment_Value --
4614 -------------------------
4616 function Get_Alignment_Value (Expr : Node_Id) return Uint is
4617 Align : constant Uint := Static_Integer (Expr);
4620 if Align = No_Uint then
4623 elsif Align <= 0 then
4624 Error_Msg_N ("alignment value must be positive", Expr);
4628 for J in Int range 0 .. 64 loop
4630 M : constant Uint := Uint_2 ** J;
4633 exit when M = Align;
4637 ("alignment value must be power of 2", Expr);
4645 end Get_Alignment_Value;
4651 procedure Initialize is
4653 Address_Clause_Checks.Init;
4654 Independence_Checks.Init;
4655 Unchecked_Conversions.Init;
4658 -------------------------
4659 -- Is_Operational_Item --
4660 -------------------------
4662 function Is_Operational_Item (N : Node_Id) return Boolean is
4664 if Nkind (N) /= N_Attribute_Definition_Clause then
4668 Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
4670 return Id = Attribute_Input
4671 or else Id = Attribute_Output
4672 or else Id = Attribute_Read
4673 or else Id = Attribute_Write
4674 or else Id = Attribute_External_Tag;
4677 end Is_Operational_Item;
4683 function Minimum_Size
4685 Biased : Boolean := False) return Nat
4687 Lo : Uint := No_Uint;
4688 Hi : Uint := No_Uint;
4689 LoR : Ureal := No_Ureal;
4690 HiR : Ureal := No_Ureal;
4691 LoSet : Boolean := False;
4692 HiSet : Boolean := False;
4696 R_Typ : constant Entity_Id := Root_Type (T);
4699 -- If bad type, return 0
4701 if T = Any_Type then
4704 -- For generic types, just return zero. There cannot be any legitimate
4705 -- need to know such a size, but this routine may be called with a
4706 -- generic type as part of normal processing.
4708 elsif Is_Generic_Type (R_Typ)
4709 or else R_Typ = Any_Type
4713 -- Access types. Normally an access type cannot have a size smaller
4714 -- than the size of System.Address. The exception is on VMS, where
4715 -- we have short and long addresses, and it is possible for an access
4716 -- type to have a short address size (and thus be less than the size
4717 -- of System.Address itself). We simply skip the check for VMS, and
4718 -- leave it to the back end to do the check.
4720 elsif Is_Access_Type (T) then
4721 if OpenVMS_On_Target then
4724 return System_Address_Size;
4727 -- Floating-point types
4729 elsif Is_Floating_Point_Type (T) then
4730 return UI_To_Int (Esize (R_Typ));
4734 elsif Is_Discrete_Type (T) then
4736 -- The following loop is looking for the nearest compile time known
4737 -- bounds following the ancestor subtype chain. The idea is to find
4738 -- the most restrictive known bounds information.
4742 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
4747 if Compile_Time_Known_Value (Type_Low_Bound (Ancest)) then
4748 Lo := Expr_Rep_Value (Type_Low_Bound (Ancest));
4755 if Compile_Time_Known_Value (Type_High_Bound (Ancest)) then
4756 Hi := Expr_Rep_Value (Type_High_Bound (Ancest));
4762 Ancest := Ancestor_Subtype (Ancest);
4765 Ancest := Base_Type (T);
4767 if Is_Generic_Type (Ancest) then
4773 -- Fixed-point types. We can't simply use Expr_Value to get the
4774 -- Corresponding_Integer_Value values of the bounds, since these do not
4775 -- get set till the type is frozen, and this routine can be called
4776 -- before the type is frozen. Similarly the test for bounds being static
4777 -- needs to include the case where we have unanalyzed real literals for
4780 elsif Is_Fixed_Point_Type (T) then
4782 -- The following loop is looking for the nearest compile time known
4783 -- bounds following the ancestor subtype chain. The idea is to find
4784 -- the most restrictive known bounds information.
4788 if Ancest = Any_Type or else Etype (Ancest) = Any_Type then
4792 -- Note: In the following two tests for LoSet and HiSet, it may
4793 -- seem redundant to test for N_Real_Literal here since normally
4794 -- one would assume that the test for the value being known at
4795 -- compile time includes this case. However, there is a glitch.
4796 -- If the real literal comes from folding a non-static expression,
4797 -- then we don't consider any non- static expression to be known
4798 -- at compile time if we are in configurable run time mode (needed
4799 -- in some cases to give a clearer definition of what is and what
4800 -- is not accepted). So the test is indeed needed. Without it, we
4801 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
4804 if Nkind (Type_Low_Bound (Ancest)) = N_Real_Literal
4805 or else Compile_Time_Known_Value (Type_Low_Bound (Ancest))
4807 LoR := Expr_Value_R (Type_Low_Bound (Ancest));
4814 if Nkind (Type_High_Bound (Ancest)) = N_Real_Literal
4815 or else Compile_Time_Known_Value (Type_High_Bound (Ancest))
4817 HiR := Expr_Value_R (Type_High_Bound (Ancest));
4823 Ancest := Ancestor_Subtype (Ancest);
4826 Ancest := Base_Type (T);
4828 if Is_Generic_Type (Ancest) then
4834 Lo := UR_To_Uint (LoR / Small_Value (T));
4835 Hi := UR_To_Uint (HiR / Small_Value (T));
4837 -- No other types allowed
4840 raise Program_Error;
4843 -- Fall through with Hi and Lo set. Deal with biased case
4846 and then not Is_Fixed_Point_Type (T)
4847 and then not (Is_Enumeration_Type (T)
4848 and then Has_Non_Standard_Rep (T)))
4849 or else Has_Biased_Representation (T)
4855 -- Signed case. Note that we consider types like range 1 .. -1 to be
4856 -- signed for the purpose of computing the size, since the bounds have
4857 -- to be accommodated in the base type.
4859 if Lo < 0 or else Hi < 0 then
4863 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
4864 -- Note that we accommodate the case where the bounds cross. This
4865 -- can happen either because of the way the bounds are declared
4866 -- or because of the algorithm in Freeze_Fixed_Point_Type.
4880 -- If both bounds are positive, make sure that both are represen-
4881 -- table in the case where the bounds are crossed. This can happen
4882 -- either because of the way the bounds are declared, or because of
4883 -- the algorithm in Freeze_Fixed_Point_Type.
4889 -- S = size, (can accommodate 0 .. (2**size - 1))
4892 while Hi >= Uint_2 ** S loop
4900 ---------------------------
4901 -- New_Stream_Subprogram --
4902 ---------------------------
4904 procedure New_Stream_Subprogram
4908 Nam : TSS_Name_Type)
4910 Loc : constant Source_Ptr := Sloc (N);
4911 Sname : constant Name_Id := Make_TSS_Name (Base_Type (Ent), Nam);
4912 Subp_Id : Entity_Id;
4913 Subp_Decl : Node_Id;
4917 Defer_Declaration : constant Boolean :=
4918 Is_Tagged_Type (Ent) or else Is_Private_Type (Ent);
4919 -- For a tagged type, there is a declaration for each stream attribute
4920 -- at the freeze point, and we must generate only a completion of this
4921 -- declaration. We do the same for private types, because the full view
4922 -- might be tagged. Otherwise we generate a declaration at the point of
4923 -- the attribute definition clause.
4925 function Build_Spec return Node_Id;
4926 -- Used for declaration and renaming declaration, so that this is
4927 -- treated as a renaming_as_body.
4933 function Build_Spec return Node_Id is
4934 Out_P : constant Boolean := (Nam = TSS_Stream_Read);
4937 T_Ref : constant Node_Id := New_Reference_To (Etyp, Loc);
4940 Subp_Id := Make_Defining_Identifier (Loc, Sname);
4942 -- S : access Root_Stream_Type'Class
4944 Formals := New_List (
4945 Make_Parameter_Specification (Loc,
4946 Defining_Identifier =>
4947 Make_Defining_Identifier (Loc, Name_S),
4949 Make_Access_Definition (Loc,
4952 Designated_Type (Etype (F)), Loc))));
4954 if Nam = TSS_Stream_Input then
4955 Spec := Make_Function_Specification (Loc,
4956 Defining_Unit_Name => Subp_Id,
4957 Parameter_Specifications => Formals,
4958 Result_Definition => T_Ref);
4963 Make_Parameter_Specification (Loc,
4964 Defining_Identifier => Make_Defining_Identifier (Loc, Name_V),
4965 Out_Present => Out_P,
4966 Parameter_Type => T_Ref));
4969 Make_Procedure_Specification (Loc,
4970 Defining_Unit_Name => Subp_Id,
4971 Parameter_Specifications => Formals);
4977 -- Start of processing for New_Stream_Subprogram
4980 F := First_Formal (Subp);
4982 if Ekind (Subp) = E_Procedure then
4983 Etyp := Etype (Next_Formal (F));
4985 Etyp := Etype (Subp);
4988 -- Prepare subprogram declaration and insert it as an action on the
4989 -- clause node. The visibility for this entity is used to test for
4990 -- visibility of the attribute definition clause (in the sense of
4991 -- 8.3(23) as amended by AI-195).
4993 if not Defer_Declaration then
4995 Make_Subprogram_Declaration (Loc,
4996 Specification => Build_Spec);
4998 -- For a tagged type, there is always a visible declaration for each
4999 -- stream TSS (it is a predefined primitive operation), and the
5000 -- completion of this declaration occurs at the freeze point, which is
5001 -- not always visible at places where the attribute definition clause is
5002 -- visible. So, we create a dummy entity here for the purpose of
5003 -- tracking the visibility of the attribute definition clause itself.
5007 Make_Defining_Identifier (Loc,
5008 Chars => New_External_Name (Sname, 'V'));
5010 Make_Object_Declaration (Loc,
5011 Defining_Identifier => Subp_Id,
5012 Object_Definition => New_Occurrence_Of (Standard_Boolean, Loc));
5015 Insert_Action (N, Subp_Decl);
5016 Set_Entity (N, Subp_Id);
5019 Make_Subprogram_Renaming_Declaration (Loc,
5020 Specification => Build_Spec,
5021 Name => New_Reference_To (Subp, Loc));
5023 if Defer_Declaration then
5024 Set_TSS (Base_Type (Ent), Subp_Id);
5026 Insert_Action (N, Subp_Decl);
5027 Copy_TSS (Subp_Id, Base_Type (Ent));
5029 end New_Stream_Subprogram;
5031 ------------------------
5032 -- Rep_Item_Too_Early --
5033 ------------------------
5035 function Rep_Item_Too_Early (T : Entity_Id; N : Node_Id) return Boolean is
5037 -- Cannot apply non-operational rep items to generic types
5039 if Is_Operational_Item (N) then
5043 and then Is_Generic_Type (Root_Type (T))
5045 Error_Msg_N ("representation item not allowed for generic type", N);
5049 -- Otherwise check for incomplete type
5051 if Is_Incomplete_Or_Private_Type (T)
5052 and then No (Underlying_Type (T))
5055 ("representation item must be after full type declaration", N);
5058 -- If the type has incomplete components, a representation clause is
5059 -- illegal but stream attributes and Convention pragmas are correct.
5061 elsif Has_Private_Component (T) then
5062 if Nkind (N) = N_Pragma then
5066 ("representation item must appear after type is fully defined",
5073 end Rep_Item_Too_Early;
5075 -----------------------
5076 -- Rep_Item_Too_Late --
5077 -----------------------
5079 function Rep_Item_Too_Late
5082 FOnly : Boolean := False) return Boolean
5085 Parent_Type : Entity_Id;
5088 -- Output the too late message. Note that this is not considered a
5089 -- serious error, since the effect is simply that we ignore the
5090 -- representation clause in this case.
5096 procedure Too_Late is
5098 Error_Msg_N ("|representation item appears too late!", N);
5101 -- Start of processing for Rep_Item_Too_Late
5104 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
5105 -- types, which may be frozen if they appear in a representation clause
5106 -- for a local type.
5109 and then not From_With_Type (T)
5112 S := First_Subtype (T);
5114 if Present (Freeze_Node (S)) then
5116 ("?no more representation items for }", Freeze_Node (S), S);
5121 -- Check for case of non-tagged derived type whose parent either has
5122 -- primitive operations, or is a by reference type (RM 13.1(10)).
5126 and then Is_Derived_Type (T)
5127 and then not Is_Tagged_Type (T)
5129 Parent_Type := Etype (Base_Type (T));
5131 if Has_Primitive_Operations (Parent_Type) then
5134 ("primitive operations already defined for&!", N, Parent_Type);
5137 elsif Is_By_Reference_Type (Parent_Type) then
5140 ("parent type & is a by reference type!", N, Parent_Type);
5145 -- No error, link item into head of chain of rep items for the entity,
5146 -- but avoid chaining if we have an overloadable entity, and the pragma
5147 -- is one that can apply to multiple overloaded entities.
5149 if Is_Overloadable (T)
5150 and then Nkind (N) = N_Pragma
5153 Pname : constant Name_Id := Pragma_Name (N);
5155 if Pname = Name_Convention or else
5156 Pname = Name_Import or else
5157 Pname = Name_Export or else
5158 Pname = Name_External or else
5159 Pname = Name_Interface
5166 Record_Rep_Item (T, N);
5168 end Rep_Item_Too_Late;
5170 -------------------------
5171 -- Same_Representation --
5172 -------------------------
5174 function Same_Representation (Typ1, Typ2 : Entity_Id) return Boolean is
5175 T1 : constant Entity_Id := Underlying_Type (Typ1);
5176 T2 : constant Entity_Id := Underlying_Type (Typ2);
5179 -- A quick check, if base types are the same, then we definitely have
5180 -- the same representation, because the subtype specific representation
5181 -- attributes (Size and Alignment) do not affect representation from
5182 -- the point of view of this test.
5184 if Base_Type (T1) = Base_Type (T2) then
5187 elsif Is_Private_Type (Base_Type (T2))
5188 and then Base_Type (T1) = Full_View (Base_Type (T2))
5193 -- Tagged types never have differing representations
5195 if Is_Tagged_Type (T1) then
5199 -- Representations are definitely different if conventions differ
5201 if Convention (T1) /= Convention (T2) then
5205 -- Representations are different if component alignments differ
5207 if (Is_Record_Type (T1) or else Is_Array_Type (T1))
5209 (Is_Record_Type (T2) or else Is_Array_Type (T2))
5210 and then Component_Alignment (T1) /= Component_Alignment (T2)
5215 -- For arrays, the only real issue is component size. If we know the
5216 -- component size for both arrays, and it is the same, then that's
5217 -- good enough to know we don't have a change of representation.
5219 if Is_Array_Type (T1) then
5220 if Known_Component_Size (T1)
5221 and then Known_Component_Size (T2)
5222 and then Component_Size (T1) = Component_Size (T2)
5228 -- Types definitely have same representation if neither has non-standard
5229 -- representation since default representations are always consistent.
5230 -- If only one has non-standard representation, and the other does not,
5231 -- then we consider that they do not have the same representation. They
5232 -- might, but there is no way of telling early enough.
5234 if Has_Non_Standard_Rep (T1) then
5235 if not Has_Non_Standard_Rep (T2) then
5239 return not Has_Non_Standard_Rep (T2);
5242 -- Here the two types both have non-standard representation, and we need
5243 -- to determine if they have the same non-standard representation.
5245 -- For arrays, we simply need to test if the component sizes are the
5246 -- same. Pragma Pack is reflected in modified component sizes, so this
5247 -- check also deals with pragma Pack.
5249 if Is_Array_Type (T1) then
5250 return Component_Size (T1) = Component_Size (T2);
5252 -- Tagged types always have the same representation, because it is not
5253 -- possible to specify different representations for common fields.
5255 elsif Is_Tagged_Type (T1) then
5258 -- Case of record types
5260 elsif Is_Record_Type (T1) then
5262 -- Packed status must conform
5264 if Is_Packed (T1) /= Is_Packed (T2) then
5267 -- Otherwise we must check components. Typ2 maybe a constrained
5268 -- subtype with fewer components, so we compare the components
5269 -- of the base types.
5272 Record_Case : declare
5273 CD1, CD2 : Entity_Id;
5275 function Same_Rep return Boolean;
5276 -- CD1 and CD2 are either components or discriminants. This
5277 -- function tests whether the two have the same representation
5283 function Same_Rep return Boolean is
5285 if No (Component_Clause (CD1)) then
5286 return No (Component_Clause (CD2));
5290 Present (Component_Clause (CD2))
5292 Component_Bit_Offset (CD1) = Component_Bit_Offset (CD2)
5294 Esize (CD1) = Esize (CD2);
5298 -- Start of processing for Record_Case
5301 if Has_Discriminants (T1) then
5302 CD1 := First_Discriminant (T1);
5303 CD2 := First_Discriminant (T2);
5305 -- The number of discriminants may be different if the
5306 -- derived type has fewer (constrained by values). The
5307 -- invisible discriminants retain the representation of
5308 -- the original, so the discrepancy does not per se
5309 -- indicate a different representation.
5312 and then Present (CD2)
5314 if not Same_Rep then
5317 Next_Discriminant (CD1);
5318 Next_Discriminant (CD2);
5323 CD1 := First_Component (Underlying_Type (Base_Type (T1)));
5324 CD2 := First_Component (Underlying_Type (Base_Type (T2)));
5326 while Present (CD1) loop
5327 if not Same_Rep then
5330 Next_Component (CD1);
5331 Next_Component (CD2);
5339 -- For enumeration types, we must check each literal to see if the
5340 -- representation is the same. Note that we do not permit enumeration
5341 -- representation clauses for Character and Wide_Character, so these
5342 -- cases were already dealt with.
5344 elsif Is_Enumeration_Type (T1) then
5345 Enumeration_Case : declare
5349 L1 := First_Literal (T1);
5350 L2 := First_Literal (T2);
5352 while Present (L1) loop
5353 if Enumeration_Rep (L1) /= Enumeration_Rep (L2) then
5363 end Enumeration_Case;
5365 -- Any other types have the same representation for these purposes
5370 end Same_Representation;
5376 procedure Set_Biased
5380 Biased : Boolean := True)
5384 Set_Has_Biased_Representation (E);
5386 if Warn_On_Biased_Representation then
5388 ("?" & Msg & " forces biased representation for&", N, E);
5393 --------------------
5394 -- Set_Enum_Esize --
5395 --------------------
5397 procedure Set_Enum_Esize (T : Entity_Id) is
5405 -- Find the minimum standard size (8,16,32,64) that fits
5407 Lo := Enumeration_Rep (Entity (Type_Low_Bound (T)));
5408 Hi := Enumeration_Rep (Entity (Type_High_Bound (T)));
5411 if Lo >= -Uint_2**07 and then Hi < Uint_2**07 then
5412 Sz := Standard_Character_Size; -- May be > 8 on some targets
5414 elsif Lo >= -Uint_2**15 and then Hi < Uint_2**15 then
5417 elsif Lo >= -Uint_2**31 and then Hi < Uint_2**31 then
5420 else pragma Assert (Lo >= -Uint_2**63 and then Hi < Uint_2**63);
5425 if Hi < Uint_2**08 then
5426 Sz := Standard_Character_Size; -- May be > 8 on some targets
5428 elsif Hi < Uint_2**16 then
5431 elsif Hi < Uint_2**32 then
5434 else pragma Assert (Hi < Uint_2**63);
5439 -- That minimum is the proper size unless we have a foreign convention
5440 -- and the size required is 32 or less, in which case we bump the size
5441 -- up to 32. This is required for C and C++ and seems reasonable for
5442 -- all other foreign conventions.
5444 if Has_Foreign_Convention (T)
5445 and then Esize (T) < Standard_Integer_Size
5447 Init_Esize (T, Standard_Integer_Size);
5453 ------------------------------
5454 -- Validate_Address_Clauses --
5455 ------------------------------
5457 procedure Validate_Address_Clauses is
5459 for J in Address_Clause_Checks.First .. Address_Clause_Checks.Last loop
5461 ACCR : Address_Clause_Check_Record
5462 renames Address_Clause_Checks.Table (J);
5473 -- Skip processing of this entry if warning already posted
5475 if not Address_Warning_Posted (ACCR.N) then
5477 Expr := Original_Node (Expression (ACCR.N));
5481 X_Alignment := Alignment (ACCR.X);
5482 Y_Alignment := Alignment (ACCR.Y);
5484 -- Similarly obtain sizes
5486 X_Size := Esize (ACCR.X);
5487 Y_Size := Esize (ACCR.Y);
5489 -- Check for large object overlaying smaller one
5492 and then X_Size > Uint_0
5493 and then X_Size > Y_Size
5496 ("?& overlays smaller object", ACCR.N, ACCR.X);
5498 ("\?program execution may be erroneous", ACCR.N);
5499 Error_Msg_Uint_1 := X_Size;
5501 ("\?size of & is ^", ACCR.N, ACCR.X);
5502 Error_Msg_Uint_1 := Y_Size;
5504 ("\?size of & is ^", ACCR.N, ACCR.Y);
5506 -- Check for inadequate alignment, both of the base object
5507 -- and of the offset, if any.
5509 -- Note: we do not check the alignment if we gave a size
5510 -- warning, since it would likely be redundant.
5512 elsif Y_Alignment /= Uint_0
5513 and then (Y_Alignment < X_Alignment
5516 Nkind (Expr) = N_Attribute_Reference
5518 Attribute_Name (Expr) = Name_Address
5520 Has_Compatible_Alignment
5521 (ACCR.X, Prefix (Expr))
5522 /= Known_Compatible))
5525 ("?specified address for& may be inconsistent "
5529 ("\?program execution may be erroneous (RM 13.3(27))",
5531 Error_Msg_Uint_1 := X_Alignment;
5533 ("\?alignment of & is ^",
5535 Error_Msg_Uint_1 := Y_Alignment;
5537 ("\?alignment of & is ^",
5539 if Y_Alignment >= X_Alignment then
5541 ("\?but offset is not multiple of alignment",
5548 end Validate_Address_Clauses;
5550 ---------------------------
5551 -- Validate_Independence --
5552 ---------------------------
5554 procedure Validate_Independence is
5555 SU : constant Uint := UI_From_Int (System_Storage_Unit);
5563 procedure Check_Array_Type (Atyp : Entity_Id);
5564 -- Checks if the array type Atyp has independent components, and
5565 -- if not, outputs an appropriate set of error messages.
5567 procedure No_Independence;
5568 -- Output message that independence cannot be guaranteed
5570 function OK_Component (C : Entity_Id) return Boolean;
5571 -- Checks one component to see if it is independently accessible, and
5572 -- if so yields True, otherwise yields False if independent access
5573 -- cannot be guaranteed. This is a conservative routine, it only
5574 -- returns True if it knows for sure, it returns False if it knows
5575 -- there is a problem, or it cannot be sure there is no problem.
5577 procedure Reason_Bad_Component (C : Entity_Id);
5578 -- Outputs continuation message if a reason can be determined for
5579 -- the component C being bad.
5581 ----------------------
5582 -- Check_Array_Type --
5583 ----------------------
5585 procedure Check_Array_Type (Atyp : Entity_Id) is
5586 Ctyp : constant Entity_Id := Component_Type (Atyp);
5589 -- OK if no alignment clause, no pack, and no component size
5591 if not Has_Component_Size_Clause (Atyp)
5592 and then not Has_Alignment_Clause (Atyp)
5593 and then not Is_Packed (Atyp)
5598 -- Check actual component size
5600 if not Known_Component_Size (Atyp)
5601 or else not (Addressable (Component_Size (Atyp))
5602 and then Component_Size (Atyp) < 64)
5603 or else Component_Size (Atyp) mod Esize (Ctyp) /= 0
5607 -- Bad component size, check reason
5609 if Has_Component_Size_Clause (Atyp) then
5611 Get_Attribute_Definition_Clause
5612 (Atyp, Attribute_Component_Size);
5615 Error_Msg_Sloc := Sloc (P);
5616 Error_Msg_N ("\because of Component_Size clause#", N);
5621 if Is_Packed (Atyp) then
5622 P := Get_Rep_Pragma (Atyp, Name_Pack);
5625 Error_Msg_Sloc := Sloc (P);
5626 Error_Msg_N ("\because of pragma Pack#", N);
5631 -- No reason found, just return
5636 -- Array type is OK independence-wise
5639 end Check_Array_Type;
5641 ---------------------
5642 -- No_Independence --
5643 ---------------------
5645 procedure No_Independence is
5647 if Pragma_Name (N) = Name_Independent then
5649 ("independence cannot be guaranteed for&", N, E);
5652 ("independent components cannot be guaranteed for&", N, E);
5654 end No_Independence;
5660 function OK_Component (C : Entity_Id) return Boolean is
5661 Rec : constant Entity_Id := Scope (C);
5662 Ctyp : constant Entity_Id := Etype (C);
5665 -- OK if no component clause, no Pack, and no alignment clause
5667 if No (Component_Clause (C))
5668 and then not Is_Packed (Rec)
5669 and then not Has_Alignment_Clause (Rec)
5674 -- Here we look at the actual component layout. A component is
5675 -- addressable if its size is a multiple of the Esize of the
5676 -- component type, and its starting position in the record has
5677 -- appropriate alignment, and the record itself has appropriate
5678 -- alignment to guarantee the component alignment.
5680 -- Make sure sizes are static, always assume the worst for any
5681 -- cases where we cannot check static values.
5683 if not (Known_Static_Esize (C)
5684 and then Known_Static_Esize (Ctyp))
5689 -- Size of component must be addressable or greater than 64 bits
5690 -- and a multiple of bytes.
5692 if not Addressable (Esize (C))
5693 and then Esize (C) < Uint_64
5698 -- Check size is proper multiple
5700 if Esize (C) mod Esize (Ctyp) /= 0 then
5704 -- Check alignment of component is OK
5706 if not Known_Component_Bit_Offset (C)
5707 or else Component_Bit_Offset (C) < Uint_0
5708 or else Component_Bit_Offset (C) mod Esize (Ctyp) /= 0
5713 -- Check alignment of record type is OK
5715 if not Known_Alignment (Rec)
5716 or else (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
5721 -- All tests passed, component is addressable
5726 --------------------------
5727 -- Reason_Bad_Component --
5728 --------------------------
5730 procedure Reason_Bad_Component (C : Entity_Id) is
5731 Rec : constant Entity_Id := Scope (C);
5732 Ctyp : constant Entity_Id := Etype (C);
5735 -- If component clause present assume that's the problem
5737 if Present (Component_Clause (C)) then
5738 Error_Msg_Sloc := Sloc (Component_Clause (C));
5739 Error_Msg_N ("\because of Component_Clause#", N);
5743 -- If pragma Pack clause present, assume that's the problem
5745 if Is_Packed (Rec) then
5746 P := Get_Rep_Pragma (Rec, Name_Pack);
5749 Error_Msg_Sloc := Sloc (P);
5750 Error_Msg_N ("\because of pragma Pack#", N);
5755 -- See if record has bad alignment clause
5757 if Has_Alignment_Clause (Rec)
5758 and then Known_Alignment (Rec)
5759 and then (Alignment (Rec) * SU) mod Esize (Ctyp) /= 0
5761 P := Get_Attribute_Definition_Clause (Rec, Attribute_Alignment);
5764 Error_Msg_Sloc := Sloc (P);
5765 Error_Msg_N ("\because of Alignment clause#", N);
5769 -- Couldn't find a reason, so return without a message
5772 end Reason_Bad_Component;
5774 -- Start of processing for Validate_Independence
5777 for J in Independence_Checks.First .. Independence_Checks.Last loop
5778 N := Independence_Checks.Table (J).N;
5779 E := Independence_Checks.Table (J).E;
5780 IC := Pragma_Name (N) = Name_Independent_Components;
5782 -- Deal with component case
5784 if Ekind (E) = E_Discriminant or else Ekind (E) = E_Component then
5785 if not OK_Component (E) then
5787 Reason_Bad_Component (E);
5792 -- Deal with record with Independent_Components
5794 if IC and then Is_Record_Type (E) then
5795 Comp := First_Component_Or_Discriminant (E);
5796 while Present (Comp) loop
5797 if not OK_Component (Comp) then
5799 Reason_Bad_Component (Comp);
5803 Next_Component_Or_Discriminant (Comp);
5807 -- Deal with address clause case
5809 if Is_Object (E) then
5810 Addr := Address_Clause (E);
5812 if Present (Addr) then
5814 Error_Msg_Sloc := Sloc (Addr);
5815 Error_Msg_N ("\because of Address clause#", N);
5820 -- Deal with independent components for array type
5822 if IC and then Is_Array_Type (E) then
5823 Check_Array_Type (E);
5826 -- Deal with independent components for array object
5828 if IC and then Is_Object (E) and then Is_Array_Type (Etype (E)) then
5829 Check_Array_Type (Etype (E));
5834 end Validate_Independence;
5836 -----------------------------------
5837 -- Validate_Unchecked_Conversion --
5838 -----------------------------------
5840 procedure Validate_Unchecked_Conversion
5842 Act_Unit : Entity_Id)
5849 -- Obtain source and target types. Note that we call Ancestor_Subtype
5850 -- here because the processing for generic instantiation always makes
5851 -- subtypes, and we want the original frozen actual types.
5853 -- If we are dealing with private types, then do the check on their
5854 -- fully declared counterparts if the full declarations have been
5855 -- encountered (they don't have to be visible, but they must exist!)
5857 Source := Ancestor_Subtype (Etype (First_Formal (Act_Unit)));
5859 if Is_Private_Type (Source)
5860 and then Present (Underlying_Type (Source))
5862 Source := Underlying_Type (Source);
5865 Target := Ancestor_Subtype (Etype (Act_Unit));
5867 -- If either type is generic, the instantiation happens within a generic
5868 -- unit, and there is nothing to check. The proper check
5869 -- will happen when the enclosing generic is instantiated.
5871 if Is_Generic_Type (Source) or else Is_Generic_Type (Target) then
5875 if Is_Private_Type (Target)
5876 and then Present (Underlying_Type (Target))
5878 Target := Underlying_Type (Target);
5881 -- Source may be unconstrained array, but not target
5883 if Is_Array_Type (Target)
5884 and then not Is_Constrained (Target)
5887 ("unchecked conversion to unconstrained array not allowed", N);
5891 -- Warn if conversion between two different convention pointers
5893 if Is_Access_Type (Target)
5894 and then Is_Access_Type (Source)
5895 and then Convention (Target) /= Convention (Source)
5896 and then Warn_On_Unchecked_Conversion
5898 -- Give warnings for subprogram pointers only on most targets. The
5899 -- exception is VMS, where data pointers can have different lengths
5900 -- depending on the pointer convention.
5902 if Is_Access_Subprogram_Type (Target)
5903 or else Is_Access_Subprogram_Type (Source)
5904 or else OpenVMS_On_Target
5907 ("?conversion between pointers with different conventions!", N);
5911 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
5912 -- warning when compiling GNAT-related sources.
5914 if Warn_On_Unchecked_Conversion
5915 and then not In_Predefined_Unit (N)
5916 and then RTU_Loaded (Ada_Calendar)
5918 (Chars (Source) = Name_Time
5920 Chars (Target) = Name_Time)
5922 -- If Ada.Calendar is loaded and the name of one of the operands is
5923 -- Time, there is a good chance that this is Ada.Calendar.Time.
5926 Calendar_Time : constant Entity_Id :=
5927 Full_View (RTE (RO_CA_Time));
5929 pragma Assert (Present (Calendar_Time));
5931 if Source = Calendar_Time
5932 or else Target = Calendar_Time
5935 ("?representation of 'Time values may change between " &
5936 "'G'N'A'T versions", N);
5941 -- Make entry in unchecked conversion table for later processing by
5942 -- Validate_Unchecked_Conversions, which will check sizes and alignments
5943 -- (using values set by the back-end where possible). This is only done
5944 -- if the appropriate warning is active.
5946 if Warn_On_Unchecked_Conversion then
5947 Unchecked_Conversions.Append
5948 (New_Val => UC_Entry'
5953 -- If both sizes are known statically now, then back end annotation
5954 -- is not required to do a proper check but if either size is not
5955 -- known statically, then we need the annotation.
5957 if Known_Static_RM_Size (Source)
5958 and then Known_Static_RM_Size (Target)
5962 Back_Annotate_Rep_Info := True;
5966 -- If unchecked conversion to access type, and access type is declared
5967 -- in the same unit as the unchecked conversion, then set the
5968 -- No_Strict_Aliasing flag (no strict aliasing is implicit in this
5971 if Is_Access_Type (Target) and then
5972 In_Same_Source_Unit (Target, N)
5974 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
5977 -- Generate N_Validate_Unchecked_Conversion node for back end in
5978 -- case the back end needs to perform special validation checks.
5980 -- Shouldn't this be in Exp_Ch13, since the check only gets done
5981 -- if we have full expansion and the back end is called ???
5984 Make_Validate_Unchecked_Conversion (Sloc (N));
5985 Set_Source_Type (Vnode, Source);
5986 Set_Target_Type (Vnode, Target);
5988 -- If the unchecked conversion node is in a list, just insert before it.
5989 -- If not we have some strange case, not worth bothering about.
5991 if Is_List_Member (N) then
5992 Insert_After (N, Vnode);
5994 end Validate_Unchecked_Conversion;
5996 ------------------------------------
5997 -- Validate_Unchecked_Conversions --
5998 ------------------------------------
6000 procedure Validate_Unchecked_Conversions is
6002 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
6004 T : UC_Entry renames Unchecked_Conversions.Table (N);
6006 Eloc : constant Source_Ptr := T.Eloc;
6007 Source : constant Entity_Id := T.Source;
6008 Target : constant Entity_Id := T.Target;
6014 -- This validation check, which warns if we have unequal sizes for
6015 -- unchecked conversion, and thus potentially implementation
6016 -- dependent semantics, is one of the few occasions on which we
6017 -- use the official RM size instead of Esize. See description in
6018 -- Einfo "Handling of Type'Size Values" for details.
6020 if Serious_Errors_Detected = 0
6021 and then Known_Static_RM_Size (Source)
6022 and then Known_Static_RM_Size (Target)
6024 -- Don't do the check if warnings off for either type, note the
6025 -- deliberate use of OR here instead of OR ELSE to get the flag
6026 -- Warnings_Off_Used set for both types if appropriate.
6028 and then not (Has_Warnings_Off (Source)
6030 Has_Warnings_Off (Target))
6032 Source_Siz := RM_Size (Source);
6033 Target_Siz := RM_Size (Target);
6035 if Source_Siz /= Target_Siz then
6037 ("?types for unchecked conversion have different sizes!",
6040 if All_Errors_Mode then
6041 Error_Msg_Name_1 := Chars (Source);
6042 Error_Msg_Uint_1 := Source_Siz;
6043 Error_Msg_Name_2 := Chars (Target);
6044 Error_Msg_Uint_2 := Target_Siz;
6045 Error_Msg ("\size of % is ^, size of % is ^?", Eloc);
6047 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
6049 if Is_Discrete_Type (Source)
6050 and then Is_Discrete_Type (Target)
6052 if Source_Siz > Target_Siz then
6054 ("\?^ high order bits of source will be ignored!",
6057 elsif Is_Unsigned_Type (Source) then
6059 ("\?source will be extended with ^ high order " &
6060 "zero bits?!", Eloc);
6064 ("\?source will be extended with ^ high order " &
6069 elsif Source_Siz < Target_Siz then
6070 if Is_Discrete_Type (Target) then
6071 if Bytes_Big_Endian then
6073 ("\?target value will include ^ undefined " &
6078 ("\?target value will include ^ undefined " &
6085 ("\?^ trailing bits of target value will be " &
6086 "undefined!", Eloc);
6089 else pragma Assert (Source_Siz > Target_Siz);
6091 ("\?^ trailing bits of source will be ignored!",
6098 -- If both types are access types, we need to check the alignment.
6099 -- If the alignment of both is specified, we can do it here.
6101 if Serious_Errors_Detected = 0
6102 and then Ekind (Source) in Access_Kind
6103 and then Ekind (Target) in Access_Kind
6104 and then Target_Strict_Alignment
6105 and then Present (Designated_Type (Source))
6106 and then Present (Designated_Type (Target))
6109 D_Source : constant Entity_Id := Designated_Type (Source);
6110 D_Target : constant Entity_Id := Designated_Type (Target);
6113 if Known_Alignment (D_Source)
6114 and then Known_Alignment (D_Target)
6117 Source_Align : constant Uint := Alignment (D_Source);
6118 Target_Align : constant Uint := Alignment (D_Target);
6121 if Source_Align < Target_Align
6122 and then not Is_Tagged_Type (D_Source)
6124 -- Suppress warning if warnings suppressed on either
6125 -- type or either designated type. Note the use of
6126 -- OR here instead of OR ELSE. That is intentional,
6127 -- we would like to set flag Warnings_Off_Used in
6128 -- all types for which warnings are suppressed.
6130 and then not (Has_Warnings_Off (D_Source)
6132 Has_Warnings_Off (D_Target)
6134 Has_Warnings_Off (Source)
6136 Has_Warnings_Off (Target))
6138 Error_Msg_Uint_1 := Target_Align;
6139 Error_Msg_Uint_2 := Source_Align;
6140 Error_Msg_Node_1 := D_Target;
6141 Error_Msg_Node_2 := D_Source;
6143 ("?alignment of & (^) is stricter than " &
6144 "alignment of & (^)!", Eloc);
6146 ("\?resulting access value may have invalid " &
6147 "alignment!", Eloc);
6155 end Validate_Unchecked_Conversions;