1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Atree
; use Atree
;
27 with Checks
; use Checks
;
28 with Einfo
; use Einfo
;
29 with Errout
; use Errout
;
30 with Exp_Tss
; use Exp_Tss
;
31 with Exp_Util
; use Exp_Util
;
32 with Layout
; use Layout
;
34 with Lib
.Xref
; use Lib
.Xref
;
35 with Namet
; use Namet
;
36 with Nlists
; use Nlists
;
37 with Nmake
; use Nmake
;
39 with Restrict
; use Restrict
;
40 with Rident
; use Rident
;
41 with Rtsfind
; use Rtsfind
;
43 with Sem_Ch8
; use Sem_Ch8
;
44 with Sem_Eval
; use Sem_Eval
;
45 with Sem_Res
; use Sem_Res
;
46 with Sem_Type
; use Sem_Type
;
47 with Sem_Util
; use Sem_Util
;
48 with Sem_Warn
; use Sem_Warn
;
49 with Snames
; use Snames
;
50 with Stand
; use Stand
;
51 with Sinfo
; use Sinfo
;
53 with Targparm
; use Targparm
;
54 with Ttypes
; use Ttypes
;
55 with Tbuild
; use Tbuild
;
56 with Urealp
; use Urealp
;
58 with GNAT
.Heap_Sort_G
;
60 package body Sem_Ch13
is
62 SSU
: constant Pos
:= System_Storage_Unit
;
63 -- Convenient short hand for commonly used constant
65 -----------------------
66 -- Local Subprograms --
67 -----------------------
69 procedure Alignment_Check_For_Esize_Change
(Typ
: Entity_Id
);
70 -- This routine is called after setting the Esize of type entity Typ.
71 -- The purpose is to deal with the situation where an aligment has been
72 -- inherited from a derived type that is no longer appropriate for the
73 -- new Esize value. In this case, we reset the Alignment to unknown.
75 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
);
76 -- Given two entities for record components or discriminants, checks
77 -- if they hav overlapping component clauses and issues errors if so.
79 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
;
80 -- Given the expression for an alignment value, returns the corresponding
81 -- Uint value. If the value is inappropriate, then error messages are
82 -- posted as required, and a value of No_Uint is returned.
84 function Is_Operational_Item
(N
: Node_Id
) return Boolean;
85 -- A specification for a stream attribute is allowed before the full
86 -- type is declared, as explained in AI-00137 and the corrigendum.
87 -- Attributes that do not specify a representation characteristic are
88 -- operational attributes.
90 function Address_Aliased_Entity
(N
: Node_Id
) return Entity_Id
;
91 -- If expression N is of the form E'Address, return E
93 procedure New_Stream_Subprogram
98 -- Create a subprogram renaming of a given stream attribute to the
99 -- designated subprogram and then in the tagged case, provide this as a
100 -- primitive operation, or in the non-tagged case make an appropriate TSS
101 -- entry. This is more properly an expansion activity than just semantics,
102 -- but the presence of user-defined stream functions for limited types is a
103 -- legality check, which is why this takes place here rather than in
104 -- exp_ch13, where it was previously. Nam indicates the name of the TSS
105 -- function to be generated.
107 -- To avoid elaboration anomalies with freeze nodes, for untagged types
108 -- we generate both a subprogram declaration and a subprogram renaming
109 -- declaration, so that the attribute specification is handled as a
110 -- renaming_as_body. For tagged types, the specification is one of the
113 ----------------------------------------------
114 -- Table for Validate_Unchecked_Conversions --
115 ----------------------------------------------
117 -- The following table collects unchecked conversions for validation.
118 -- Entries are made by Validate_Unchecked_Conversion and then the
119 -- call to Validate_Unchecked_Conversions does the actual error
120 -- checking and posting of warnings. The reason for this delayed
121 -- processing is to take advantage of back-annotations of size and
122 -- alignment values peformed by the back end.
124 type UC_Entry
is record
125 Enode
: Node_Id
; -- node used for posting warnings
126 Source
: Entity_Id
; -- source type for unchecked conversion
127 Target
: Entity_Id
; -- target type for unchecked conversion
130 package Unchecked_Conversions
is new Table
.Table
(
131 Table_Component_Type
=> UC_Entry
,
132 Table_Index_Type
=> Int
,
133 Table_Low_Bound
=> 1,
135 Table_Increment
=> 200,
136 Table_Name
=> "Unchecked_Conversions");
138 ----------------------------------------
139 -- Table for Validate_Address_Clauses --
140 ----------------------------------------
142 -- If an address clause has the form
144 -- for X'Address use Expr
146 -- where Expr is of the form Y'Address or recursively is a reference
147 -- to a constant of either of these forms, and X and Y are entities of
148 -- objects, then if Y has a smaller alignment than X, that merits a
149 -- warning about possible bad alignment. The following table collects
150 -- address clauses of this kind. We put these in a table so that they
151 -- can be checked after the back end has completed annotation of the
152 -- alignments of objects, since we can catch more cases that way.
154 type Address_Clause_Check_Record
is record
156 -- The address clause
159 -- The entity of the object overlaying Y
162 -- The entity of the object being overlaid
165 package Address_Clause_Checks
is new Table
.Table
(
166 Table_Component_Type
=> Address_Clause_Check_Record
,
167 Table_Index_Type
=> Int
,
168 Table_Low_Bound
=> 1,
170 Table_Increment
=> 200,
171 Table_Name
=> "Address_Clause_Checks");
173 ----------------------------
174 -- Address_Aliased_Entity --
175 ----------------------------
177 function Address_Aliased_Entity
(N
: Node_Id
) return Entity_Id
is
179 if Nkind
(N
) = N_Attribute_Reference
180 and then Attribute_Name
(N
) = Name_Address
183 Nam
: Node_Id
:= Prefix
(N
);
186 or else Nkind
(Nam
) = N_Selected_Component
187 or else Nkind
(Nam
) = N_Indexed_Component
192 if Is_Entity_Name
(Nam
) then
199 end Address_Aliased_Entity
;
201 -----------------------------------------
202 -- Adjust_Record_For_Reverse_Bit_Order --
203 -----------------------------------------
205 procedure Adjust_Record_For_Reverse_Bit_Order
(R
: Entity_Id
) is
206 Max_Machine_Scalar_Size
: constant Uint
:=
208 (Standard_Long_Long_Integer_Size
);
209 -- We use this as the maximum machine scalar size in the sense of AI-133
213 SSU
: constant Uint
:= UI_From_Int
(System_Storage_Unit
);
216 -- This first loop through components does two things. First it deals
217 -- with the case of components with component clauses whose length is
218 -- greater than the maximum machine scalar size (either accepting them
219 -- or rejecting as needed). Second, it counts the number of components
220 -- with component clauses whose length does not exceed this maximum for
224 Comp
:= First_Component_Or_Discriminant
(R
);
225 while Present
(Comp
) loop
227 CC
: constant Node_Id
:= Component_Clause
(Comp
);
228 Fbit
: constant Uint
:= Static_Integer
(First_Bit
(CC
));
233 -- Case of component with size > max machine scalar
235 if Esize
(Comp
) > Max_Machine_Scalar_Size
then
237 -- Must begin on byte boundary
239 if Fbit
mod SSU
/= 0 then
241 ("illegal first bit value for reverse bit order",
243 Error_Msg_Uint_1
:= SSU
;
244 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
247 ("\must be a multiple of ^ if size greater than ^",
250 -- Must end on byte boundary
252 elsif Esize
(Comp
) mod SSU
/= 0 then
254 ("illegal last bit value for reverse bit order",
256 Error_Msg_Uint_1
:= SSU
;
257 Error_Msg_Uint_2
:= Max_Machine_Scalar_Size
;
260 ("\must be a multiple of ^ if size greater than ^",
263 -- OK, give warning if enabled
265 elsif Warn_On_Reverse_Bit_Order
then
267 ("multi-byte field specified with non-standard"
268 & " Bit_Order?", CC
);
270 if Bytes_Big_Endian
then
272 ("\bytes are not reversed "
273 & "(component is big-endian)?", CC
);
276 ("\bytes are not reversed "
277 & "(component is little-endian)?", CC
);
281 -- Case where size is not greater than max machine scalar.
282 -- For now, we just count these.
285 Num_CC
:= Num_CC
+ 1;
290 Next_Component_Or_Discriminant
(Comp
);
293 -- We need to sort the component clauses on the basis of the Position
294 -- values in the clause, so we can group clauses with the same Position.
295 -- together to determine the relevant machine scalar size.
298 Comps
: array (0 .. Num_CC
) of Entity_Id
;
299 -- Array to collect component and discrimninant entities. The data
300 -- starts at index 1, the 0'th entry is for the sort routine.
302 function CP_Lt
(Op1
, Op2
: Natural) return Boolean;
303 -- Compare routine for Sort
305 procedure CP_Move
(From
: Natural; To
: Natural);
306 -- Move routine for Sort
308 package Sorting
is new GNAT
.Heap_Sort_G
(CP_Move
, CP_Lt
);
312 -- Start and stop positions in component list of set of components
313 -- with the same starting position (that constitute components in
314 -- a single machine scalar).
317 -- Maximum last bit value of any component in this set
320 -- Corresponding machine scalar size
326 function CP_Lt
(Op1
, Op2
: Natural) return Boolean is
328 return Position
(Component_Clause
(Comps
(Op1
))) <
329 Position
(Component_Clause
(Comps
(Op2
)));
336 procedure CP_Move
(From
: Natural; To
: Natural) is
338 Comps
(To
) := Comps
(From
);
342 -- Collect the component clauses
345 Comp
:= First_Component_Or_Discriminant
(R
);
346 while Present
(Comp
) loop
347 if Present
(Component_Clause
(Comp
))
348 and then Esize
(Comp
) <= Max_Machine_Scalar_Size
350 Num_CC
:= Num_CC
+ 1;
351 Comps
(Num_CC
) := Comp
;
354 Next_Component_Or_Discriminant
(Comp
);
357 -- Sort by ascending position number
359 Sorting
.Sort
(Num_CC
);
361 -- We now have all the components whose size does not exceed the max
362 -- machine scalar value, sorted by starting position. In this loop
363 -- we gather groups of clauses starting at the same position, to
364 -- process them in accordance with Ada 2005 AI-133.
367 while Stop
< Num_CC
loop
371 Static_Integer
(Last_Bit
(Component_Clause
(Comps
(Start
))));
372 while Stop
< Num_CC
loop
374 (Position
(Component_Clause
(Comps
(Stop
+ 1)))) =
376 (Position
(Component_Clause
(Comps
(Stop
))))
383 (Last_Bit
(Component_Clause
(Comps
(Stop
)))));
389 -- Now we have a group of component clauses from Start to Stop
390 -- whose positions are identical, and MaxL is the maximum last bit
391 -- value of any of these components.
393 -- We need to determine the corresponding machine scalar size.
394 -- This loop assumes that machine scalar sizes are even, and that
395 -- each possible machine scalar has twice as many bits as the
398 MSS
:= Max_Machine_Scalar_Size
;
400 and then (MSS
/ 2) >= SSU
401 and then (MSS
/ 2) > MaxL
406 -- Here is where we fix up the Component_Bit_Offset value to
407 -- account for the reverse bit order. Some examples of what needs
408 -- to be done for the case of a machine scalar size of 8 are:
410 -- First_Bit .. Last_Bit Component_Bit_Offset
422 -- The general rule is that the first bit is is obtained by
423 -- subtracting the old ending bit from machine scalar size - 1.
425 for C
in Start
.. Stop
loop
427 Comp
: constant Entity_Id
:= Comps
(C
);
428 CC
: constant Node_Id
:= Component_Clause
(Comp
);
429 LB
: constant Uint
:= Static_Integer
(Last_Bit
(CC
));
430 NFB
: constant Uint
:= MSS
- Uint_1
- LB
;
431 NLB
: constant Uint
:= NFB
+ Esize
(Comp
) - 1;
432 Pos
: constant Uint
:= Static_Integer
(Position
(CC
));
435 if Warn_On_Reverse_Bit_Order
then
436 Error_Msg_Uint_1
:= MSS
;
438 ("?reverse bit order in machine " &
439 "scalar of length^", First_Bit
(CC
));
440 Error_Msg_Uint_1
:= NFB
;
441 Error_Msg_Uint_2
:= NLB
;
443 if Bytes_Big_Endian
then
445 ("?\big-endian range for component & is ^ .. ^",
446 First_Bit
(CC
), Comp
);
449 ("?\little-endian range for component & is ^ .. ^",
450 First_Bit
(CC
), Comp
);
454 Set_Component_Bit_Offset
(Comp
, Pos
* SSU
+ NFB
);
455 Set_Normalized_First_Bit
(Comp
, NFB
mod SSU
);
460 end Adjust_Record_For_Reverse_Bit_Order
;
462 --------------------------------------
463 -- Alignment_Check_For_Esize_Change --
464 --------------------------------------
466 procedure Alignment_Check_For_Esize_Change
(Typ
: Entity_Id
) is
468 -- If the alignment is known, and not set by a rep clause, and is
469 -- inconsistent with the size being set, then reset it to unknown,
470 -- we assume in this case that the size overrides the inherited
471 -- alignment, and that the alignment must be recomputed.
473 if Known_Alignment
(Typ
)
474 and then not Has_Alignment_Clause
(Typ
)
475 and then Esize
(Typ
) mod (Alignment
(Typ
) * SSU
) /= 0
477 Init_Alignment
(Typ
);
479 end Alignment_Check_For_Esize_Change
;
481 -----------------------
482 -- Analyze_At_Clause --
483 -----------------------
485 -- An at clause is replaced by the corresponding Address attribute
486 -- definition clause that is the preferred approach in Ada 95.
488 procedure Analyze_At_Clause
(N
: Node_Id
) is
490 Check_Restriction
(No_Obsolescent_Features
, N
);
492 if Warn_On_Obsolescent_Feature
then
494 ("at clause is an obsolescent feature (RM J.7(2))?", N
);
496 ("\use address attribute definition clause instead?", N
);
500 Make_Attribute_Definition_Clause
(Sloc
(N
),
501 Name
=> Identifier
(N
),
502 Chars
=> Name_Address
,
503 Expression
=> Expression
(N
)));
504 Analyze_Attribute_Definition_Clause
(N
);
505 end Analyze_At_Clause
;
507 -----------------------------------------
508 -- Analyze_Attribute_Definition_Clause --
509 -----------------------------------------
511 procedure Analyze_Attribute_Definition_Clause
(N
: Node_Id
) is
512 Loc
: constant Source_Ptr
:= Sloc
(N
);
513 Nam
: constant Node_Id
:= Name
(N
);
514 Attr
: constant Name_Id
:= Chars
(N
);
515 Expr
: constant Node_Id
:= Expression
(N
);
516 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Attr
);
520 FOnly
: Boolean := False;
521 -- Reset to True for subtype specific attribute (Alignment, Size)
522 -- and for stream attributes, i.e. those cases where in the call
523 -- to Rep_Item_Too_Late, FOnly is set True so that only the freezing
524 -- rules are checked. Note that the case of stream attributes is not
525 -- clear from the RM, but see AI95-00137. Also, the RM seems to
526 -- disallow Storage_Size for derived task types, but that is also
527 -- clearly unintentional.
529 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
);
530 -- Common processing for 'Read, 'Write, 'Input and 'Output attribute
531 -- definition clauses.
533 procedure Analyze_Stream_TSS_Definition
(TSS_Nam
: TSS_Name_Type
) is
534 Subp
: Entity_Id
:= Empty
;
539 Is_Read
: constant Boolean := (TSS_Nam
= TSS_Stream_Read
);
541 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean;
542 -- Return true if the entity is a subprogram with an appropriate
543 -- profile for the attribute being defined.
545 ----------------------
546 -- Has_Good_Profile --
547 ----------------------
549 function Has_Good_Profile
(Subp
: Entity_Id
) return Boolean is
551 Is_Function
: constant Boolean := (TSS_Nam
= TSS_Stream_Input
);
552 Expected_Ekind
: constant array (Boolean) of Entity_Kind
:=
553 (False => E_Procedure
, True => E_Function
);
557 if Ekind
(Subp
) /= Expected_Ekind
(Is_Function
) then
561 F
:= First_Formal
(Subp
);
564 or else Ekind
(Etype
(F
)) /= E_Anonymous_Access_Type
565 or else Designated_Type
(Etype
(F
)) /=
566 Class_Wide_Type
(RTE
(RE_Root_Stream_Type
))
571 if not Is_Function
then
575 Expected_Mode
: constant array (Boolean) of Entity_Kind
:=
576 (False => E_In_Parameter
,
577 True => E_Out_Parameter
);
579 if Parameter_Mode
(F
) /= Expected_Mode
(Is_Read
) then
590 return Base_Type
(Typ
) = Base_Type
(Ent
)
591 and then No
(Next_Formal
(F
));
593 end Has_Good_Profile
;
595 -- Start of processing for Analyze_Stream_TSS_Definition
600 if not Is_Type
(U_Ent
) then
601 Error_Msg_N
("local name must be a subtype", Nam
);
605 Pnam
:= TSS
(Base_Type
(U_Ent
), TSS_Nam
);
607 -- If Pnam is present, it can be either inherited from an ancestor
608 -- type (in which case it is legal to redefine it for this type), or
609 -- be a previous definition of the attribute for the same type (in
610 -- which case it is illegal).
612 -- In the first case, it will have been analyzed already, and we
613 -- can check that its profile does not match the expected profile
614 -- for a stream attribute of U_Ent. In the second case, either Pnam
615 -- has been analyzed (and has the expected profile), or it has not
616 -- been analyzed yet (case of a type that has not been frozen yet
617 -- and for which the stream attribute has been set using Set_TSS).
620 and then (No
(First_Entity
(Pnam
)) or else Has_Good_Profile
(Pnam
))
622 Error_Msg_Sloc
:= Sloc
(Pnam
);
623 Error_Msg_Name_1
:= Attr
;
624 Error_Msg_N
("% attribute already defined #", Nam
);
630 if Is_Entity_Name
(Expr
) then
631 if not Is_Overloaded
(Expr
) then
632 if Has_Good_Profile
(Entity
(Expr
)) then
633 Subp
:= Entity
(Expr
);
637 Get_First_Interp
(Expr
, I
, It
);
638 while Present
(It
.Nam
) loop
639 if Has_Good_Profile
(It
.Nam
) then
644 Get_Next_Interp
(I
, It
);
649 if Present
(Subp
) then
650 if Is_Abstract_Subprogram
(Subp
) then
651 Error_Msg_N
("stream subprogram must not be abstract", Expr
);
655 Set_Entity
(Expr
, Subp
);
656 Set_Etype
(Expr
, Etype
(Subp
));
658 New_Stream_Subprogram
(N
, U_Ent
, Subp
, TSS_Nam
);
661 Error_Msg_Name_1
:= Attr
;
662 Error_Msg_N
("incorrect expression for% attribute", Expr
);
664 end Analyze_Stream_TSS_Definition
;
666 -- Start of processing for Analyze_Attribute_Definition_Clause
669 if Ignore_Rep_Clauses
then
670 Rewrite
(N
, Make_Null_Statement
(Sloc
(N
)));
677 if Rep_Item_Too_Early
(Ent
, N
) then
681 -- Rep clause applies to full view of incomplete type or private type if
682 -- we have one (if not, this is a premature use of the type). However,
683 -- certain semantic checks need to be done on the specified entity (i.e.
684 -- the private view), so we save it in Ent.
686 if Is_Private_Type
(Ent
)
687 and then Is_Derived_Type
(Ent
)
688 and then not Is_Tagged_Type
(Ent
)
689 and then No
(Full_View
(Ent
))
691 -- If this is a private type whose completion is a derivation from
692 -- another private type, there is no full view, and the attribute
693 -- belongs to the type itself, not its underlying parent.
697 elsif Ekind
(Ent
) = E_Incomplete_Type
then
699 -- The attribute applies to the full view, set the entity of the
700 -- attribute definition accordingly.
702 Ent
:= Underlying_Type
(Ent
);
704 Set_Entity
(Nam
, Ent
);
707 U_Ent
:= Underlying_Type
(Ent
);
710 -- Complete other routine error checks
712 if Etype
(Nam
) = Any_Type
then
715 elsif Scope
(Ent
) /= Current_Scope
then
716 Error_Msg_N
("entity must be declared in this scope", Nam
);
719 elsif No
(U_Ent
) then
722 elsif Is_Type
(U_Ent
)
723 and then not Is_First_Subtype
(U_Ent
)
724 and then Id
/= Attribute_Object_Size
725 and then Id
/= Attribute_Value_Size
726 and then not From_At_Mod
(N
)
728 Error_Msg_N
("cannot specify attribute for subtype", Nam
);
732 -- Switch on particular attribute
740 -- Address attribute definition clause
742 when Attribute_Address
=> Address
: begin
743 Analyze_And_Resolve
(Expr
, RTE
(RE_Address
));
745 if Present
(Address_Clause
(U_Ent
)) then
746 Error_Msg_N
("address already given for &", Nam
);
748 -- Case of address clause for subprogram
750 elsif Is_Subprogram
(U_Ent
) then
751 if Has_Homonym
(U_Ent
) then
753 ("address clause cannot be given " &
754 "for overloaded subprogram",
759 -- For subprograms, all address clauses are permitted, and we
760 -- mark the subprogram as having a deferred freeze so that Gigi
761 -- will not elaborate it too soon.
763 -- Above needs more comments, what is too soon about???
765 Set_Has_Delayed_Freeze
(U_Ent
);
767 -- Case of address clause for entry
769 elsif Ekind
(U_Ent
) = E_Entry
then
770 if Nkind
(Parent
(N
)) = N_Task_Body
then
772 ("entry address must be specified in task spec", Nam
);
776 -- For entries, we require a constant address
778 Check_Constant_Address_Clause
(Expr
, U_Ent
);
780 -- Special checks for task types
782 if Is_Task_Type
(Scope
(U_Ent
))
783 and then Comes_From_Source
(Scope
(U_Ent
))
786 ("?entry address declared for entry in task type", N
);
788 ("\?only one task can be declared of this type", N
);
791 -- Entry address clauses are obsolescent
793 Check_Restriction
(No_Obsolescent_Features
, N
);
795 if Warn_On_Obsolescent_Feature
then
797 ("attaching interrupt to task entry is an " &
798 "obsolescent feature (RM J.7.1)?", N
);
800 ("\use interrupt procedure instead?", N
);
803 -- Case of an address clause for a controlled object which we
804 -- consider to be erroneous.
806 elsif Is_Controlled
(Etype
(U_Ent
))
807 or else Has_Controlled_Component
(Etype
(U_Ent
))
810 ("?controlled object& must not be overlaid", Nam
, U_Ent
);
812 ("\?Program_Error will be raised at run time", Nam
);
813 Insert_Action
(Declaration_Node
(U_Ent
),
814 Make_Raise_Program_Error
(Loc
,
815 Reason
=> PE_Overlaid_Controlled_Object
));
818 -- Case of address clause for a (non-controlled) object
821 Ekind
(U_Ent
) = E_Variable
823 Ekind
(U_Ent
) = E_Constant
826 Expr
: constant Node_Id
:= Expression
(N
);
827 Aent
: constant Entity_Id
:= Address_Aliased_Entity
(Expr
);
828 Ent_Y
: constant Entity_Id
:= Find_Overlaid_Object
(N
);
831 -- Exported variables cannot have an address clause,
832 -- because this cancels the effect of the pragma Export
834 if Is_Exported
(U_Ent
) then
836 ("cannot export object with address clause", Nam
);
839 -- Overlaying controlled objects is erroneous
842 and then (Has_Controlled_Component
(Etype
(Aent
))
843 or else Is_Controlled
(Etype
(Aent
)))
846 ("?cannot overlay with controlled object", Expr
);
848 ("\?Program_Error will be raised at run time", Expr
);
849 Insert_Action
(Declaration_Node
(U_Ent
),
850 Make_Raise_Program_Error
(Loc
,
851 Reason
=> PE_Overlaid_Controlled_Object
));
855 and then Ekind
(U_Ent
) = E_Constant
856 and then Ekind
(Aent
) /= E_Constant
858 Error_Msg_N
("constant overlays a variable?", Expr
);
860 elsif Present
(Renamed_Object
(U_Ent
)) then
862 ("address clause not allowed"
863 & " for a renaming declaration (RM 13.1(6))", Nam
);
866 -- Imported variables can have an address clause, but then
867 -- the import is pretty meaningless except to suppress
868 -- initializations, so we do not need such variables to
869 -- be statically allocated (and in fact it causes trouble
870 -- if the address clause is a local value).
872 elsif Is_Imported
(U_Ent
) then
873 Set_Is_Statically_Allocated
(U_Ent
, False);
876 -- We mark a possible modification of a variable with an
877 -- address clause, since it is likely aliasing is occurring.
879 Note_Possible_Modification
(Nam
);
881 -- Here we are checking for explicit overlap of one variable
882 -- by another, and if we find this then mark the overlapped
883 -- variable as also being volatile to prevent unwanted
886 if Present
(Ent_Y
) then
887 Set_Treat_As_Volatile
(Ent_Y
);
890 -- Legality checks on the address clause for initialized
891 -- objects is deferred until the freeze point, because
892 -- a subsequent pragma might indicate that the object is
893 -- imported and thus not initialized.
895 Set_Has_Delayed_Freeze
(U_Ent
);
897 if Is_Exported
(U_Ent
) then
899 ("& cannot be exported if an address clause is given",
902 ("\define and export a variable " &
903 "that holds its address instead",
907 -- Entity has delayed freeze, so we will generate an
908 -- alignment check at the freeze point unless suppressed.
910 if not Range_Checks_Suppressed
(U_Ent
)
911 and then not Alignment_Checks_Suppressed
(U_Ent
)
913 Set_Check_Address_Alignment
(N
);
916 -- Kill the size check code, since we are not allocating
917 -- the variable, it is somewhere else.
919 Kill_Size_Check_Code
(U_Ent
);
922 -- If the address clause is of the form:
924 -- for X'Address use Y'Address
928 -- Const : constant Address := Y'Address;
930 -- for X'Address use Const;
932 -- then we make an entry in the table for checking the size and
933 -- alignment of the overlaying variable. We defer this check
934 -- till after code generation to take full advantage of the
935 -- annotation done by the back end. This entry is only made if
936 -- we have not already posted a warning about size/alignment
937 -- (some warnings of this type are posted in Checks).
939 if Address_Clause_Overlay_Warnings
then
941 Ent_X
: Entity_Id
:= Empty
;
942 Ent_Y
: Entity_Id
:= Empty
;
945 Ent_Y
:= Find_Overlaid_Object
(N
);
947 if Present
(Ent_Y
) and then Is_Entity_Name
(Name
(N
)) then
948 Ent_X
:= Entity
(Name
(N
));
949 Address_Clause_Checks
.Append
((N
, Ent_X
, Ent_Y
));
954 -- Not a valid entity for an address clause
957 Error_Msg_N
("address cannot be given for &", Nam
);
965 -- Alignment attribute definition clause
967 when Attribute_Alignment
=> Alignment_Block
: declare
968 Align
: constant Uint
:= Get_Alignment_Value
(Expr
);
973 if not Is_Type
(U_Ent
)
974 and then Ekind
(U_Ent
) /= E_Variable
975 and then Ekind
(U_Ent
) /= E_Constant
977 Error_Msg_N
("alignment cannot be given for &", Nam
);
979 elsif Has_Alignment_Clause
(U_Ent
) then
980 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
981 Error_Msg_N
("alignment clause previously given#", N
);
983 elsif Align
/= No_Uint
then
984 Set_Has_Alignment_Clause
(U_Ent
);
985 Set_Alignment
(U_Ent
, Align
);
993 -- Bit_Order attribute definition clause
995 when Attribute_Bit_Order
=> Bit_Order
: declare
997 if not Is_Record_Type
(U_Ent
) then
999 ("Bit_Order can only be defined for record type", Nam
);
1002 Analyze_And_Resolve
(Expr
, RTE
(RE_Bit_Order
));
1004 if Etype
(Expr
) = Any_Type
then
1007 elsif not Is_Static_Expression
(Expr
) then
1008 Flag_Non_Static_Expr
1009 ("Bit_Order requires static expression!", Expr
);
1012 if (Expr_Value
(Expr
) = 0) /= Bytes_Big_Endian
then
1013 Set_Reverse_Bit_Order
(U_Ent
, True);
1019 --------------------
1020 -- Component_Size --
1021 --------------------
1023 -- Component_Size attribute definition clause
1025 when Attribute_Component_Size
=> Component_Size_Case
: declare
1026 Csize
: constant Uint
:= Static_Integer
(Expr
);
1029 New_Ctyp
: Entity_Id
;
1033 if not Is_Array_Type
(U_Ent
) then
1034 Error_Msg_N
("component size requires array type", Nam
);
1038 Btype
:= Base_Type
(U_Ent
);
1040 if Has_Component_Size_Clause
(Btype
) then
1042 ("component size clause for& previously given", Nam
);
1044 elsif Csize
/= No_Uint
then
1045 Check_Size
(Expr
, Component_Type
(Btype
), Csize
, Biased
);
1047 if Has_Aliased_Components
(Btype
)
1050 and then Csize
/= 16
1053 ("component size incorrect for aliased components", N
);
1057 -- For the biased case, build a declaration for a subtype
1058 -- that will be used to represent the biased subtype that
1059 -- reflects the biased representation of components. We need
1060 -- this subtype to get proper conversions on referencing
1061 -- elements of the array. Note that component size clauses
1062 -- are ignored in VM mode.
1064 if VM_Target
= No_VM
then
1067 Make_Defining_Identifier
(Loc
,
1069 New_External_Name
(Chars
(U_Ent
), 'C', 0, 'T'));
1072 Make_Subtype_Declaration
(Loc
,
1073 Defining_Identifier
=> New_Ctyp
,
1074 Subtype_Indication
=>
1075 New_Occurrence_Of
(Component_Type
(Btype
), Loc
));
1077 Set_Parent
(Decl
, N
);
1078 Analyze
(Decl
, Suppress
=> All_Checks
);
1080 Set_Has_Delayed_Freeze
(New_Ctyp
, False);
1081 Set_Esize
(New_Ctyp
, Csize
);
1082 Set_RM_Size
(New_Ctyp
, Csize
);
1083 Init_Alignment
(New_Ctyp
);
1084 Set_Has_Biased_Representation
(New_Ctyp
, True);
1085 Set_Is_Itype
(New_Ctyp
, True);
1086 Set_Associated_Node_For_Itype
(New_Ctyp
, U_Ent
);
1088 Set_Component_Type
(Btype
, New_Ctyp
);
1091 Set_Component_Size
(Btype
, Csize
);
1093 -- For VM case, we ignore component size clauses
1096 -- Give a warning unless we are in GNAT mode, in which case
1097 -- the warning is suppressed since it is not useful.
1099 if not GNAT_Mode
then
1101 ("?component size ignored in this configuration", N
);
1105 Set_Has_Component_Size_Clause
(Btype
, True);
1106 Set_Has_Non_Standard_Rep
(Btype
, True);
1108 end Component_Size_Case
;
1114 when Attribute_External_Tag
=> External_Tag
:
1116 if not Is_Tagged_Type
(U_Ent
) then
1117 Error_Msg_N
("should be a tagged type", Nam
);
1120 Analyze_And_Resolve
(Expr
, Standard_String
);
1122 if not Is_Static_Expression
(Expr
) then
1123 Flag_Non_Static_Expr
1124 ("static string required for tag name!", Nam
);
1127 if VM_Target
= No_VM
then
1128 Set_Has_External_Tag_Rep_Clause
(U_Ent
);
1129 elsif not Inspector_Mode
then
1130 Error_Msg_Name_1
:= Attr
;
1132 ("% attribute unsupported in this configuration", Nam
);
1135 if not Is_Library_Level_Entity
(U_Ent
) then
1137 ("?non-unique external tag supplied for &", N
, U_Ent
);
1139 ("?\same external tag applies to all subprogram calls", N
);
1141 ("?\corresponding internal tag cannot be obtained", N
);
1149 when Attribute_Input
=>
1150 Analyze_Stream_TSS_Definition
(TSS_Stream_Input
);
1151 Set_Has_Specified_Stream_Input
(Ent
);
1157 -- Machine radix attribute definition clause
1159 when Attribute_Machine_Radix
=> Machine_Radix
: declare
1160 Radix
: constant Uint
:= Static_Integer
(Expr
);
1163 if not Is_Decimal_Fixed_Point_Type
(U_Ent
) then
1164 Error_Msg_N
("decimal fixed-point type expected for &", Nam
);
1166 elsif Has_Machine_Radix_Clause
(U_Ent
) then
1167 Error_Msg_Sloc
:= Sloc
(Alignment_Clause
(U_Ent
));
1168 Error_Msg_N
("machine radix clause previously given#", N
);
1170 elsif Radix
/= No_Uint
then
1171 Set_Has_Machine_Radix_Clause
(U_Ent
);
1172 Set_Has_Non_Standard_Rep
(Base_Type
(U_Ent
));
1176 elsif Radix
= 10 then
1177 Set_Machine_Radix_10
(U_Ent
);
1179 Error_Msg_N
("machine radix value must be 2 or 10", Expr
);
1188 -- Object_Size attribute definition clause
1190 when Attribute_Object_Size
=> Object_Size
: declare
1191 Size
: constant Uint
:= Static_Integer
(Expr
);
1194 pragma Warnings
(Off
, Biased
);
1197 if not Is_Type
(U_Ent
) then
1198 Error_Msg_N
("Object_Size cannot be given for &", Nam
);
1200 elsif Has_Object_Size_Clause
(U_Ent
) then
1201 Error_Msg_N
("Object_Size already given for &", Nam
);
1204 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1212 UI_Mod
(Size
, 64) /= 0
1215 ("Object_Size must be 8, 16, 32, or multiple of 64",
1219 Set_Esize
(U_Ent
, Size
);
1220 Set_Has_Object_Size_Clause
(U_Ent
);
1221 Alignment_Check_For_Esize_Change
(U_Ent
);
1229 when Attribute_Output
=>
1230 Analyze_Stream_TSS_Definition
(TSS_Stream_Output
);
1231 Set_Has_Specified_Stream_Output
(Ent
);
1237 when Attribute_Read
=>
1238 Analyze_Stream_TSS_Definition
(TSS_Stream_Read
);
1239 Set_Has_Specified_Stream_Read
(Ent
);
1245 -- Size attribute definition clause
1247 when Attribute_Size
=> Size
: declare
1248 Size
: constant Uint
:= Static_Integer
(Expr
);
1255 if Has_Size_Clause
(U_Ent
) then
1256 Error_Msg_N
("size already given for &", Nam
);
1258 elsif not Is_Type
(U_Ent
)
1259 and then Ekind
(U_Ent
) /= E_Variable
1260 and then Ekind
(U_Ent
) /= E_Constant
1262 Error_Msg_N
("size cannot be given for &", Nam
);
1264 elsif Is_Array_Type
(U_Ent
)
1265 and then not Is_Constrained
(U_Ent
)
1268 ("size cannot be given for unconstrained array", Nam
);
1270 elsif Size
/= No_Uint
then
1271 if Is_Type
(U_Ent
) then
1274 Etyp
:= Etype
(U_Ent
);
1277 -- Check size, note that Gigi is in charge of checking that the
1278 -- size of an array or record type is OK. Also we do not check
1279 -- the size in the ordinary fixed-point case, since it is too
1280 -- early to do so (there may be subsequent small clause that
1281 -- affects the size). We can check the size if a small clause
1282 -- has already been given.
1284 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
)
1285 or else Has_Small_Clause
(U_Ent
)
1287 Check_Size
(Expr
, Etyp
, Size
, Biased
);
1288 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1291 -- For types set RM_Size and Esize if possible
1293 if Is_Type
(U_Ent
) then
1294 Set_RM_Size
(U_Ent
, Size
);
1296 -- For scalar types, increase Object_Size to power of 2, but
1297 -- not less than a storage unit in any case (i.e., normally
1298 -- this means it will be byte addressable).
1300 if Is_Scalar_Type
(U_Ent
) then
1301 if Size
<= System_Storage_Unit
then
1302 Init_Esize
(U_Ent
, System_Storage_Unit
);
1303 elsif Size
<= 16 then
1304 Init_Esize
(U_Ent
, 16);
1305 elsif Size
<= 32 then
1306 Init_Esize
(U_Ent
, 32);
1308 Set_Esize
(U_Ent
, (Size
+ 63) / 64 * 64);
1311 -- For all other types, object size = value size. The
1312 -- backend will adjust as needed.
1315 Set_Esize
(U_Ent
, Size
);
1318 Alignment_Check_For_Esize_Change
(U_Ent
);
1320 -- For objects, set Esize only
1323 if Is_Elementary_Type
(Etyp
) then
1324 if Size
/= System_Storage_Unit
1326 Size
/= System_Storage_Unit
* 2
1328 Size
/= System_Storage_Unit
* 4
1330 Size
/= System_Storage_Unit
* 8
1332 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
1333 Error_Msg_Uint_2
:= Error_Msg_Uint_1
* 8;
1335 ("size for primitive object must be a power of 2"
1336 & " in the range ^-^", N
);
1340 Set_Esize
(U_Ent
, Size
);
1343 Set_Has_Size_Clause
(U_Ent
);
1351 -- Small attribute definition clause
1353 when Attribute_Small
=> Small
: declare
1354 Implicit_Base
: constant Entity_Id
:= Base_Type
(U_Ent
);
1358 Analyze_And_Resolve
(Expr
, Any_Real
);
1360 if Etype
(Expr
) = Any_Type
then
1363 elsif not Is_Static_Expression
(Expr
) then
1364 Flag_Non_Static_Expr
1365 ("small requires static expression!", Expr
);
1369 Small
:= Expr_Value_R
(Expr
);
1371 if Small
<= Ureal_0
then
1372 Error_Msg_N
("small value must be greater than zero", Expr
);
1378 if not Is_Ordinary_Fixed_Point_Type
(U_Ent
) then
1380 ("small requires an ordinary fixed point type", Nam
);
1382 elsif Has_Small_Clause
(U_Ent
) then
1383 Error_Msg_N
("small already given for &", Nam
);
1385 elsif Small
> Delta_Value
(U_Ent
) then
1387 ("small value must not be greater then delta value", Nam
);
1390 Set_Small_Value
(U_Ent
, Small
);
1391 Set_Small_Value
(Implicit_Base
, Small
);
1392 Set_Has_Small_Clause
(U_Ent
);
1393 Set_Has_Small_Clause
(Implicit_Base
);
1394 Set_Has_Non_Standard_Rep
(Implicit_Base
);
1395 Set_Discrete_RM_Size
(U_Ent
);
1403 -- Storage_Pool attribute definition clause
1405 when Attribute_Storage_Pool
=> Storage_Pool
: declare
1410 if Ekind
(U_Ent
) = E_Access_Subprogram_Type
then
1412 ("storage pool cannot be given for access-to-subprogram type",
1416 elsif Ekind
(U_Ent
) /= E_Access_Type
1417 and then Ekind
(U_Ent
) /= E_General_Access_Type
1420 ("storage pool can only be given for access types", Nam
);
1423 elsif Is_Derived_Type
(U_Ent
) then
1425 ("storage pool cannot be given for a derived access type",
1428 elsif Has_Storage_Size_Clause
(U_Ent
) then
1429 Error_Msg_N
("storage size already given for &", Nam
);
1432 elsif Present
(Associated_Storage_Pool
(U_Ent
)) then
1433 Error_Msg_N
("storage pool already given for &", Nam
);
1438 (Expr
, Class_Wide_Type
(RTE
(RE_Root_Storage_Pool
)));
1440 if Nkind
(Expr
) = N_Type_Conversion
then
1441 T
:= Etype
(Expression
(Expr
));
1446 -- The Stack_Bounded_Pool is used internally for implementing
1447 -- access types with a Storage_Size. Since it only work
1448 -- properly when used on one specific type, we need to check
1449 -- that it is not highjacked improperly:
1450 -- type T is access Integer;
1451 -- for T'Storage_Size use n;
1452 -- type Q is access Float;
1453 -- for Q'Storage_Size use T'Storage_Size; -- incorrect
1455 if RTE_Available
(RE_Stack_Bounded_Pool
)
1456 and then Base_Type
(T
) = RTE
(RE_Stack_Bounded_Pool
)
1458 Error_Msg_N
("non-shareable internal Pool", Expr
);
1462 -- If the argument is a name that is not an entity name, then
1463 -- we construct a renaming operation to define an entity of
1464 -- type storage pool.
1466 if not Is_Entity_Name
(Expr
)
1467 and then Is_Object_Reference
(Expr
)
1470 Make_Defining_Identifier
(Loc
,
1471 Chars
=> New_Internal_Name
('P'));
1474 Rnode
: constant Node_Id
:=
1475 Make_Object_Renaming_Declaration
(Loc
,
1476 Defining_Identifier
=> Pool
,
1478 New_Occurrence_Of
(Etype
(Expr
), Loc
),
1482 Insert_Before
(N
, Rnode
);
1484 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1487 elsif Is_Entity_Name
(Expr
) then
1488 Pool
:= Entity
(Expr
);
1490 -- If pool is a renamed object, get original one. This can
1491 -- happen with an explicit renaming, and within instances.
1493 while Present
(Renamed_Object
(Pool
))
1494 and then Is_Entity_Name
(Renamed_Object
(Pool
))
1496 Pool
:= Entity
(Renamed_Object
(Pool
));
1499 if Present
(Renamed_Object
(Pool
))
1500 and then Nkind
(Renamed_Object
(Pool
)) = N_Type_Conversion
1501 and then Is_Entity_Name
(Expression
(Renamed_Object
(Pool
)))
1503 Pool
:= Entity
(Expression
(Renamed_Object
(Pool
)));
1506 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1508 elsif Nkind
(Expr
) = N_Type_Conversion
1509 and then Is_Entity_Name
(Expression
(Expr
))
1510 and then Nkind
(Original_Node
(Expr
)) = N_Attribute_Reference
1512 Pool
:= Entity
(Expression
(Expr
));
1513 Set_Associated_Storage_Pool
(U_Ent
, Pool
);
1516 Error_Msg_N
("incorrect reference to a Storage Pool", Expr
);
1525 -- Storage_Size attribute definition clause
1527 when Attribute_Storage_Size
=> Storage_Size
: declare
1528 Btype
: constant Entity_Id
:= Base_Type
(U_Ent
);
1532 if Is_Task_Type
(U_Ent
) then
1533 Check_Restriction
(No_Obsolescent_Features
, N
);
1535 if Warn_On_Obsolescent_Feature
then
1537 ("storage size clause for task is an " &
1538 "obsolescent feature (RM J.9)?", N
);
1540 ("\use Storage_Size pragma instead?", N
);
1546 if not Is_Access_Type
(U_Ent
)
1547 and then Ekind
(U_Ent
) /= E_Task_Type
1549 Error_Msg_N
("storage size cannot be given for &", Nam
);
1551 elsif Is_Access_Type
(U_Ent
) and Is_Derived_Type
(U_Ent
) then
1553 ("storage size cannot be given for a derived access type",
1556 elsif Has_Storage_Size_Clause
(Btype
) then
1557 Error_Msg_N
("storage size already given for &", Nam
);
1560 Analyze_And_Resolve
(Expr
, Any_Integer
);
1562 if Is_Access_Type
(U_Ent
) then
1563 if Present
(Associated_Storage_Pool
(U_Ent
)) then
1564 Error_Msg_N
("storage pool already given for &", Nam
);
1568 if Compile_Time_Known_Value
(Expr
)
1569 and then Expr_Value
(Expr
) = 0
1571 Set_No_Pool_Assigned
(Btype
);
1574 else -- Is_Task_Type (U_Ent)
1575 Sprag
:= Get_Rep_Pragma
(Btype
, Name_Storage_Size
);
1577 if Present
(Sprag
) then
1578 Error_Msg_Sloc
:= Sloc
(Sprag
);
1580 ("Storage_Size already specified#", Nam
);
1585 Set_Has_Storage_Size_Clause
(Btype
);
1593 when Attribute_Stream_Size
=> Stream_Size
: declare
1594 Size
: constant Uint
:= Static_Integer
(Expr
);
1597 if Ada_Version
<= Ada_95
then
1598 Check_Restriction
(No_Implementation_Attributes
, N
);
1601 if Has_Stream_Size_Clause
(U_Ent
) then
1602 Error_Msg_N
("Stream_Size already given for &", Nam
);
1604 elsif Is_Elementary_Type
(U_Ent
) then
1605 if Size
/= System_Storage_Unit
1607 Size
/= System_Storage_Unit
* 2
1609 Size
/= System_Storage_Unit
* 4
1611 Size
/= System_Storage_Unit
* 8
1613 Error_Msg_Uint_1
:= UI_From_Int
(System_Storage_Unit
);
1615 ("stream size for elementary type must be a"
1616 & " power of 2 and at least ^", N
);
1618 elsif RM_Size
(U_Ent
) > Size
then
1619 Error_Msg_Uint_1
:= RM_Size
(U_Ent
);
1621 ("stream size for elementary type must be a"
1622 & " power of 2 and at least ^", N
);
1625 Set_Has_Stream_Size_Clause
(U_Ent
);
1628 Error_Msg_N
("Stream_Size cannot be given for &", Nam
);
1636 -- Value_Size attribute definition clause
1638 when Attribute_Value_Size
=> Value_Size
: declare
1639 Size
: constant Uint
:= Static_Integer
(Expr
);
1643 if not Is_Type
(U_Ent
) then
1644 Error_Msg_N
("Value_Size cannot be given for &", Nam
);
1647 (Get_Attribute_Definition_Clause
1648 (U_Ent
, Attribute_Value_Size
))
1650 Error_Msg_N
("Value_Size already given for &", Nam
);
1652 elsif Is_Array_Type
(U_Ent
)
1653 and then not Is_Constrained
(U_Ent
)
1656 ("Value_Size cannot be given for unconstrained array", Nam
);
1659 if Is_Elementary_Type
(U_Ent
) then
1660 Check_Size
(Expr
, U_Ent
, Size
, Biased
);
1661 Set_Has_Biased_Representation
(U_Ent
, Biased
);
1664 Set_RM_Size
(U_Ent
, Size
);
1672 when Attribute_Write
=>
1673 Analyze_Stream_TSS_Definition
(TSS_Stream_Write
);
1674 Set_Has_Specified_Stream_Write
(Ent
);
1676 -- All other attributes cannot be set
1680 ("attribute& cannot be set with definition clause", N
);
1683 -- The test for the type being frozen must be performed after
1684 -- any expression the clause has been analyzed since the expression
1685 -- itself might cause freezing that makes the clause illegal.
1687 if Rep_Item_Too_Late
(U_Ent
, N
, FOnly
) then
1690 end Analyze_Attribute_Definition_Clause
;
1692 ----------------------------
1693 -- Analyze_Code_Statement --
1694 ----------------------------
1696 procedure Analyze_Code_Statement
(N
: Node_Id
) is
1697 HSS
: constant Node_Id
:= Parent
(N
);
1698 SBody
: constant Node_Id
:= Parent
(HSS
);
1699 Subp
: constant Entity_Id
:= Current_Scope
;
1706 -- Analyze and check we get right type, note that this implements the
1707 -- requirement (RM 13.8(1)) that Machine_Code be with'ed, since that
1708 -- is the only way that Asm_Insn could possibly be visible.
1710 Analyze_And_Resolve
(Expression
(N
));
1712 if Etype
(Expression
(N
)) = Any_Type
then
1714 elsif Etype
(Expression
(N
)) /= RTE
(RE_Asm_Insn
) then
1715 Error_Msg_N
("incorrect type for code statement", N
);
1719 Check_Code_Statement
(N
);
1721 -- Make sure we appear in the handled statement sequence of a
1722 -- subprogram (RM 13.8(3)).
1724 if Nkind
(HSS
) /= N_Handled_Sequence_Of_Statements
1725 or else Nkind
(SBody
) /= N_Subprogram_Body
1728 ("code statement can only appear in body of subprogram", N
);
1732 -- Do remaining checks (RM 13.8(3)) if not already done
1734 if not Is_Machine_Code_Subprogram
(Subp
) then
1735 Set_Is_Machine_Code_Subprogram
(Subp
);
1737 -- No exception handlers allowed
1739 if Present
(Exception_Handlers
(HSS
)) then
1741 ("exception handlers not permitted in machine code subprogram",
1742 First
(Exception_Handlers
(HSS
)));
1745 -- No declarations other than use clauses and pragmas (we allow
1746 -- certain internally generated declarations as well).
1748 Decl
:= First
(Declarations
(SBody
));
1749 while Present
(Decl
) loop
1750 DeclO
:= Original_Node
(Decl
);
1751 if Comes_From_Source
(DeclO
)
1752 and then Nkind
(DeclO
) /= N_Pragma
1753 and then Nkind
(DeclO
) /= N_Use_Package_Clause
1754 and then Nkind
(DeclO
) /= N_Use_Type_Clause
1755 and then Nkind
(DeclO
) /= N_Implicit_Label_Declaration
1758 ("this declaration not allowed in machine code subprogram",
1765 -- No statements other than code statements, pragmas, and labels.
1766 -- Again we allow certain internally generated statements.
1768 Stmt
:= First
(Statements
(HSS
));
1769 while Present
(Stmt
) loop
1770 StmtO
:= Original_Node
(Stmt
);
1771 if Comes_From_Source
(StmtO
)
1772 and then Nkind
(StmtO
) /= N_Pragma
1773 and then Nkind
(StmtO
) /= N_Label
1774 and then Nkind
(StmtO
) /= N_Code_Statement
1777 ("this statement is not allowed in machine code subprogram",
1784 end Analyze_Code_Statement
;
1786 -----------------------------------------------
1787 -- Analyze_Enumeration_Representation_Clause --
1788 -----------------------------------------------
1790 procedure Analyze_Enumeration_Representation_Clause
(N
: Node_Id
) is
1791 Ident
: constant Node_Id
:= Identifier
(N
);
1792 Aggr
: constant Node_Id
:= Array_Aggregate
(N
);
1793 Enumtype
: Entity_Id
;
1799 Err
: Boolean := False;
1801 Lo
: constant Uint
:= Expr_Value
(Type_Low_Bound
(Universal_Integer
));
1802 Hi
: constant Uint
:= Expr_Value
(Type_High_Bound
(Universal_Integer
));
1807 if Ignore_Rep_Clauses
then
1811 -- First some basic error checks
1814 Enumtype
:= Entity
(Ident
);
1816 if Enumtype
= Any_Type
1817 or else Rep_Item_Too_Early
(Enumtype
, N
)
1821 Enumtype
:= Underlying_Type
(Enumtype
);
1824 if not Is_Enumeration_Type
(Enumtype
) then
1826 ("enumeration type required, found}",
1827 Ident
, First_Subtype
(Enumtype
));
1831 -- Ignore rep clause on generic actual type. This will already have
1832 -- been flagged on the template as an error, and this is the safest
1833 -- way to ensure we don't get a junk cascaded message in the instance.
1835 if Is_Generic_Actual_Type
(Enumtype
) then
1838 -- Type must be in current scope
1840 elsif Scope
(Enumtype
) /= Current_Scope
then
1841 Error_Msg_N
("type must be declared in this scope", Ident
);
1844 -- Type must be a first subtype
1846 elsif not Is_First_Subtype
(Enumtype
) then
1847 Error_Msg_N
("cannot give enumeration rep clause for subtype", N
);
1850 -- Ignore duplicate rep clause
1852 elsif Has_Enumeration_Rep_Clause
(Enumtype
) then
1853 Error_Msg_N
("duplicate enumeration rep clause ignored", N
);
1856 -- Don't allow rep clause for standard [wide_[wide_]]character
1858 elsif Root_Type
(Enumtype
) = Standard_Character
1859 or else Root_Type
(Enumtype
) = Standard_Wide_Character
1860 or else Root_Type
(Enumtype
) = Standard_Wide_Wide_Character
1862 Error_Msg_N
("enumeration rep clause not allowed for this type", N
);
1865 -- Check that the expression is a proper aggregate (no parentheses)
1867 elsif Paren_Count
(Aggr
) /= 0 then
1869 ("extra parentheses surrounding aggregate not allowed",
1873 -- All tests passed, so set rep clause in place
1876 Set_Has_Enumeration_Rep_Clause
(Enumtype
);
1877 Set_Has_Enumeration_Rep_Clause
(Base_Type
(Enumtype
));
1880 -- Now we process the aggregate. Note that we don't use the normal
1881 -- aggregate code for this purpose, because we don't want any of the
1882 -- normal expansion activities, and a number of special semantic
1883 -- rules apply (including the component type being any integer type)
1885 Elit
:= First_Literal
(Enumtype
);
1887 -- First the positional entries if any
1889 if Present
(Expressions
(Aggr
)) then
1890 Expr
:= First
(Expressions
(Aggr
));
1891 while Present
(Expr
) loop
1893 Error_Msg_N
("too many entries in aggregate", Expr
);
1897 Val
:= Static_Integer
(Expr
);
1899 -- Err signals that we found some incorrect entries processing
1900 -- the list. The final checks for completeness and ordering are
1901 -- skipped in this case.
1903 if Val
= No_Uint
then
1905 elsif Val
< Lo
or else Hi
< Val
then
1906 Error_Msg_N
("value outside permitted range", Expr
);
1910 Set_Enumeration_Rep
(Elit
, Val
);
1911 Set_Enumeration_Rep_Expr
(Elit
, Expr
);
1917 -- Now process the named entries if present
1919 if Present
(Component_Associations
(Aggr
)) then
1920 Assoc
:= First
(Component_Associations
(Aggr
));
1921 while Present
(Assoc
) loop
1922 Choice
:= First
(Choices
(Assoc
));
1924 if Present
(Next
(Choice
)) then
1926 ("multiple choice not allowed here", Next
(Choice
));
1930 if Nkind
(Choice
) = N_Others_Choice
then
1931 Error_Msg_N
("others choice not allowed here", Choice
);
1934 elsif Nkind
(Choice
) = N_Range
then
1935 -- ??? should allow zero/one element range here
1936 Error_Msg_N
("range not allowed here", Choice
);
1940 Analyze_And_Resolve
(Choice
, Enumtype
);
1942 if Is_Entity_Name
(Choice
)
1943 and then Is_Type
(Entity
(Choice
))
1945 Error_Msg_N
("subtype name not allowed here", Choice
);
1947 -- ??? should allow static subtype with zero/one entry
1949 elsif Etype
(Choice
) = Base_Type
(Enumtype
) then
1950 if not Is_Static_Expression
(Choice
) then
1951 Flag_Non_Static_Expr
1952 ("non-static expression used for choice!", Choice
);
1956 Elit
:= Expr_Value_E
(Choice
);
1958 if Present
(Enumeration_Rep_Expr
(Elit
)) then
1959 Error_Msg_Sloc
:= Sloc
(Enumeration_Rep_Expr
(Elit
));
1961 ("representation for& previously given#",
1966 Set_Enumeration_Rep_Expr
(Elit
, Choice
);
1968 Expr
:= Expression
(Assoc
);
1969 Val
:= Static_Integer
(Expr
);
1971 if Val
= No_Uint
then
1974 elsif Val
< Lo
or else Hi
< Val
then
1975 Error_Msg_N
("value outside permitted range", Expr
);
1979 Set_Enumeration_Rep
(Elit
, Val
);
1988 -- Aggregate is fully processed. Now we check that a full set of
1989 -- representations was given, and that they are in range and in order.
1990 -- These checks are only done if no other errors occurred.
1996 Elit
:= First_Literal
(Enumtype
);
1997 while Present
(Elit
) loop
1998 if No
(Enumeration_Rep_Expr
(Elit
)) then
1999 Error_Msg_NE
("missing representation for&!", N
, Elit
);
2002 Val
:= Enumeration_Rep
(Elit
);
2004 if Min
= No_Uint
then
2008 if Val
/= No_Uint
then
2009 if Max
/= No_Uint
and then Val
<= Max
then
2011 ("enumeration value for& not ordered!",
2012 Enumeration_Rep_Expr
(Elit
), Elit
);
2018 -- If there is at least one literal whose representation
2019 -- is not equal to the Pos value, then note that this
2020 -- enumeration type has a non-standard representation.
2022 if Val
/= Enumeration_Pos
(Elit
) then
2023 Set_Has_Non_Standard_Rep
(Base_Type
(Enumtype
));
2030 -- Now set proper size information
2033 Minsize
: Uint
:= UI_From_Int
(Minimum_Size
(Enumtype
));
2036 if Has_Size_Clause
(Enumtype
) then
2037 if Esize
(Enumtype
) >= Minsize
then
2042 UI_From_Int
(Minimum_Size
(Enumtype
, Biased
=> True));
2044 if Esize
(Enumtype
) < Minsize
then
2045 Error_Msg_N
("previously given size is too small", N
);
2048 Set_Has_Biased_Representation
(Enumtype
);
2053 Set_RM_Size
(Enumtype
, Minsize
);
2054 Set_Enum_Esize
(Enumtype
);
2057 Set_RM_Size
(Base_Type
(Enumtype
), RM_Size
(Enumtype
));
2058 Set_Esize
(Base_Type
(Enumtype
), Esize
(Enumtype
));
2059 Set_Alignment
(Base_Type
(Enumtype
), Alignment
(Enumtype
));
2063 -- We repeat the too late test in case it froze itself!
2065 if Rep_Item_Too_Late
(Enumtype
, N
) then
2068 end Analyze_Enumeration_Representation_Clause
;
2070 ----------------------------
2071 -- Analyze_Free_Statement --
2072 ----------------------------
2074 procedure Analyze_Free_Statement
(N
: Node_Id
) is
2076 Analyze
(Expression
(N
));
2077 end Analyze_Free_Statement
;
2079 ------------------------------------------
2080 -- Analyze_Record_Representation_Clause --
2081 ------------------------------------------
2083 procedure Analyze_Record_Representation_Clause
(N
: Node_Id
) is
2084 Loc
: constant Source_Ptr
:= Sloc
(N
);
2085 Ident
: constant Node_Id
:= Identifier
(N
);
2086 Rectype
: Entity_Id
;
2092 Hbit
: Uint
:= Uint_0
;
2097 Max_Bit_So_Far
: Uint
;
2098 -- Records the maximum bit position so far. If all field positions
2099 -- are monotonically increasing, then we can skip the circuit for
2100 -- checking for overlap, since no overlap is possible.
2102 Overlap_Check_Required
: Boolean;
2103 -- Used to keep track of whether or not an overlap check is required
2105 Ccount
: Natural := 0;
2106 -- Number of component clauses in record rep clause
2108 CR_Pragma
: Node_Id
:= Empty
;
2109 -- Points to N_Pragma node if Complete_Representation pragma present
2112 if Ignore_Rep_Clauses
then
2117 Rectype
:= Entity
(Ident
);
2119 if Rectype
= Any_Type
2120 or else Rep_Item_Too_Early
(Rectype
, N
)
2124 Rectype
:= Underlying_Type
(Rectype
);
2127 -- First some basic error checks
2129 if not Is_Record_Type
(Rectype
) then
2131 ("record type required, found}", Ident
, First_Subtype
(Rectype
));
2134 elsif Is_Unchecked_Union
(Rectype
) then
2136 ("record rep clause not allowed for Unchecked_Union", N
);
2138 elsif Scope
(Rectype
) /= Current_Scope
then
2139 Error_Msg_N
("type must be declared in this scope", N
);
2142 elsif not Is_First_Subtype
(Rectype
) then
2143 Error_Msg_N
("cannot give record rep clause for subtype", N
);
2146 elsif Has_Record_Rep_Clause
(Rectype
) then
2147 Error_Msg_N
("duplicate record rep clause ignored", N
);
2150 elsif Rep_Item_Too_Late
(Rectype
, N
) then
2154 if Present
(Mod_Clause
(N
)) then
2156 Loc
: constant Source_Ptr
:= Sloc
(N
);
2157 M
: constant Node_Id
:= Mod_Clause
(N
);
2158 P
: constant List_Id
:= Pragmas_Before
(M
);
2162 pragma Warnings
(Off
, Mod_Val
);
2165 Check_Restriction
(No_Obsolescent_Features
, Mod_Clause
(N
));
2167 if Warn_On_Obsolescent_Feature
then
2169 ("mod clause is an obsolescent feature (RM J.8)?", N
);
2171 ("\use alignment attribute definition clause instead?", N
);
2178 -- In ASIS_Mode mode, expansion is disabled, but we must convert
2179 -- the Mod clause into an alignment clause anyway, so that the
2180 -- back-end can compute and back-annotate properly the size and
2181 -- alignment of types that may include this record.
2183 -- This seems dubious, this destroys the source tree in a manner
2184 -- not detectable by ASIS ???
2186 if Operating_Mode
= Check_Semantics
2190 Make_Attribute_Definition_Clause
(Loc
,
2191 Name
=> New_Reference_To
(Base_Type
(Rectype
), Loc
),
2192 Chars
=> Name_Alignment
,
2193 Expression
=> Relocate_Node
(Expression
(M
)));
2195 Set_From_At_Mod
(AtM_Nod
);
2196 Insert_After
(N
, AtM_Nod
);
2197 Mod_Val
:= Get_Alignment_Value
(Expression
(AtM_Nod
));
2198 Set_Mod_Clause
(N
, Empty
);
2201 -- Get the alignment value to perform error checking
2203 Mod_Val
:= Get_Alignment_Value
(Expression
(M
));
2209 -- For untagged types, clear any existing component clauses for the
2210 -- type. If the type is derived, this is what allows us to override
2211 -- a rep clause for the parent. For type extensions, the representation
2212 -- of the inherited components is inherited, so we want to keep previous
2213 -- component clauses for completeness.
2215 if not Is_Tagged_Type
(Rectype
) then
2216 Comp
:= First_Component_Or_Discriminant
(Rectype
);
2217 while Present
(Comp
) loop
2218 Set_Component_Clause
(Comp
, Empty
);
2219 Next_Component_Or_Discriminant
(Comp
);
2223 -- All done if no component clauses
2225 CC
:= First
(Component_Clauses
(N
));
2231 -- If a tag is present, then create a component clause that places it
2232 -- at the start of the record (otherwise gigi may place it after other
2233 -- fields that have rep clauses).
2235 Fent
:= First_Entity
(Rectype
);
2237 if Nkind
(Fent
) = N_Defining_Identifier
2238 and then Chars
(Fent
) = Name_uTag
2240 Set_Component_Bit_Offset
(Fent
, Uint_0
);
2241 Set_Normalized_Position
(Fent
, Uint_0
);
2242 Set_Normalized_First_Bit
(Fent
, Uint_0
);
2243 Set_Normalized_Position_Max
(Fent
, Uint_0
);
2244 Init_Esize
(Fent
, System_Address_Size
);
2246 Set_Component_Clause
(Fent
,
2247 Make_Component_Clause
(Loc
,
2249 Make_Identifier
(Loc
,
2250 Chars
=> Name_uTag
),
2253 Make_Integer_Literal
(Loc
,
2257 Make_Integer_Literal
(Loc
,
2261 Make_Integer_Literal
(Loc
,
2262 UI_From_Int
(System_Address_Size
))));
2264 Ccount
:= Ccount
+ 1;
2267 -- A representation like this applies to the base type
2269 Set_Has_Record_Rep_Clause
(Base_Type
(Rectype
));
2270 Set_Has_Non_Standard_Rep
(Base_Type
(Rectype
));
2271 Set_Has_Specified_Layout
(Base_Type
(Rectype
));
2273 Max_Bit_So_Far
:= Uint_Minus_1
;
2274 Overlap_Check_Required
:= False;
2276 -- Process the component clauses
2278 while Present
(CC
) loop
2282 if Nkind
(CC
) = N_Pragma
then
2285 -- The only pragma of interest is Complete_Representation
2287 if Chars
(CC
) = Name_Complete_Representation
then
2291 -- Processing for real component clause
2294 Ccount
:= Ccount
+ 1;
2295 Posit
:= Static_Integer
(Position
(CC
));
2296 Fbit
:= Static_Integer
(First_Bit
(CC
));
2297 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2300 and then Fbit
/= No_Uint
2301 and then Lbit
/= No_Uint
2305 ("position cannot be negative", Position
(CC
));
2309 ("first bit cannot be negative", First_Bit
(CC
));
2311 -- Values look OK, so find the corresponding record component
2312 -- Even though the syntax allows an attribute reference for
2313 -- implementation-defined components, GNAT does not allow the
2314 -- tag to get an explicit position.
2316 elsif Nkind
(Component_Name
(CC
)) = N_Attribute_Reference
then
2317 if Attribute_Name
(Component_Name
(CC
)) = Name_Tag
then
2318 Error_Msg_N
("position of tag cannot be specified", CC
);
2320 Error_Msg_N
("illegal component name", CC
);
2324 Comp
:= First_Entity
(Rectype
);
2325 while Present
(Comp
) loop
2326 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
2332 -- Maybe component of base type that is absent from
2333 -- statically constrained first subtype.
2335 Comp
:= First_Entity
(Base_Type
(Rectype
));
2336 while Present
(Comp
) loop
2337 exit when Chars
(Comp
) = Chars
(Component_Name
(CC
));
2344 ("component clause is for non-existent field", CC
);
2346 elsif Present
(Component_Clause
(Comp
)) then
2348 -- Diagose duplicate rep clause, or check consistency
2349 -- if this is inherited component. In a double fault,
2350 -- there may be a duplicate inconsistent clause for an
2351 -- inherited component.
2354 Scope
(Original_Record_Component
(Comp
)) = Rectype
2355 or else Parent
(Component_Clause
(Comp
)) = N
2357 Error_Msg_Sloc
:= Sloc
(Component_Clause
(Comp
));
2358 Error_Msg_N
("component clause previously given#", CC
);
2362 Rep1
: constant Node_Id
:= Component_Clause
(Comp
);
2365 if Intval
(Position
(Rep1
)) /=
2366 Intval
(Position
(CC
))
2367 or else Intval
(First_Bit
(Rep1
)) /=
2368 Intval
(First_Bit
(CC
))
2369 or else Intval
(Last_Bit
(Rep1
)) /=
2370 Intval
(Last_Bit
(CC
))
2372 Error_Msg_N
("component clause inconsistent "
2373 & "with representation of ancestor", CC
);
2375 elsif Warn_On_Redundant_Constructs
then
2376 Error_Msg_N
("?redundant component clause "
2377 & "for inherited component!", CC
);
2383 -- Make reference for field in record rep clause and set
2384 -- appropriate entity field in the field identifier.
2387 (Comp
, Component_Name
(CC
), Set_Ref
=> False);
2388 Set_Entity
(Component_Name
(CC
), Comp
);
2390 -- Update Fbit and Lbit to the actual bit number
2392 Fbit
:= Fbit
+ UI_From_Int
(SSU
) * Posit
;
2393 Lbit
:= Lbit
+ UI_From_Int
(SSU
) * Posit
;
2395 if Fbit
<= Max_Bit_So_Far
then
2396 Overlap_Check_Required
:= True;
2398 Max_Bit_So_Far
:= Lbit
;
2401 if Has_Size_Clause
(Rectype
)
2402 and then Esize
(Rectype
) <= Lbit
2405 ("bit number out of range of specified size",
2408 Set_Component_Clause
(Comp
, CC
);
2409 Set_Component_Bit_Offset
(Comp
, Fbit
);
2410 Set_Esize
(Comp
, 1 + (Lbit
- Fbit
));
2411 Set_Normalized_First_Bit
(Comp
, Fbit
mod SSU
);
2412 Set_Normalized_Position
(Comp
, Fbit
/ SSU
);
2414 Set_Normalized_Position_Max
2415 (Fent
, Normalized_Position
(Fent
));
2417 if Is_Tagged_Type
(Rectype
)
2418 and then Fbit
< System_Address_Size
2421 ("component overlaps tag field of&",
2425 -- This information is also set in the corresponding
2426 -- component of the base type, found by accessing the
2427 -- Original_Record_Component link if it is present.
2429 Ocomp
:= Original_Record_Component
(Comp
);
2436 (Component_Name
(CC
),
2441 Set_Has_Biased_Representation
(Comp
, Biased
);
2443 if Present
(Ocomp
) then
2444 Set_Component_Clause
(Ocomp
, CC
);
2445 Set_Component_Bit_Offset
(Ocomp
, Fbit
);
2446 Set_Normalized_First_Bit
(Ocomp
, Fbit
mod SSU
);
2447 Set_Normalized_Position
(Ocomp
, Fbit
/ SSU
);
2448 Set_Esize
(Ocomp
, 1 + (Lbit
- Fbit
));
2450 Set_Normalized_Position_Max
2451 (Ocomp
, Normalized_Position
(Ocomp
));
2453 Set_Has_Biased_Representation
2454 (Ocomp
, Has_Biased_Representation
(Comp
));
2457 if Esize
(Comp
) < 0 then
2458 Error_Msg_N
("component size is negative", CC
);
2469 -- Now that we have processed all the component clauses, check for
2470 -- overlap. We have to leave this till last, since the components
2471 -- can appear in any arbitrary order in the representation clause.
2473 -- We do not need this check if all specified ranges were monotonic,
2474 -- as recorded by Overlap_Check_Required being False at this stage.
2476 -- This first section checks if there are any overlapping entries
2477 -- at all. It does this by sorting all entries and then seeing if
2478 -- there are any overlaps. If there are none, then that is decisive,
2479 -- but if there are overlaps, they may still be OK (they may result
2480 -- from fields in different variants).
2482 if Overlap_Check_Required
then
2483 Overlap_Check1
: declare
2485 OC_Fbit
: array (0 .. Ccount
) of Uint
;
2486 -- First-bit values for component clauses, the value is the
2487 -- offset of the first bit of the field from start of record.
2488 -- The zero entry is for use in sorting.
2490 OC_Lbit
: array (0 .. Ccount
) of Uint
;
2491 -- Last-bit values for component clauses, the value is the
2492 -- offset of the last bit of the field from start of record.
2493 -- The zero entry is for use in sorting.
2495 OC_Count
: Natural := 0;
2496 -- Count of entries in OC_Fbit and OC_Lbit
2498 function OC_Lt
(Op1
, Op2
: Natural) return Boolean;
2499 -- Compare routine for Sort
2501 procedure OC_Move
(From
: Natural; To
: Natural);
2502 -- Move routine for Sort
2504 package Sorting
is new GNAT
.Heap_Sort_G
(OC_Move
, OC_Lt
);
2506 function OC_Lt
(Op1
, Op2
: Natural) return Boolean is
2508 return OC_Fbit
(Op1
) < OC_Fbit
(Op2
);
2511 procedure OC_Move
(From
: Natural; To
: Natural) is
2513 OC_Fbit
(To
) := OC_Fbit
(From
);
2514 OC_Lbit
(To
) := OC_Lbit
(From
);
2518 CC
:= First
(Component_Clauses
(N
));
2519 while Present
(CC
) loop
2520 if Nkind
(CC
) /= N_Pragma
then
2521 Posit
:= Static_Integer
(Position
(CC
));
2522 Fbit
:= Static_Integer
(First_Bit
(CC
));
2523 Lbit
:= Static_Integer
(Last_Bit
(CC
));
2526 and then Fbit
/= No_Uint
2527 and then Lbit
/= No_Uint
2529 OC_Count
:= OC_Count
+ 1;
2530 Posit
:= Posit
* SSU
;
2531 OC_Fbit
(OC_Count
) := Fbit
+ Posit
;
2532 OC_Lbit
(OC_Count
) := Lbit
+ Posit
;
2539 Sorting
.Sort
(OC_Count
);
2541 Overlap_Check_Required
:= False;
2542 for J
in 1 .. OC_Count
- 1 loop
2543 if OC_Lbit
(J
) >= OC_Fbit
(J
+ 1) then
2544 Overlap_Check_Required
:= True;
2551 -- If Overlap_Check_Required is still True, then we have to do
2552 -- the full scale overlap check, since we have at least two fields
2553 -- that do overlap, and we need to know if that is OK since they
2554 -- are in the same variant, or whether we have a definite problem
2556 if Overlap_Check_Required
then
2557 Overlap_Check2
: declare
2558 C1_Ent
, C2_Ent
: Entity_Id
;
2559 -- Entities of components being checked for overlap
2562 -- Component_List node whose Component_Items are being checked
2565 -- Component declaration for component being checked
2568 C1_Ent
:= First_Entity
(Base_Type
(Rectype
));
2570 -- Loop through all components in record. For each component check
2571 -- for overlap with any of the preceding elements on the component
2572 -- list containing the component, and also, if the component is in
2573 -- a variant, check against components outside the case structure.
2574 -- This latter test is repeated recursively up the variant tree.
2576 Main_Component_Loop
: while Present
(C1_Ent
) loop
2577 if Ekind
(C1_Ent
) /= E_Component
2578 and then Ekind
(C1_Ent
) /= E_Discriminant
2580 goto Continue_Main_Component_Loop
;
2583 -- Skip overlap check if entity has no declaration node. This
2584 -- happens with discriminants in constrained derived types.
2585 -- Probably we are missing some checks as a result, but that
2586 -- does not seem terribly serious ???
2588 if No
(Declaration_Node
(C1_Ent
)) then
2589 goto Continue_Main_Component_Loop
;
2592 Clist
:= Parent
(List_Containing
(Declaration_Node
(C1_Ent
)));
2594 -- Loop through component lists that need checking. Check the
2595 -- current component list and all lists in variants above us.
2597 Component_List_Loop
: loop
2599 -- If derived type definition, go to full declaration
2600 -- If at outer level, check discriminants if there are any
2602 if Nkind
(Clist
) = N_Derived_Type_Definition
then
2603 Clist
:= Parent
(Clist
);
2606 -- Outer level of record definition, check discriminants
2608 if Nkind
(Clist
) = N_Full_Type_Declaration
2609 or else Nkind
(Clist
) = N_Private_Type_Declaration
2611 if Has_Discriminants
(Defining_Identifier
(Clist
)) then
2613 First_Discriminant
(Defining_Identifier
(Clist
));
2615 while Present
(C2_Ent
) loop
2616 exit when C1_Ent
= C2_Ent
;
2617 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2618 Next_Discriminant
(C2_Ent
);
2622 -- Record extension case
2624 elsif Nkind
(Clist
) = N_Derived_Type_Definition
then
2627 -- Otherwise check one component list
2630 Citem
:= First
(Component_Items
(Clist
));
2632 while Present
(Citem
) loop
2633 if Nkind
(Citem
) = N_Component_Declaration
then
2634 C2_Ent
:= Defining_Identifier
(Citem
);
2635 exit when C1_Ent
= C2_Ent
;
2636 Check_Component_Overlap
(C1_Ent
, C2_Ent
);
2643 -- Check for variants above us (the parent of the Clist can
2644 -- be a variant, in which case its parent is a variant part,
2645 -- and the parent of the variant part is a component list
2646 -- whose components must all be checked against the current
2647 -- component for overlap.
2649 if Nkind
(Parent
(Clist
)) = N_Variant
then
2650 Clist
:= Parent
(Parent
(Parent
(Clist
)));
2652 -- Check for possible discriminant part in record, this is
2653 -- treated essentially as another level in the recursion.
2654 -- For this case we have the parent of the component list
2655 -- is the record definition, and its parent is the full
2656 -- type declaration which contains the discriminant
2659 elsif Nkind
(Parent
(Clist
)) = N_Record_Definition
then
2660 Clist
:= Parent
(Parent
((Clist
)));
2662 -- If neither of these two cases, we are at the top of
2666 exit Component_List_Loop
;
2668 end loop Component_List_Loop
;
2670 <<Continue_Main_Component_Loop
>>
2671 Next_Entity
(C1_Ent
);
2673 end loop Main_Component_Loop
;
2677 -- For records that have component clauses for all components, and
2678 -- whose size is less than or equal to 32, we need to know the size
2679 -- in the front end to activate possible packed array processing
2680 -- where the component type is a record.
2682 -- At this stage Hbit + 1 represents the first unused bit from all
2683 -- the component clauses processed, so if the component clauses are
2684 -- complete, then this is the length of the record.
2686 -- For records longer than System.Storage_Unit, and for those where
2687 -- not all components have component clauses, the back end determines
2688 -- the length (it may for example be appopriate to round up the size
2689 -- to some convenient boundary, based on alignment considerations etc).
2691 if Unknown_RM_Size
(Rectype
)
2692 and then Hbit
+ 1 <= 32
2694 -- Nothing to do if at least one component with no component clause
2696 Comp
:= First_Component_Or_Discriminant
(Rectype
);
2697 while Present
(Comp
) loop
2698 exit when No
(Component_Clause
(Comp
));
2699 Next_Component_Or_Discriminant
(Comp
);
2702 -- If we fall out of loop, all components have component clauses
2703 -- and so we can set the size to the maximum value.
2706 Set_RM_Size
(Rectype
, Hbit
+ 1);
2710 -- Check missing components if Complete_Representation pragma appeared
2712 if Present
(CR_Pragma
) then
2713 Comp
:= First_Component_Or_Discriminant
(Rectype
);
2714 while Present
(Comp
) loop
2715 if No
(Component_Clause
(Comp
)) then
2717 ("missing component clause for &", CR_Pragma
, Comp
);
2720 Next_Component_Or_Discriminant
(Comp
);
2723 -- If no Complete_Representation pragma, warn if missing components
2725 elsif Warn_On_Unrepped_Components
2726 and then not Warnings_Off
(Rectype
)
2729 Num_Repped_Components
: Nat
:= 0;
2730 Num_Unrepped_Components
: Nat
:= 0;
2733 -- First count number of repped and unrepped components
2735 Comp
:= First_Component_Or_Discriminant
(Rectype
);
2736 while Present
(Comp
) loop
2737 if Present
(Component_Clause
(Comp
)) then
2738 Num_Repped_Components
:= Num_Repped_Components
+ 1;
2741 Num_Unrepped_Components
:= Num_Unrepped_Components
+ 1;
2744 Next_Component_Or_Discriminant
(Comp
);
2747 -- We are only interested in the case where there is at least one
2748 -- unrepped component, and at least half the components have rep
2749 -- clauses. We figure that if less than half have them, then the
2750 -- partial rep clause is really intentional.
2752 if Num_Unrepped_Components
> 0
2753 and then Num_Unrepped_Components
< Num_Repped_Components
2755 Comp
:= First_Component_Or_Discriminant
(Rectype
);
2756 while Present
(Comp
) loop
2757 if No
(Component_Clause
(Comp
))
2758 and then Comes_From_Source
(Comp
)
2759 and then (Is_Scalar_Type
(Underlying_Type
(Etype
(Comp
)))
2760 or else Size_Known_At_Compile_Time
2761 (Underlying_Type
(Etype
(Comp
))))
2763 Error_Msg_Sloc
:= Sloc
(Comp
);
2765 ("?no component clause given for & declared #",
2769 Next_Component_Or_Discriminant
(Comp
);
2774 end Analyze_Record_Representation_Clause
;
2776 -----------------------------
2777 -- Check_Component_Overlap --
2778 -----------------------------
2780 procedure Check_Component_Overlap
(C1_Ent
, C2_Ent
: Entity_Id
) is
2782 if Present
(Component_Clause
(C1_Ent
))
2783 and then Present
(Component_Clause
(C2_Ent
))
2785 -- Exclude odd case where we have two tag fields in the same
2786 -- record, both at location zero. This seems a bit strange,
2787 -- but it seems to happen in some circumstances ???
2789 if Chars
(C1_Ent
) = Name_uTag
2790 and then Chars
(C2_Ent
) = Name_uTag
2795 -- Here we check if the two fields overlap
2798 S1
: constant Uint
:= Component_Bit_Offset
(C1_Ent
);
2799 S2
: constant Uint
:= Component_Bit_Offset
(C2_Ent
);
2800 E1
: constant Uint
:= S1
+ Esize
(C1_Ent
);
2801 E2
: constant Uint
:= S2
+ Esize
(C2_Ent
);
2804 if E2
<= S1
or else E1
<= S2
then
2808 Component_Name
(Component_Clause
(C2_Ent
));
2809 Error_Msg_Sloc
:= Sloc
(Error_Msg_Node_2
);
2811 Component_Name
(Component_Clause
(C1_Ent
));
2813 ("component& overlaps & #",
2814 Component_Name
(Component_Clause
(C1_Ent
)));
2818 end Check_Component_Overlap
;
2820 -----------------------------------
2821 -- Check_Constant_Address_Clause --
2822 -----------------------------------
2824 procedure Check_Constant_Address_Clause
2828 procedure Check_At_Constant_Address
(Nod
: Node_Id
);
2829 -- Checks that the given node N represents a name whose 'Address
2830 -- is constant (in the same sense as OK_Constant_Address_Clause,
2831 -- i.e. the address value is the same at the point of declaration
2832 -- of U_Ent and at the time of elaboration of the address clause.
2834 procedure Check_Expr_Constants
(Nod
: Node_Id
);
2835 -- Checks that Nod meets the requirements for a constant address
2836 -- clause in the sense of the enclosing procedure.
2838 procedure Check_List_Constants
(Lst
: List_Id
);
2839 -- Check that all elements of list Lst meet the requirements for a
2840 -- constant address clause in the sense of the enclosing procedure.
2842 -------------------------------
2843 -- Check_At_Constant_Address --
2844 -------------------------------
2846 procedure Check_At_Constant_Address
(Nod
: Node_Id
) is
2848 if Is_Entity_Name
(Nod
) then
2849 if Present
(Address_Clause
(Entity
((Nod
)))) then
2851 ("invalid address clause for initialized object &!",
2854 ("address for& cannot" &
2855 " depend on another address clause! (RM 13.1(22))!",
2858 elsif In_Same_Source_Unit
(Entity
(Nod
), U_Ent
)
2859 and then Sloc
(U_Ent
) < Sloc
(Entity
(Nod
))
2862 ("invalid address clause for initialized object &!",
2864 Error_Msg_Name_1
:= Chars
(Entity
(Nod
));
2865 Error_Msg_Name_2
:= Chars
(U_Ent
);
2867 ("\% must be defined before % (RM 13.1(22))!",
2871 elsif Nkind
(Nod
) = N_Selected_Component
then
2873 T
: constant Entity_Id
:= Etype
(Prefix
(Nod
));
2876 if (Is_Record_Type
(T
)
2877 and then Has_Discriminants
(T
))
2880 and then Is_Record_Type
(Designated_Type
(T
))
2881 and then Has_Discriminants
(Designated_Type
(T
)))
2884 ("invalid address clause for initialized object &!",
2887 ("\address cannot depend on component" &
2888 " of discriminated record (RM 13.1(22))!",
2891 Check_At_Constant_Address
(Prefix
(Nod
));
2895 elsif Nkind
(Nod
) = N_Indexed_Component
then
2896 Check_At_Constant_Address
(Prefix
(Nod
));
2897 Check_List_Constants
(Expressions
(Nod
));
2900 Check_Expr_Constants
(Nod
);
2902 end Check_At_Constant_Address
;
2904 --------------------------
2905 -- Check_Expr_Constants --
2906 --------------------------
2908 procedure Check_Expr_Constants
(Nod
: Node_Id
) is
2909 Loc_U_Ent
: constant Source_Ptr
:= Sloc
(U_Ent
);
2910 Ent
: Entity_Id
:= Empty
;
2913 if Nkind
(Nod
) in N_Has_Etype
2914 and then Etype
(Nod
) = Any_Type
2920 when N_Empty | N_Error
=>
2923 when N_Identifier | N_Expanded_Name
=>
2924 Ent
:= Entity
(Nod
);
2926 -- We need to look at the original node if it is different
2927 -- from the node, since we may have rewritten things and
2928 -- substituted an identifier representing the rewrite.
2930 if Original_Node
(Nod
) /= Nod
then
2931 Check_Expr_Constants
(Original_Node
(Nod
));
2933 -- If the node is an object declaration without initial
2934 -- value, some code has been expanded, and the expression
2935 -- is not constant, even if the constituents might be
2936 -- acceptable, as in A'Address + offset.
2938 if Ekind
(Ent
) = E_Variable
2939 and then Nkind
(Declaration_Node
(Ent
))
2940 = N_Object_Declaration
2942 No
(Expression
(Declaration_Node
(Ent
)))
2945 ("invalid address clause for initialized object &!",
2948 -- If entity is constant, it may be the result of expanding
2949 -- a check. We must verify that its declaration appears
2950 -- before the object in question, else we also reject the
2953 elsif Ekind
(Ent
) = E_Constant
2954 and then In_Same_Source_Unit
(Ent
, U_Ent
)
2955 and then Sloc
(Ent
) > Loc_U_Ent
2958 ("invalid address clause for initialized object &!",
2965 -- Otherwise look at the identifier and see if it is OK
2967 if Ekind
(Ent
) = E_Named_Integer
2969 Ekind
(Ent
) = E_Named_Real
2976 Ekind
(Ent
) = E_Constant
2978 Ekind
(Ent
) = E_In_Parameter
2980 -- This is the case where we must have Ent defined
2981 -- before U_Ent. Clearly if they are in different
2982 -- units this requirement is met since the unit
2983 -- containing Ent is already processed.
2985 if not In_Same_Source_Unit
(Ent
, U_Ent
) then
2988 -- Otherwise location of Ent must be before the
2989 -- location of U_Ent, that's what prior defined means.
2991 elsif Sloc
(Ent
) < Loc_U_Ent
then
2996 ("invalid address clause for initialized object &!",
2998 Error_Msg_Name_1
:= Chars
(Ent
);
2999 Error_Msg_Name_2
:= Chars
(U_Ent
);
3001 ("\% must be defined before % (RM 13.1(22))!",
3005 elsif Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
3006 Check_Expr_Constants
(Original_Node
(Nod
));
3010 ("invalid address clause for initialized object &!",
3013 if Comes_From_Source
(Ent
) then
3014 Error_Msg_Name_1
:= Chars
(Ent
);
3016 ("\reference to variable% not allowed"
3017 & " (RM 13.1(22))!", Nod
);
3020 ("non-static expression not allowed"
3021 & " (RM 13.1(22))!", Nod
);
3025 when N_Integer_Literal
=>
3027 -- If this is a rewritten unchecked conversion, in a system
3028 -- where Address is an integer type, always use the base type
3029 -- for a literal value. This is user-friendly and prevents
3030 -- order-of-elaboration issues with instances of unchecked
3033 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
3034 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
3037 when N_Real_Literal |
3039 N_Character_Literal
=>
3043 Check_Expr_Constants
(Low_Bound
(Nod
));
3044 Check_Expr_Constants
(High_Bound
(Nod
));
3046 when N_Explicit_Dereference
=>
3047 Check_Expr_Constants
(Prefix
(Nod
));
3049 when N_Indexed_Component
=>
3050 Check_Expr_Constants
(Prefix
(Nod
));
3051 Check_List_Constants
(Expressions
(Nod
));
3054 Check_Expr_Constants
(Prefix
(Nod
));
3055 Check_Expr_Constants
(Discrete_Range
(Nod
));
3057 when N_Selected_Component
=>
3058 Check_Expr_Constants
(Prefix
(Nod
));
3060 when N_Attribute_Reference
=>
3061 if Attribute_Name
(Nod
) = Name_Address
3063 Attribute_Name
(Nod
) = Name_Access
3065 Attribute_Name
(Nod
) = Name_Unchecked_Access
3067 Attribute_Name
(Nod
) = Name_Unrestricted_Access
3069 Check_At_Constant_Address
(Prefix
(Nod
));
3072 Check_Expr_Constants
(Prefix
(Nod
));
3073 Check_List_Constants
(Expressions
(Nod
));
3077 Check_List_Constants
(Component_Associations
(Nod
));
3078 Check_List_Constants
(Expressions
(Nod
));
3080 when N_Component_Association
=>
3081 Check_Expr_Constants
(Expression
(Nod
));
3083 when N_Extension_Aggregate
=>
3084 Check_Expr_Constants
(Ancestor_Part
(Nod
));
3085 Check_List_Constants
(Component_Associations
(Nod
));
3086 Check_List_Constants
(Expressions
(Nod
));
3091 when N_Binary_Op | N_And_Then | N_Or_Else | N_Membership_Test
=>
3092 Check_Expr_Constants
(Left_Opnd
(Nod
));
3093 Check_Expr_Constants
(Right_Opnd
(Nod
));
3096 Check_Expr_Constants
(Right_Opnd
(Nod
));
3098 when N_Type_Conversion |
3099 N_Qualified_Expression |
3101 Check_Expr_Constants
(Expression
(Nod
));
3103 when N_Unchecked_Type_Conversion
=>
3104 Check_Expr_Constants
(Expression
(Nod
));
3106 -- If this is a rewritten unchecked conversion, subtypes
3107 -- in this node are those created within the instance.
3108 -- To avoid order of elaboration issues, replace them
3109 -- with their base types. Note that address clauses can
3110 -- cause order of elaboration problems because they are
3111 -- elaborated by the back-end at the point of definition,
3112 -- and may mention entities declared in between (as long
3113 -- as everything is static). It is user-friendly to allow
3114 -- unchecked conversions in this context.
3116 if Nkind
(Original_Node
(Nod
)) = N_Function_Call
then
3117 Set_Etype
(Expression
(Nod
),
3118 Base_Type
(Etype
(Expression
(Nod
))));
3119 Set_Etype
(Nod
, Base_Type
(Etype
(Nod
)));
3122 when N_Function_Call
=>
3123 if not Is_Pure
(Entity
(Name
(Nod
))) then
3125 ("invalid address clause for initialized object &!",
3129 ("\function & is not pure (RM 13.1(22))!",
3130 Nod
, Entity
(Name
(Nod
)));
3133 Check_List_Constants
(Parameter_Associations
(Nod
));
3136 when N_Parameter_Association
=>
3137 Check_Expr_Constants
(Explicit_Actual_Parameter
(Nod
));
3141 ("invalid address clause for initialized object &!",
3144 ("\must be constant defined before& (RM 13.1(22))!",
3147 end Check_Expr_Constants
;
3149 --------------------------
3150 -- Check_List_Constants --
3151 --------------------------
3153 procedure Check_List_Constants
(Lst
: List_Id
) is
3157 if Present
(Lst
) then
3158 Nod1
:= First
(Lst
);
3159 while Present
(Nod1
) loop
3160 Check_Expr_Constants
(Nod1
);
3164 end Check_List_Constants
;
3166 -- Start of processing for Check_Constant_Address_Clause
3169 Check_Expr_Constants
(Expr
);
3170 end Check_Constant_Address_Clause
;
3176 procedure Check_Size
3180 Biased
: out Boolean)
3182 UT
: constant Entity_Id
:= Underlying_Type
(T
);
3188 -- Dismiss cases for generic types or types with previous errors
3191 or else UT
= Any_Type
3192 or else Is_Generic_Type
(UT
)
3193 or else Is_Generic_Type
(Root_Type
(UT
))
3197 -- Check case of bit packed array
3199 elsif Is_Array_Type
(UT
)
3200 and then Known_Static_Component_Size
(UT
)
3201 and then Is_Bit_Packed_Array
(UT
)
3209 Asiz
:= Component_Size
(UT
);
3210 Indx
:= First_Index
(UT
);
3212 Ityp
:= Etype
(Indx
);
3214 -- If non-static bound, then we are not in the business of
3215 -- trying to check the length, and indeed an error will be
3216 -- issued elsewhere, since sizes of non-static array types
3217 -- cannot be set implicitly or explicitly.
3219 if not Is_Static_Subtype
(Ityp
) then
3223 -- Otherwise accumulate next dimension
3225 Asiz
:= Asiz
* (Expr_Value
(Type_High_Bound
(Ityp
)) -
3226 Expr_Value
(Type_Low_Bound
(Ityp
)) +
3230 exit when No
(Indx
);
3236 Error_Msg_Uint_1
:= Asiz
;
3238 ("size for& too small, minimum allowed is ^", N
, T
);
3239 Set_Esize
(T
, Asiz
);
3240 Set_RM_Size
(T
, Asiz
);
3244 -- All other composite types are ignored
3246 elsif Is_Composite_Type
(UT
) then
3249 -- For fixed-point types, don't check minimum if type is not frozen,
3250 -- since we don't know all the characteristics of the type that can
3251 -- affect the size (e.g. a specified small) till freeze time.
3253 elsif Is_Fixed_Point_Type
(UT
)
3254 and then not Is_Frozen
(UT
)
3258 -- Cases for which a minimum check is required
3261 -- Ignore if specified size is correct for the type
3263 if Known_Esize
(UT
) and then Siz
= Esize
(UT
) then
3267 -- Otherwise get minimum size
3269 M
:= UI_From_Int
(Minimum_Size
(UT
));
3273 -- Size is less than minimum size, but one possibility remains
3274 -- that we can manage with the new size if we bias the type
3276 M
:= UI_From_Int
(Minimum_Size
(UT
, Biased
=> True));
3279 Error_Msg_Uint_1
:= M
;
3281 ("size for& too small, minimum allowed is ^", N
, T
);
3291 -------------------------
3292 -- Get_Alignment_Value --
3293 -------------------------
3295 function Get_Alignment_Value
(Expr
: Node_Id
) return Uint
is
3296 Align
: constant Uint
:= Static_Integer
(Expr
);
3299 if Align
= No_Uint
then
3302 elsif Align
<= 0 then
3303 Error_Msg_N
("alignment value must be positive", Expr
);
3307 for J
in Int
range 0 .. 64 loop
3309 M
: constant Uint
:= Uint_2
** J
;
3312 exit when M
= Align
;
3316 ("alignment value must be power of 2", Expr
);
3324 end Get_Alignment_Value
;
3330 procedure Initialize
is
3332 Unchecked_Conversions
.Init
;
3335 -------------------------
3336 -- Is_Operational_Item --
3337 -------------------------
3339 function Is_Operational_Item
(N
: Node_Id
) return Boolean is
3341 if Nkind
(N
) /= N_Attribute_Definition_Clause
then
3345 Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
3348 return Id
= Attribute_Input
3349 or else Id
= Attribute_Output
3350 or else Id
= Attribute_Read
3351 or else Id
= Attribute_Write
3352 or else Id
= Attribute_External_Tag
;
3355 end Is_Operational_Item
;
3361 function Minimum_Size
3363 Biased
: Boolean := False) return Nat
3365 Lo
: Uint
:= No_Uint
;
3366 Hi
: Uint
:= No_Uint
;
3367 LoR
: Ureal
:= No_Ureal
;
3368 HiR
: Ureal
:= No_Ureal
;
3369 LoSet
: Boolean := False;
3370 HiSet
: Boolean := False;
3374 R_Typ
: constant Entity_Id
:= Root_Type
(T
);
3377 -- If bad type, return 0
3379 if T
= Any_Type
then
3382 -- For generic types, just return zero. There cannot be any legitimate
3383 -- need to know such a size, but this routine may be called with a
3384 -- generic type as part of normal processing.
3386 elsif Is_Generic_Type
(R_Typ
)
3387 or else R_Typ
= Any_Type
3391 -- Access types. Normally an access type cannot have a size smaller
3392 -- than the size of System.Address. The exception is on VMS, where
3393 -- we have short and long addresses, and it is possible for an access
3394 -- type to have a short address size (and thus be less than the size
3395 -- of System.Address itself). We simply skip the check for VMS, and
3396 -- leave the back end to do the check.
3398 elsif Is_Access_Type
(T
) then
3399 if OpenVMS_On_Target
then
3402 return System_Address_Size
;
3405 -- Floating-point types
3407 elsif Is_Floating_Point_Type
(T
) then
3408 return UI_To_Int
(Esize
(R_Typ
));
3412 elsif Is_Discrete_Type
(T
) then
3414 -- The following loop is looking for the nearest compile time
3415 -- known bounds following the ancestor subtype chain. The idea
3416 -- is to find the most restrictive known bounds information.
3420 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3425 if Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
)) then
3426 Lo
:= Expr_Rep_Value
(Type_Low_Bound
(Ancest
));
3433 if Compile_Time_Known_Value
(Type_High_Bound
(Ancest
)) then
3434 Hi
:= Expr_Rep_Value
(Type_High_Bound
(Ancest
));
3440 Ancest
:= Ancestor_Subtype
(Ancest
);
3443 Ancest
:= Base_Type
(T
);
3445 if Is_Generic_Type
(Ancest
) then
3451 -- Fixed-point types. We can't simply use Expr_Value to get the
3452 -- Corresponding_Integer_Value values of the bounds, since these
3453 -- do not get set till the type is frozen, and this routine can
3454 -- be called before the type is frozen. Similarly the test for
3455 -- bounds being static needs to include the case where we have
3456 -- unanalyzed real literals for the same reason.
3458 elsif Is_Fixed_Point_Type
(T
) then
3460 -- The following loop is looking for the nearest compile time
3461 -- known bounds following the ancestor subtype chain. The idea
3462 -- is to find the most restrictive known bounds information.
3466 if Ancest
= Any_Type
or else Etype
(Ancest
) = Any_Type
then
3470 -- Note: In the following two tests for LoSet and HiSet, it may
3471 -- seem redundant to test for N_Real_Literal here since normally
3472 -- one would assume that the test for the value being known at
3473 -- compile time includes this case. However, there is a glitch.
3474 -- If the real literal comes from folding a non-static expression,
3475 -- then we don't consider any non- static expression to be known
3476 -- at compile time if we are in configurable run time mode (needed
3477 -- in some cases to give a clearer definition of what is and what
3478 -- is not accepted). So the test is indeed needed. Without it, we
3479 -- would set neither Lo_Set nor Hi_Set and get an infinite loop.
3482 if Nkind
(Type_Low_Bound
(Ancest
)) = N_Real_Literal
3483 or else Compile_Time_Known_Value
(Type_Low_Bound
(Ancest
))
3485 LoR
:= Expr_Value_R
(Type_Low_Bound
(Ancest
));
3492 if Nkind
(Type_High_Bound
(Ancest
)) = N_Real_Literal
3493 or else Compile_Time_Known_Value
(Type_High_Bound
(Ancest
))
3495 HiR
:= Expr_Value_R
(Type_High_Bound
(Ancest
));
3501 Ancest
:= Ancestor_Subtype
(Ancest
);
3504 Ancest
:= Base_Type
(T
);
3506 if Is_Generic_Type
(Ancest
) then
3512 Lo
:= UR_To_Uint
(LoR
/ Small_Value
(T
));
3513 Hi
:= UR_To_Uint
(HiR
/ Small_Value
(T
));
3515 -- No other types allowed
3518 raise Program_Error
;
3521 -- Fall through with Hi and Lo set. Deal with biased case
3523 if (Biased
and then not Is_Fixed_Point_Type
(T
))
3524 or else Has_Biased_Representation
(T
)
3530 -- Signed case. Note that we consider types like range 1 .. -1 to be
3531 -- signed for the purpose of computing the size, since the bounds
3532 -- have to be accomodated in the base type.
3534 if Lo
< 0 or else Hi
< 0 then
3538 -- S = size, B = 2 ** (size - 1) (can accommodate -B .. +(B - 1))
3539 -- Note that we accommodate the case where the bounds cross. This
3540 -- can happen either because of the way the bounds are declared
3541 -- or because of the algorithm in Freeze_Fixed_Point_Type.
3555 -- If both bounds are positive, make sure that both are represen-
3556 -- table in the case where the bounds are crossed. This can happen
3557 -- either because of the way the bounds are declared, or because of
3558 -- the algorithm in Freeze_Fixed_Point_Type.
3564 -- S = size, (can accommodate 0 .. (2**size - 1))
3567 while Hi
>= Uint_2
** S
loop
3575 ---------------------------
3576 -- New_Stream_Subprogram --
3577 ---------------------------
3579 procedure New_Stream_Subprogram
3583 Nam
: TSS_Name_Type
)
3585 Loc
: constant Source_Ptr
:= Sloc
(N
);
3586 Sname
: constant Name_Id
:= Make_TSS_Name
(Base_Type
(Ent
), Nam
);
3587 Subp_Id
: Entity_Id
;
3588 Subp_Decl
: Node_Id
;
3592 Defer_Declaration
: constant Boolean :=
3593 Is_Tagged_Type
(Ent
) or else Is_Private_Type
(Ent
);
3594 -- For a tagged type, there is a declaration for each stream attribute
3595 -- at the freeze point, and we must generate only a completion of this
3596 -- declaration. We do the same for private types, because the full view
3597 -- might be tagged. Otherwise we generate a declaration at the point of
3598 -- the attribute definition clause.
3600 function Build_Spec
return Node_Id
;
3601 -- Used for declaration and renaming declaration, so that this is
3602 -- treated as a renaming_as_body.
3608 function Build_Spec
return Node_Id
is
3609 Out_P
: constant Boolean := (Nam
= TSS_Stream_Read
);
3612 T_Ref
: constant Node_Id
:= New_Reference_To
(Etyp
, Loc
);
3615 Subp_Id
:= Make_Defining_Identifier
(Loc
, Sname
);
3617 -- S : access Root_Stream_Type'Class
3619 Formals
:= New_List
(
3620 Make_Parameter_Specification
(Loc
,
3621 Defining_Identifier
=>
3622 Make_Defining_Identifier
(Loc
, Name_S
),
3624 Make_Access_Definition
(Loc
,
3627 Designated_Type
(Etype
(F
)), Loc
))));
3629 if Nam
= TSS_Stream_Input
then
3630 Spec
:= Make_Function_Specification
(Loc
,
3631 Defining_Unit_Name
=> Subp_Id
,
3632 Parameter_Specifications
=> Formals
,
3633 Result_Definition
=> T_Ref
);
3638 Make_Parameter_Specification
(Loc
,
3639 Defining_Identifier
=> Make_Defining_Identifier
(Loc
, Name_V
),
3640 Out_Present
=> Out_P
,
3641 Parameter_Type
=> T_Ref
));
3643 Spec
:= Make_Procedure_Specification
(Loc
,
3644 Defining_Unit_Name
=> Subp_Id
,
3645 Parameter_Specifications
=> Formals
);
3651 -- Start of processing for New_Stream_Subprogram
3654 F
:= First_Formal
(Subp
);
3656 if Ekind
(Subp
) = E_Procedure
then
3657 Etyp
:= Etype
(Next_Formal
(F
));
3659 Etyp
:= Etype
(Subp
);
3662 -- Prepare subprogram declaration and insert it as an action on the
3663 -- clause node. The visibility for this entity is used to test for
3664 -- visibility of the attribute definition clause (in the sense of
3665 -- 8.3(23) as amended by AI-195).
3667 if not Defer_Declaration
then
3669 Make_Subprogram_Declaration
(Loc
,
3670 Specification
=> Build_Spec
);
3672 -- For a tagged type, there is always a visible declaration for each
3673 -- stream TSS (it is a predefined primitive operation), and the
3674 -- completion of this declaration occurs at the freeze point, which is
3675 -- not always visible at places where the attribute definition clause is
3676 -- visible. So, we create a dummy entity here for the purpose of
3677 -- tracking the visibility of the attribute definition clause itself.
3681 Make_Defining_Identifier
(Loc
,
3682 Chars
=> New_External_Name
(Sname
, 'V'));
3684 Make_Object_Declaration
(Loc
,
3685 Defining_Identifier
=> Subp_Id
,
3686 Object_Definition
=> New_Occurrence_Of
(Standard_Boolean
, Loc
));
3689 Insert_Action
(N
, Subp_Decl
);
3690 Set_Entity
(N
, Subp_Id
);
3693 Make_Subprogram_Renaming_Declaration
(Loc
,
3694 Specification
=> Build_Spec
,
3695 Name
=> New_Reference_To
(Subp
, Loc
));
3697 if Defer_Declaration
then
3698 Set_TSS
(Base_Type
(Ent
), Subp_Id
);
3700 Insert_Action
(N
, Subp_Decl
);
3701 Copy_TSS
(Subp_Id
, Base_Type
(Ent
));
3703 end New_Stream_Subprogram
;
3705 ------------------------
3706 -- Rep_Item_Too_Early --
3707 ------------------------
3709 function Rep_Item_Too_Early
(T
: Entity_Id
; N
: Node_Id
) return Boolean is
3711 -- Cannot apply non-operational rep items to generic types
3713 if Is_Operational_Item
(N
) then
3717 and then Is_Generic_Type
(Root_Type
(T
))
3720 ("representation item not allowed for generic type", N
);
3724 -- Otherwise check for incompleted type
3726 if Is_Incomplete_Or_Private_Type
(T
)
3727 and then No
(Underlying_Type
(T
))
3730 ("representation item must be after full type declaration", N
);
3733 -- If the type has incompleted components, a representation clause is
3734 -- illegal but stream attributes and Convention pragmas are correct.
3736 elsif Has_Private_Component
(T
) then
3737 if Nkind
(N
) = N_Pragma
then
3741 ("representation item must appear after type is fully defined",
3748 end Rep_Item_Too_Early
;
3750 -----------------------
3751 -- Rep_Item_Too_Late --
3752 -----------------------
3754 function Rep_Item_Too_Late
3757 FOnly
: Boolean := False) return Boolean
3760 Parent_Type
: Entity_Id
;
3763 -- Output the too late message. Note that this is not considered a
3764 -- serious error, since the effect is simply that we ignore the
3765 -- representation clause in this case.
3771 procedure Too_Late
is
3773 Error_Msg_N
("|representation item appears too late!", N
);
3776 -- Start of processing for Rep_Item_Too_Late
3779 -- First make sure entity is not frozen (RM 13.1(9)). Exclude imported
3780 -- types, which may be frozen if they appear in a representation clause
3781 -- for a local type.
3784 and then not From_With_Type
(T
)
3787 S
:= First_Subtype
(T
);
3789 if Present
(Freeze_Node
(S
)) then
3791 ("?no more representation items for }", Freeze_Node
(S
), S
);
3796 -- Check for case of non-tagged derived type whose parent either has
3797 -- primitive operations, or is a by reference type (RM 13.1(10)).
3801 and then Is_Derived_Type
(T
)
3802 and then not Is_Tagged_Type
(T
)
3804 Parent_Type
:= Etype
(Base_Type
(T
));
3806 if Has_Primitive_Operations
(Parent_Type
) then
3809 ("primitive operations already defined for&!", N
, Parent_Type
);
3812 elsif Is_By_Reference_Type
(Parent_Type
) then
3815 ("parent type & is a by reference type!", N
, Parent_Type
);
3820 -- No error, link item into head of chain of rep items for the entity,
3821 -- but avoid chaining if we have an overloadable entity, and the pragma
3822 -- is one that can apply to multiple overloaded entities.
3824 if Is_Overloadable
(T
)
3825 and then Nkind
(N
) = N_Pragma
3826 and then (Chars
(N
) = Name_Convention
3828 Chars
(N
) = Name_Import
3830 Chars
(N
) = Name_Export
3832 Chars
(N
) = Name_External
3834 Chars
(N
) = Name_Interface
)
3838 Record_Rep_Item
(T
, N
);
3841 -- Rep item was OK, not too late
3844 end Rep_Item_Too_Late
;
3846 -------------------------
3847 -- Same_Representation --
3848 -------------------------
3850 function Same_Representation
(Typ1
, Typ2
: Entity_Id
) return Boolean is
3851 T1
: constant Entity_Id
:= Underlying_Type
(Typ1
);
3852 T2
: constant Entity_Id
:= Underlying_Type
(Typ2
);
3855 -- A quick check, if base types are the same, then we definitely have
3856 -- the same representation, because the subtype specific representation
3857 -- attributes (Size and Alignment) do not affect representation from
3858 -- the point of view of this test.
3860 if Base_Type
(T1
) = Base_Type
(T2
) then
3863 elsif Is_Private_Type
(Base_Type
(T2
))
3864 and then Base_Type
(T1
) = Full_View
(Base_Type
(T2
))
3869 -- Tagged types never have differing representations
3871 if Is_Tagged_Type
(T1
) then
3875 -- Representations are definitely different if conventions differ
3877 if Convention
(T1
) /= Convention
(T2
) then
3881 -- Representations are different if component alignments differ
3883 if (Is_Record_Type
(T1
) or else Is_Array_Type
(T1
))
3885 (Is_Record_Type
(T2
) or else Is_Array_Type
(T2
))
3886 and then Component_Alignment
(T1
) /= Component_Alignment
(T2
)
3891 -- For arrays, the only real issue is component size. If we know the
3892 -- component size for both arrays, and it is the same, then that's
3893 -- good enough to know we don't have a change of representation.
3895 if Is_Array_Type
(T1
) then
3896 if Known_Component_Size
(T1
)
3897 and then Known_Component_Size
(T2
)
3898 and then Component_Size
(T1
) = Component_Size
(T2
)
3904 -- Types definitely have same representation if neither has non-standard
3905 -- representation since default representations are always consistent.
3906 -- If only one has non-standard representation, and the other does not,
3907 -- then we consider that they do not have the same representation. They
3908 -- might, but there is no way of telling early enough.
3910 if Has_Non_Standard_Rep
(T1
) then
3911 if not Has_Non_Standard_Rep
(T2
) then
3915 return not Has_Non_Standard_Rep
(T2
);
3918 -- Here the two types both have non-standard representation, and we
3919 -- need to determine if they have the same non-standard representation
3921 -- For arrays, we simply need to test if the component sizes are the
3922 -- same. Pragma Pack is reflected in modified component sizes, so this
3923 -- check also deals with pragma Pack.
3925 if Is_Array_Type
(T1
) then
3926 return Component_Size
(T1
) = Component_Size
(T2
);
3928 -- Tagged types always have the same representation, because it is not
3929 -- possible to specify different representations for common fields.
3931 elsif Is_Tagged_Type
(T1
) then
3934 -- Case of record types
3936 elsif Is_Record_Type
(T1
) then
3938 -- Packed status must conform
3940 if Is_Packed
(T1
) /= Is_Packed
(T2
) then
3943 -- Otherwise we must check components. Typ2 maybe a constrained
3944 -- subtype with fewer components, so we compare the components
3945 -- of the base types.
3948 Record_Case
: declare
3949 CD1
, CD2
: Entity_Id
;
3951 function Same_Rep
return Boolean;
3952 -- CD1 and CD2 are either components or discriminants. This
3953 -- function tests whether the two have the same representation
3959 function Same_Rep
return Boolean is
3961 if No
(Component_Clause
(CD1
)) then
3962 return No
(Component_Clause
(CD2
));
3966 Present
(Component_Clause
(CD2
))
3968 Component_Bit_Offset
(CD1
) = Component_Bit_Offset
(CD2
)
3970 Esize
(CD1
) = Esize
(CD2
);
3974 -- Start processing for Record_Case
3977 if Has_Discriminants
(T1
) then
3978 CD1
:= First_Discriminant
(T1
);
3979 CD2
:= First_Discriminant
(T2
);
3981 -- The number of discriminants may be different if the
3982 -- derived type has fewer (constrained by values). The
3983 -- invisible discriminants retain the representation of
3984 -- the original, so the discrepancy does not per se
3985 -- indicate a different representation.
3988 and then Present
(CD2
)
3990 if not Same_Rep
then
3993 Next_Discriminant
(CD1
);
3994 Next_Discriminant
(CD2
);
3999 CD1
:= First_Component
(Underlying_Type
(Base_Type
(T1
)));
4000 CD2
:= First_Component
(Underlying_Type
(Base_Type
(T2
)));
4002 while Present
(CD1
) loop
4003 if not Same_Rep
then
4006 Next_Component
(CD1
);
4007 Next_Component
(CD2
);
4015 -- For enumeration types, we must check each literal to see if the
4016 -- representation is the same. Note that we do not permit enumeration
4017 -- reprsentation clauses for Character and Wide_Character, so these
4018 -- cases were already dealt with.
4020 elsif Is_Enumeration_Type
(T1
) then
4022 Enumeration_Case
: declare
4026 L1
:= First_Literal
(T1
);
4027 L2
:= First_Literal
(T2
);
4029 while Present
(L1
) loop
4030 if Enumeration_Rep
(L1
) /= Enumeration_Rep
(L2
) then
4040 end Enumeration_Case
;
4042 -- Any other types have the same representation for these purposes
4047 end Same_Representation
;
4049 --------------------
4050 -- Set_Enum_Esize --
4051 --------------------
4053 procedure Set_Enum_Esize
(T
: Entity_Id
) is
4061 -- Find the minimum standard size (8,16,32,64) that fits
4063 Lo
:= Enumeration_Rep
(Entity
(Type_Low_Bound
(T
)));
4064 Hi
:= Enumeration_Rep
(Entity
(Type_High_Bound
(T
)));
4067 if Lo
>= -Uint_2
**07 and then Hi
< Uint_2
**07 then
4068 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
4070 elsif Lo
>= -Uint_2
**15 and then Hi
< Uint_2
**15 then
4073 elsif Lo
>= -Uint_2
**31 and then Hi
< Uint_2
**31 then
4076 else pragma Assert
(Lo
>= -Uint_2
**63 and then Hi
< Uint_2
**63);
4081 if Hi
< Uint_2
**08 then
4082 Sz
:= Standard_Character_Size
; -- May be > 8 on some targets
4084 elsif Hi
< Uint_2
**16 then
4087 elsif Hi
< Uint_2
**32 then
4090 else pragma Assert
(Hi
< Uint_2
**63);
4095 -- That minimum is the proper size unless we have a foreign convention
4096 -- and the size required is 32 or less, in which case we bump the size
4097 -- up to 32. This is required for C and C++ and seems reasonable for
4098 -- all other foreign conventions.
4100 if Has_Foreign_Convention
(T
)
4101 and then Esize
(T
) < Standard_Integer_Size
4103 Init_Esize
(T
, Standard_Integer_Size
);
4109 ------------------------------
4110 -- Validate_Address_Clauses --
4111 ------------------------------
4113 procedure Validate_Address_Clauses
is
4115 for J
in Address_Clause_Checks
.First
.. Address_Clause_Checks
.Last
loop
4117 ACCR
: Address_Clause_Check_Record
4118 renames Address_Clause_Checks
.Table
(J
);
4127 -- Skip processing of this entry if warning already posted
4129 if not Address_Warning_Posted
(ACCR
.N
) then
4131 -- Get alignments. Really we should always have the alignment
4132 -- of the objects properly back annotated, but right now the
4133 -- back end fails to back annotate for address clauses???
4135 if Known_Alignment
(ACCR
.X
) then
4136 X_Alignment
:= Alignment
(ACCR
.X
);
4138 X_Alignment
:= Alignment
(Etype
(ACCR
.X
));
4141 if Known_Alignment
(ACCR
.Y
) then
4142 Y_Alignment
:= Alignment
(ACCR
.Y
);
4144 Y_Alignment
:= Alignment
(Etype
(ACCR
.Y
));
4147 -- Similarly obtain sizes
4149 if Known_Esize
(ACCR
.X
) then
4150 X_Size
:= Esize
(ACCR
.X
);
4152 X_Size
:= Esize
(Etype
(ACCR
.X
));
4155 if Known_Esize
(ACCR
.Y
) then
4156 Y_Size
:= Esize
(ACCR
.Y
);
4158 Y_Size
:= Esize
(Etype
(ACCR
.Y
));
4161 -- Check for large object overlaying smaller one
4164 and then X_Size
> Uint_0
4165 and then X_Size
> Y_Size
4168 ("?size for overlaid object is too small", ACCR
.N
);
4169 Error_Msg_Uint_1
:= X_Size
;
4171 ("\?size of & is ^", ACCR
.N
, ACCR
.X
);
4172 Error_Msg_Uint_1
:= Y_Size
;
4174 ("\?size of & is ^", ACCR
.N
, ACCR
.Y
);
4176 -- Check for inadequate alignment. Again the defensive check
4177 -- on Y_Alignment should not be needed, but because of the
4178 -- failure in back end annotation, we can have an alignment
4181 -- Note: we do not check alignments if we gave a size
4182 -- warning, since it would likely be redundant.
4184 elsif Y_Alignment
/= Uint_0
4185 and then Y_Alignment
< X_Alignment
4188 ("?specified address for& may be inconsistent "
4192 ("\?program execution may be erroneous (RM 13.3(27))",
4194 Error_Msg_Uint_1
:= X_Alignment
;
4196 ("\?alignment of & is ^",
4198 Error_Msg_Uint_1
:= Y_Alignment
;
4200 ("\?alignment of & is ^",
4206 end Validate_Address_Clauses
;
4208 -----------------------------------
4209 -- Validate_Unchecked_Conversion --
4210 -----------------------------------
4212 procedure Validate_Unchecked_Conversion
4214 Act_Unit
: Entity_Id
)
4221 -- Obtain source and target types. Note that we call Ancestor_Subtype
4222 -- here because the processing for generic instantiation always makes
4223 -- subtypes, and we want the original frozen actual types.
4225 -- If we are dealing with private types, then do the check on their
4226 -- fully declared counterparts if the full declarations have been
4227 -- encountered (they don't have to be visible, but they must exist!)
4229 Source
:= Ancestor_Subtype
(Etype
(First_Formal
(Act_Unit
)));
4231 if Is_Private_Type
(Source
)
4232 and then Present
(Underlying_Type
(Source
))
4234 Source
:= Underlying_Type
(Source
);
4237 Target
:= Ancestor_Subtype
(Etype
(Act_Unit
));
4239 -- If either type is generic, the instantiation happens within a
4240 -- generic unit, and there is nothing to check. The proper check
4241 -- will happen when the enclosing generic is instantiated.
4243 if Is_Generic_Type
(Source
) or else Is_Generic_Type
(Target
) then
4247 if Is_Private_Type
(Target
)
4248 and then Present
(Underlying_Type
(Target
))
4250 Target
:= Underlying_Type
(Target
);
4253 -- Source may be unconstrained array, but not target
4255 if Is_Array_Type
(Target
)
4256 and then not Is_Constrained
(Target
)
4259 ("unchecked conversion to unconstrained array not allowed", N
);
4263 -- Warn if conversion between two different convention pointers
4265 if Is_Access_Type
(Target
)
4266 and then Is_Access_Type
(Source
)
4267 and then Convention
(Target
) /= Convention
(Source
)
4268 and then Warn_On_Unchecked_Conversion
4271 ("?conversion between pointers with different conventions!", N
);
4274 -- Warn if one of the operands is Ada.Calendar.Time. Do not emit a
4275 -- warning when compiling GNAT-related sources.
4277 if Warn_On_Unchecked_Conversion
4278 and then not In_Predefined_Unit
(N
)
4279 and then RTU_Loaded
(Ada_Calendar
)
4281 (Chars
(Source
) = Name_Time
4283 Chars
(Target
) = Name_Time
)
4285 -- If Ada.Calendar is loaded and the name of one of the operands is
4286 -- Time, there is a good chance that this is Ada.Calendar.Time.
4289 Calendar_Time
: constant Entity_Id
:=
4290 Full_View
(RTE
(RO_CA_Time
));
4292 pragma Assert
(Present
(Calendar_Time
));
4294 if Source
= Calendar_Time
4295 or else Target
= Calendar_Time
4298 ("?representation of 'Time values may change between " &
4299 "'G'N'A'T versions", N
);
4304 -- Make entry in unchecked conversion table for later processing
4305 -- by Validate_Unchecked_Conversions, which will check sizes and
4306 -- alignments (using values set by the back-end where possible).
4307 -- This is only done if the appropriate warning is active
4309 if Warn_On_Unchecked_Conversion
then
4310 Unchecked_Conversions
.Append
4311 (New_Val
=> UC_Entry
'
4316 -- If both sizes are known statically now, then back end annotation
4317 -- is not required to do a proper check but if either size is not
4318 -- known statically, then we need the annotation.
4320 if Known_Static_RM_Size (Source)
4321 and then Known_Static_RM_Size (Target)
4325 Back_Annotate_Rep_Info := True;
4329 -- If unchecked conversion to access type, and access type is
4330 -- declared in the same unit as the unchecked conversion, then
4331 -- set the No_Strict_Aliasing flag (no strict aliasing is
4332 -- implicit in this situation).
4334 if Is_Access_Type (Target) and then
4335 In_Same_Source_Unit (Target, N)
4337 Set_No_Strict_Aliasing (Implementation_Base_Type (Target));
4340 -- Generate N_Validate_Unchecked_Conversion node for back end in
4341 -- case the back end needs to perform special validation checks.
4343 -- Shouldn't this be in exp_ch13, since the check only gets done
4344 -- if we have full expansion and the back end is called ???
4347 Make_Validate_Unchecked_Conversion (Sloc (N));
4348 Set_Source_Type (Vnode, Source);
4349 Set_Target_Type (Vnode, Target);
4351 -- If the unchecked conversion node is in a list, just insert before
4352 -- it. If not we have some strange case, not worth bothering about.
4354 if Is_List_Member (N) then
4355 Insert_After (N, Vnode);
4357 end Validate_Unchecked_Conversion;
4359 ------------------------------------
4360 -- Validate_Unchecked_Conversions --
4361 ------------------------------------
4363 procedure Validate_Unchecked_Conversions is
4365 for N in Unchecked_Conversions.First .. Unchecked_Conversions.Last loop
4367 T : UC_Entry renames Unchecked_Conversions.Table (N);
4369 Enode : constant Node_Id := T.Enode;
4370 Source : constant Entity_Id := T.Source;
4371 Target : constant Entity_Id := T.Target;
4377 -- This validation check, which warns if we have unequal sizes
4378 -- for unchecked conversion, and thus potentially implementation
4379 -- dependent semantics, is one of the few occasions on which we
4380 -- use the official RM size instead of Esize. See description
4381 -- in Einfo "Handling of Type'Size Values" for details.
4383 if Serious_Errors_Detected = 0
4384 and then Known_Static_RM_Size (Source)
4385 and then Known_Static_RM_Size (Target)
4387 Source_Siz := RM_Size (Source);
4388 Target_Siz := RM_Size (Target);
4390 if Source_Siz /= Target_Siz then
4392 ("?types for unchecked conversion have different sizes!",
4395 if All_Errors_Mode then
4396 Error_Msg_Name_1 := Chars (Source);
4397 Error_Msg_Uint_1 := Source_Siz;
4398 Error_Msg_Name_2 := Chars (Target);
4399 Error_Msg_Uint_2 := Target_Siz;
4401 ("\size of % is ^, size of % is ^?", Enode);
4403 Error_Msg_Uint_1 := UI_Abs (Source_Siz - Target_Siz);
4405 if Is_Discrete_Type (Source)
4406 and then Is_Discrete_Type (Target)
4408 if Source_Siz > Target_Siz then
4410 ("\?^ high order bits of source will be ignored!",
4413 elsif Is_Unsigned_Type (Source) then
4415 ("\?source will be extended with ^ high order " &
4416 "zero bits?!", Enode);
4420 ("\?source will be extended with ^ high order " &
4425 elsif Source_Siz < Target_Siz then
4426 if Is_Discrete_Type (Target) then
4427 if Bytes_Big_Endian then
4429 ("\?target value will include ^ undefined " &
4434 ("\?target value will include ^ undefined " &
4441 ("\?^ trailing bits of target value will be " &
4442 "undefined!", Enode);
4445 else pragma Assert (Source_Siz > Target_Siz);
4447 ("\?^ trailing bits of source will be ignored!",
4454 -- If both types are access types, we need to check the alignment.
4455 -- If the alignment of both is specified, we can do it here.
4457 if Serious_Errors_Detected = 0
4458 and then Ekind (Source) in Access_Kind
4459 and then Ekind (Target) in Access_Kind
4460 and then Target_Strict_Alignment
4461 and then Present (Designated_Type (Source))
4462 and then Present (Designated_Type (Target))
4465 D_Source : constant Entity_Id := Designated_Type (Source);
4466 D_Target : constant Entity_Id := Designated_Type (Target);
4469 if Known_Alignment (D_Source)
4470 and then Known_Alignment (D_Target)
4473 Source_Align : constant Uint := Alignment (D_Source);
4474 Target_Align : constant Uint := Alignment (D_Target);
4477 if Source_Align < Target_Align
4478 and then not Is_Tagged_Type (D_Source)
4480 Error_Msg_Uint_1 := Target_Align;
4481 Error_Msg_Uint_2 := Source_Align;
4482 Error_Msg_Node_2 := D_Source;
4484 ("?alignment of & (^) is stricter than " &
4485 "alignment of & (^)!", Enode, D_Target);
4487 if All_Errors_Mode then
4489 ("\?resulting access value may have invalid " &
4490 "alignment!", Enode);
4499 end Validate_Unchecked_Conversions;