1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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 Aspects
; use Aspects
;
28 with Csets
; use Csets
;
29 with Einfo
; use Einfo
;
30 with Einfo
.Entities
; use Einfo
.Entities
;
31 with Einfo
.Utils
; use Einfo
.Utils
;
33 with Nlists
; use Nlists
;
34 with Nmake
; use Nmake
;
36 with Restrict
; use Restrict
;
37 with Rident
; use Rident
;
38 with Sinfo
.Utils
; use Sinfo
.Utils
;
39 with Sem_Util
; use Sem_Util
;
40 with Snames
; use Snames
;
41 with Stand
; use Stand
;
42 with Stringt
; use Stringt
;
43 with Urealp
; use Urealp
;
45 package body Tbuild
is
47 -----------------------
48 -- Local Subprograms --
49 -----------------------
51 procedure Add_Unique_Serial_Number
;
52 -- Add a unique serialization to the string in the Name_Buffer. This
53 -- consists of a unit specific serial number, and b/s for body/spec.
55 ------------------------------
56 -- Add_Unique_Serial_Number --
57 ------------------------------
59 Config_Serial_Number
: Nat
:= 0;
60 -- Counter for use in config pragmas, see comment below
62 procedure Add_Unique_Serial_Number
is
64 -- If we are analyzing configuration pragmas, Cunit (Main_Unit) will
65 -- not be set yet. This happens for example when analyzing static
66 -- string expressions in configuration pragmas. For this case, we
67 -- just maintain a local counter, defined above and we do not need
68 -- to add a b or s indication in this case.
70 if No
(Cunit
(Current_Sem_Unit
)) then
71 Config_Serial_Number
:= Config_Serial_Number
+ 1;
72 Add_Nat_To_Name_Buffer
(Config_Serial_Number
);
75 -- Normal case, within a unit
79 Unit_Node
: constant Node_Id
:= Unit
(Cunit
(Current_Sem_Unit
));
82 Add_Nat_To_Name_Buffer
(Increment_Serial_Number
);
84 -- Add either b or s, depending on whether current unit is a spec
85 -- or a body. This is needed because we may generate the same name
86 -- in a spec and a body otherwise.
88 Name_Len
:= Name_Len
+ 1;
90 if Nkind
(Unit_Node
) = N_Package_Declaration
91 or else Nkind
(Unit_Node
) = N_Subprogram_Declaration
92 or else Nkind
(Unit_Node
) in N_Generic_Declaration
94 Name_Buffer
(Name_Len
) := 's';
96 Name_Buffer
(Name_Len
) := 'b';
100 end Add_Unique_Serial_Number
;
106 function Checks_Off
(N
: Node_Id
) return Node_Id
is
109 Make_Unchecked_Expression
(Sloc
(N
),
117 function Convert_To
(Typ
: Entity_Id
; Expr
: Node_Id
) return Node_Id
is
118 pragma Assert
(Is_Type
(Typ
));
122 if Present
(Etype
(Expr
)) and then Etype
(Expr
) = Typ
then
123 return Relocate_Node
(Expr
);
127 Make_Type_Conversion
(Sloc
(Expr
),
128 Subtype_Mark
=> New_Occurrence_Of
(Typ
, Sloc
(Expr
)),
129 Expression
=> Relocate_Node
(Expr
));
131 Set_Etype
(Result
, Typ
);
136 ----------------------------
137 -- Convert_To_And_Rewrite --
138 ----------------------------
140 procedure Convert_To_And_Rewrite
(Typ
: Entity_Id
; Expr
: Node_Id
) is
142 Rewrite
(Expr
, Convert_To
(Typ
, Expr
));
143 end Convert_To_And_Rewrite
;
149 procedure Discard_List
(L
: List_Id
) is
150 pragma Warnings
(Off
, L
);
159 procedure Discard_Node
(N
: Node_Or_Entity_Id
) is
160 pragma Warnings
(Off
, N
);
165 -------------------------------------------
166 -- Make_Byte_Aligned_Attribute_Reference --
167 -------------------------------------------
169 function Make_Byte_Aligned_Attribute_Reference
172 Attribute_Name
: Name_Id
)
175 N
: constant Node_Id
:=
176 Make_Attribute_Reference
(Sloc
,
178 Attribute_Name
=> Attribute_Name
);
182 (Attribute_Name
in Name_Address | Name_Unrestricted_Access
);
183 Set_Must_Be_Byte_Aligned
(N
, True);
185 end Make_Byte_Aligned_Attribute_Reference
;
187 ------------------------
188 -- Make_Float_Literal --
189 ------------------------
191 function Make_Float_Literal
195 Exponent
: Uint
) return Node_Id
198 if Radix
= 2 and then abs Significand
/= 1 then
202 Significand
* Radix
**(Exponent
mod 4),
207 N
: constant Node_Id
:= New_Node
(N_Real_Literal
, Loc
);
212 (Num
=> abs Significand
,
214 Rbase
=> UI_To_Int
(Radix
),
215 Negative
=> Significand
< 0));
219 end Make_Float_Literal
;
225 function Make_Id
(Str
: Text_Buffer
) return Node_Id
is
229 for J
in Str
'Range loop
230 Name_Len
:= Name_Len
+ 1;
231 Name_Buffer
(Name_Len
) := Fold_Lower
(Str
(J
));
235 Make_Identifier
(System_Location
,
239 -------------------------------------
240 -- Make_Implicit_Exception_Handler --
241 -------------------------------------
243 function Make_Implicit_Exception_Handler
245 Choice_Parameter
: Node_Id
:= Empty
;
246 Exception_Choices
: List_Id
;
247 Statements
: List_Id
) return Node_Id
253 -- Set the source location only when debugging the expanded code
255 -- When debugging the source code directly, we do not want the compiler
256 -- to associate this implicit exception handler with any specific source
257 -- line, because it can potentially confuse the debugger. The most
258 -- damaging situation would arise when the debugger tries to insert a
259 -- breakpoint at a certain line. If the code of the associated implicit
260 -- exception handler is generated before the code of that line, then the
261 -- debugger will end up inserting the breakpoint inside the exception
262 -- handler, rather than the code the user intended to break on. As a
263 -- result, it is likely that the program will not hit the breakpoint
266 if Debug_Generated_Code
then
273 Make_Exception_Handler
274 (Loc
, Choice_Parameter
, Exception_Choices
, Statements
);
275 Set_Local_Raise_Statements
(Handler
, No_Elist
);
277 end Make_Implicit_Exception_Handler
;
279 --------------------------------
280 -- Make_Implicit_If_Statement --
281 --------------------------------
283 function Make_Implicit_If_Statement
286 Then_Statements
: List_Id
;
287 Elsif_Parts
: List_Id
:= No_List
;
288 Else_Statements
: List_Id
:= No_List
) return Node_Id
291 Check_Restriction
(No_Implicit_Conditionals
, Node
);
293 return Make_If_Statement
(Sloc
(Node
),
298 end Make_Implicit_If_Statement
;
300 -------------------------------------
301 -- Make_Implicit_Label_Declaration --
302 -------------------------------------
304 function Make_Implicit_Label_Declaration
306 Defining_Identifier
: Node_Id
;
307 Label_Construct
: Node_Id
) return Node_Id
309 N
: constant Node_Id
:=
310 Make_Implicit_Label_Declaration
(Loc
, Defining_Identifier
);
312 Set_Label_Construct
(N
, Label_Construct
);
314 end Make_Implicit_Label_Declaration
;
316 ----------------------------------
317 -- Make_Implicit_Loop_Statement --
318 ----------------------------------
320 function Make_Implicit_Loop_Statement
322 Statements
: List_Id
;
323 Identifier
: Node_Id
:= Empty
;
324 Iteration_Scheme
: Node_Id
:= Empty
;
325 Has_Created_Identifier
: Boolean := False;
326 End_Label
: Node_Id
:= Empty
) return Node_Id
329 Check_Restrictions
: Boolean := True;
331 -- Do not check restrictions if the implicit loop statement is part
332 -- of a dead branch: False and then ...
333 -- This will occur in particular as part of the expansion of pragma
334 -- Assert when assertions are disabled.
337 while Present
(P
) loop
338 if Nkind
(P
) = N_And_Then
then
339 if Nkind
(Left_Opnd
(P
)) = N_Identifier
340 and then Entity
(Left_Opnd
(P
)) = Standard_False
342 Check_Restrictions
:= False;
346 -- Prevent the search from going too far
348 elsif Is_Body_Or_Package_Declaration
(P
) then
355 if Check_Restrictions
then
356 Check_Restriction
(No_Implicit_Loops
, Node
);
358 if Present
(Iteration_Scheme
)
359 and then Nkind
(Iteration_Scheme
) /= N_Iterator_Specification
360 and then Present
(Condition
(Iteration_Scheme
))
362 Check_Restriction
(No_Implicit_Conditionals
, Node
);
366 return Make_Loop_Statement
(Sloc
(Node
),
367 Identifier
=> Identifier
,
368 Iteration_Scheme
=> Iteration_Scheme
,
369 Statements
=> Statements
,
370 Has_Created_Identifier
=> Has_Created_Identifier
,
371 End_Label
=> End_Label
);
372 end Make_Implicit_Loop_Statement
;
378 function Make_Increment
379 (Loc
: Source_Ptr
; Index
: Entity_Id
; Typ
: Entity_Id
) return Node_Id
is
381 return Make_Assignment_Statement
(Loc
,
382 Name
=> New_Occurrence_Of
(Index
, Loc
),
384 Make_Attribute_Reference
(Loc
,
386 New_Occurrence_Of
(Typ
, Loc
),
387 Attribute_Name
=> Name_Succ
,
388 Expressions
=> New_List
(
389 New_Occurrence_Of
(Index
, Loc
))));
392 --------------------------
393 -- Make_Integer_Literal --
394 ---------------------------
396 function Make_Integer_Literal
398 Intval
: Int
) return Node_Id
401 return Make_Integer_Literal
(Loc
, UI_From_Int
(Intval
));
402 end Make_Integer_Literal
;
404 --------------------------------
405 -- Make_Linker_Section_Pragma --
406 --------------------------------
408 function Make_Linker_Section_Pragma
411 Sec
: String) return Node_Id
421 (Make_Pragma_Argument_Association
423 Expression
=> New_Occurrence_Of
(Ent
, Loc
)),
424 Make_Pragma_Argument_Association
431 Set_Has_Gigi_Rep_Item
(Ent
);
433 end Make_Linker_Section_Pragma
;
442 Pragma_Argument_Associations
: List_Id
:= No_List
) return Node_Id
447 Pragma_Argument_Associations
=> Pragma_Argument_Associations
,
448 Pragma_Identifier
=> Make_Identifier
(Sloc
, Chars
));
451 ---------------------------------
452 -- Make_Raise_Constraint_Error --
453 ---------------------------------
455 function Make_Raise_Constraint_Error
457 Condition
: Node_Id
:= Empty
;
458 Reason
: RT_Exception_Code
) return Node_Id
461 pragma Assert
(Rkind
(Reason
) = CE_Reason
);
463 Make_Raise_Constraint_Error
(Sloc
,
464 Condition
=> Condition
,
465 Reason
=> UI_From_Int
(RT_Exception_Code
'Pos (Reason
)));
466 end Make_Raise_Constraint_Error
;
468 ------------------------------
469 -- Make_Raise_Program_Error --
470 ------------------------------
472 function Make_Raise_Program_Error
474 Condition
: Node_Id
:= Empty
;
475 Reason
: RT_Exception_Code
) return Node_Id
478 pragma Assert
(Rkind
(Reason
) = PE_Reason
);
480 Make_Raise_Program_Error
(Sloc
,
481 Condition
=> Condition
,
482 Reason
=> UI_From_Int
(RT_Exception_Code
'Pos (Reason
)));
483 end Make_Raise_Program_Error
;
485 ------------------------------
486 -- Make_Raise_Storage_Error --
487 ------------------------------
489 function Make_Raise_Storage_Error
491 Condition
: Node_Id
:= Empty
;
492 Reason
: RT_Exception_Code
) return Node_Id
495 pragma Assert
(Rkind
(Reason
) = SE_Reason
);
497 Make_Raise_Storage_Error
(Sloc
,
498 Condition
=> Condition
,
499 Reason
=> UI_From_Int
(RT_Exception_Code
'Pos (Reason
)));
500 end Make_Raise_Storage_Error
;
506 function Make_SC
(Pre
, Sel
: Node_Id
) return Node_Id
is
509 Make_Selected_Component
(System_Location
,
511 Selector_Name
=> Sel
);
514 -------------------------
515 -- Make_String_Literal --
516 -------------------------
518 function Make_String_Literal
520 Strval
: String) return Node_Id
524 Store_String_Chars
(Strval
);
525 return Make_String_Literal
(Sloc
, Strval
=> End_String
);
526 end Make_String_Literal
;
528 -------------------------
529 -- Make_Suppress_Block --
530 -------------------------
532 -- Generates the following expansion:
535 -- pragma Suppress (<check>);
540 function Make_Suppress_Block
543 Stmts
: List_Id
) return Node_Id
547 Make_Block_Statement
(Loc
,
548 Declarations
=> New_List
(
550 Chars
=> Name_Suppress
,
551 Pragma_Argument_Associations
=> New_List
(
552 Make_Pragma_Argument_Association
(Loc
,
553 Expression
=> Make_Identifier
(Loc
, Check
))))),
555 Handled_Statement_Sequence
=>
556 Make_Handled_Sequence_Of_Statements
(Loc
,
557 Statements
=> Stmts
));
558 end Make_Suppress_Block
;
564 function Make_Temporary
567 Related_Node
: Node_Id
:= Empty
) return Entity_Id
569 Temp
: constant Entity_Id
:=
570 Make_Defining_Identifier
(Loc
, Chars
=> New_Internal_Name
(Id
));
572 Set_Related_Expression
(Temp
, Related_Node
);
576 ---------------------------
577 -- Make_Unsuppress_Block --
578 ---------------------------
580 -- Generates the following expansion:
583 -- pragma Unsuppress (<check>);
588 function Make_Unsuppress_Block
591 Stmts
: List_Id
) return Node_Id
595 Make_Block_Statement
(Loc
,
596 Declarations
=> New_List
(
598 Chars
=> Name_Unsuppress
,
599 Pragma_Argument_Associations
=> New_List
(
600 Make_Pragma_Argument_Association
(Loc
,
601 Expression
=> Make_Identifier
(Loc
, Check
))))),
603 Handled_Statement_Sequence
=>
604 Make_Handled_Sequence_Of_Statements
(Loc
,
605 Statements
=> Stmts
));
606 end Make_Unsuppress_Block
;
608 --------------------------
609 -- New_Constraint_Error --
610 --------------------------
612 function New_Constraint_Error
(Loc
: Source_Ptr
) return Node_Id
is
613 Ident_Node
: Node_Id
;
614 Raise_Node
: Node_Id
;
617 Ident_Node
:= New_Node
(N_Identifier
, Loc
);
618 Set_Chars
(Ident_Node
, Chars
(Standard_Entity
(S_Constraint_Error
)));
619 Set_Entity
(Ident_Node
, Standard_Entity
(S_Constraint_Error
));
620 Raise_Node
:= New_Node
(N_Raise_Statement
, Loc
);
621 Set_Name
(Raise_Node
, Ident_Node
);
623 end New_Constraint_Error
;
625 -----------------------
626 -- New_External_Name --
627 -----------------------
629 function New_External_Name
630 (Related_Id
: Name_Id
;
631 Suffix
: Character := ' ';
632 Suffix_Index
: Int
:= 0;
633 Prefix
: Character := ' ') return Name_Id
636 Get_Name_String
(Related_Id
);
638 if Prefix
/= ' ' then
639 pragma Assert
(Is_OK_Internal_Letter
(Prefix
) or else Prefix
= '_');
641 for J
in reverse 1 .. Name_Len
loop
642 Name_Buffer
(J
+ 1) := Name_Buffer
(J
);
645 Name_Len
:= Name_Len
+ 1;
646 Name_Buffer
(1) := Prefix
;
649 if Suffix
/= ' ' then
650 pragma Assert
(Is_OK_Internal_Letter
(Suffix
));
651 Add_Char_To_Name_Buffer
(Suffix
);
654 if Suffix_Index
/= 0 then
655 if Suffix_Index
< 0 then
656 Add_Unique_Serial_Number
;
658 Add_Nat_To_Name_Buffer
(Suffix_Index
);
663 end New_External_Name
;
665 function New_External_Name
666 (Related_Id
: Name_Id
;
668 Suffix_Index
: Int
:= 0;
669 Prefix
: Character := ' ') return Name_Id
672 Get_Name_String
(Related_Id
);
674 if Prefix
/= ' ' then
675 pragma Assert
(Is_OK_Internal_Letter
(Prefix
));
677 for J
in reverse 1 .. Name_Len
loop
678 Name_Buffer
(J
+ 1) := Name_Buffer
(J
);
681 Name_Len
:= Name_Len
+ 1;
682 Name_Buffer
(1) := Prefix
;
686 Name_Buffer
(Name_Len
+ 1 .. Name_Len
+ Suffix
'Length) := Suffix
;
687 Name_Len
:= Name_Len
+ Suffix
'Length;
690 if Suffix_Index
/= 0 then
691 if Suffix_Index
< 0 then
692 Add_Unique_Serial_Number
;
694 Add_Nat_To_Name_Buffer
(Suffix_Index
);
699 end New_External_Name
;
701 function New_External_Name
703 Suffix_Index
: Nat
) return Name_Id
706 Name_Buffer
(1) := Suffix
;
708 Add_Nat_To_Name_Buffer
(Suffix_Index
);
710 end New_External_Name
;
712 -----------------------
713 -- New_Internal_Name --
714 -----------------------
716 function New_Internal_Name
(Id_Char
: Character) return Name_Id
is
718 pragma Assert
(Is_OK_Internal_Letter
(Id_Char
));
719 Name_Buffer
(1) := Id_Char
;
721 Add_Unique_Serial_Number
;
723 end New_Internal_Name
;
725 -----------------------
726 -- New_Occurrence_Of --
727 -----------------------
729 function New_Occurrence_Of
731 Loc
: Source_Ptr
) return Node_Id
733 pragma Assert
(Present
(Def_Id
) and then Nkind
(Def_Id
) in N_Entity
);
734 Occurrence
: constant Node_Id
:=
735 Make_Identifier
(Loc
, Chars
(Def_Id
));
738 Set_Entity
(Occurrence
, Def_Id
);
740 if Is_Type
(Def_Id
) then
741 Set_Etype
(Occurrence
, Def_Id
);
743 Set_Etype
(Occurrence
, Etype
(Def_Id
));
746 if Ekind
(Def_Id
) = E_Enumeration_Literal
then
747 Set_Is_Static_Expression
(Occurrence
, True);
751 end New_Occurrence_Of
;
758 (New_Node_Kind
: Node_Kind
;
759 New_Sloc
: Source_Ptr
) return Node_Id
761 type Name_Of_Type
is array (N_Op
) of Name_Id
;
762 Name_Of
: constant Name_Of_Type
:= Name_Of_Type
'(
763 N_Op_And => Name_Op_And,
764 N_Op_Or => Name_Op_Or,
765 N_Op_Xor => Name_Op_Xor,
766 N_Op_Eq => Name_Op_Eq,
767 N_Op_Ne => Name_Op_Ne,
768 N_Op_Lt => Name_Op_Lt,
769 N_Op_Le => Name_Op_Le,
770 N_Op_Gt => Name_Op_Gt,
771 N_Op_Ge => Name_Op_Ge,
772 N_Op_Add => Name_Op_Add,
773 N_Op_Subtract => Name_Op_Subtract,
774 N_Op_Concat => Name_Op_Concat,
775 N_Op_Multiply => Name_Op_Multiply,
776 N_Op_Divide => Name_Op_Divide,
777 N_Op_Mod => Name_Op_Mod,
778 N_Op_Rem => Name_Op_Rem,
779 N_Op_Expon => Name_Op_Expon,
780 N_Op_Plus => Name_Op_Add,
781 N_Op_Minus => Name_Op_Subtract,
782 N_Op_Abs => Name_Op_Abs,
783 N_Op_Not => Name_Op_Not,
785 -- We don't really need these shift operators, since they never
786 -- appear as operators in the source, but the path of least
787 -- resistance is to put them in (the aggregate must be complete).
789 N_Op_Rotate_Left => Name_Rotate_Left,
790 N_Op_Rotate_Right => Name_Rotate_Right,
791 N_Op_Shift_Left => Name_Shift_Left,
792 N_Op_Shift_Right => Name_Shift_Right,
793 N_Op_Shift_Right_Arithmetic => Name_Shift_Right_Arithmetic);
795 Nod : constant Node_Id := New_Node (New_Node_Kind, New_Sloc);
798 if New_Node_Kind in Name_Of'Range then
799 Set_Chars (Nod, Name_Of (New_Node_Kind));
805 -----------------------
806 -- New_Suffixed_Name --
807 -----------------------
809 function New_Suffixed_Name
810 (Related_Id : Name_Id;
811 Suffix : String) return Name_Id
814 Get_Name_String (Related_Id);
815 Add_Char_To_Name_Buffer ('_
');
816 Add_Str_To_Name_Buffer (Suffix);
818 end New_Suffixed_Name;
824 function OK_Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id is
828 Make_Type_Conversion (Sloc (Expr),
829 Subtype_Mark => New_Occurrence_Of (Typ, Sloc (Expr)),
830 Expression => Relocate_Node (Expr));
831 Set_Conversion_OK (Result, True);
832 Set_Etype (Result, Typ);
840 function Sel_Comp (Pre : Node_Id; Sel : String) return Node_Id is
842 return Make_Selected_Component
845 Selector_Name => Make_Identifier (Sloc (Pre), Name_Find (Sel)));
848 function Sel_Comp (Pre, Sel : String; Loc : Source_Ptr) return Node_Id is
850 return Sel_Comp (Make_Identifier (Loc, Name_Find (Pre)), Sel);
857 procedure Set_NOD (Unit : Node_Id) is
859 Set_Restriction_No_Dependence (Unit, Warn => False);
866 procedure Set_NSA (Asp : Name_Id; OK : out Boolean) is
867 Asp_Id : constant Aspect_Id := Get_Aspect_Id (Asp);
869 if Asp_Id = No_Aspect then
873 Set_Restriction_No_Specification_Of_Aspect (Asp_Id);
881 procedure Set_NUA (Attr : Name_Id; OK : out Boolean) is
883 if Is_Attribute_Name (Attr) then
885 Set_Restriction_No_Use_Of_Attribute (Get_Attribute_Id (Attr));
895 procedure Set_NUP (Prag : Name_Id; OK : out Boolean) is
897 if Is_Pragma_Name (Prag) then
899 Set_Restriction_No_Use_Of_Pragma (Get_Pragma_Id (Prag));
905 --------------------------
906 -- Unchecked_Convert_To --
907 --------------------------
909 function Unchecked_Convert_To
911 Expr : Node_Id) return Node_Id
913 pragma Assert (Ekind (Typ) in E_Void | Type_Kind);
914 -- We don't really want to allow E_Void here, but existing code passes
917 Loc : constant Source_Ptr := Sloc (Expr);
921 -- If the expression is already of the correct type, then nothing
922 -- to do, except for relocating the node
924 if Present (Etype (Expr))
925 and then (Base_Type (Etype (Expr)) = Typ or else Etype (Expr) = Typ)
927 return Relocate_Node (Expr);
929 -- Case where the expression is already an unchecked conversion. We
930 -- replace the type being converted to, to avoid creating an unchecked
931 -- conversion of an unchecked conversion. Extra unchecked conversions
932 -- make the .dg output less readable. We can't do this in cases
933 -- involving bitfields, because the sizes might not match. The
934 -- Is_Composite_Type checks avoid such cases.
936 elsif Nkind (Expr) = N_Unchecked_Type_Conversion
937 and then Is_Composite_Type (Etype (Expr))
938 and then Is_Composite_Type (Typ)
940 Set_Subtype_Mark (Expr, New_Occurrence_Of (Typ, Loc));
941 Result := Relocate_Node (Expr);
943 elsif Nkind (Expr) = N_Null
944 and then Is_Access_Type (Typ)
946 -- No need for a conversion
948 Result := Relocate_Node (Expr);
954 Expr_Parent : constant Node_Id := Parent (Expr);
957 Make_Unchecked_Type_Conversion (Loc,
958 Subtype_Mark => New_Occurrence_Of (Typ, Loc),
959 Expression => Relocate_Node (Expr));
960 Set_Parent (Result, Expr_Parent);
964 Set_Etype (Result, Typ);
966 end Unchecked_Convert_To;