aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/tbuild.adb
diff options
context:
space:
mode:
authorBob Duff <duff@adacore.com>2021-05-08 11:39:52 -0400
committerPierre-Marie de Rodat <derodat@adacore.com>2021-07-06 14:46:54 +0000
commit82a794419a00ea98b68d69b64363ae6746710de9 (patch)
treea216a476635457a50b68eac80396d690071b19a4 /gcc/ada/tbuild.adb
parent06a5fb60eb53ef297454f58db61d3374d538f515 (diff)
downloadgcc-82a794419a00ea98b68d69b64363ae6746710de9.zip
gcc-82a794419a00ea98b68d69b64363ae6746710de9.tar.gz
gcc-82a794419a00ea98b68d69b64363ae6746710de9.tar.bz2
[Ada] Tbuild cleanup
gcc/ada/ * tbuild.adb (Convert_To): Add assert, along with a comment. (Make_DT_Access): Remove this function, which is not used. It was incorrect anyway (the call to New_Occurrence_Of should not be there). (Unchecked_Convert_To): Add assert. The previous version's test for unchecked conversion to the same type was redundant and could never be true, because the previous 'if' already checked for ANY expression of the same type. Remove that, and replace with a test for unchecked conversion to a related type. Otherwise, we somethings get things like "finalize(some_type!(some_type!(x)))" in the generated code, where x is already of type some_type, but we're converting it to the private type and then to the full type or vice versa (so the types aren't equal, so the previous 'if' doesn't catch it). Avoid updating the Parent. This is not necessary; the Parent will be updated if/when the node is attached to the tree. * tbuild.ads: Fix comments. No need to say "this is safe" when we just explained that a few lines earlier. Remove Make_DT_Access. * sinfo.ads: Add comments. * exp_ch7.adb (Make_Finalize_Address_Stmts): Minor comment fix. * gen_il-gen.adb, gen_il-gen.ads, gen_il-gen-gen_nodes.adb, gen_il-internals.ads: Implement a feature where you can put: Nmake_Assert => "expr" where expr is a boolean expression in a call to Create_Concrete_Node_Type. It is added in a pragma Assert in the Nmake.Make_... function for that type.
Diffstat (limited to 'gcc/ada/tbuild.adb')
-rw-r--r--gcc/ada/tbuild.adb59
1 files changed, 16 insertions, 43 deletions
diff --git a/gcc/ada/tbuild.adb b/gcc/ada/tbuild.adb
index 4c53cdb..e718644 100644
--- a/gcc/ada/tbuild.adb
+++ b/gcc/ada/tbuild.adb
@@ -29,14 +29,12 @@ with Csets; use Csets;
with Einfo; use Einfo;
with Einfo.Entities; use Einfo.Entities;
with Einfo.Utils; use Einfo.Utils;
-with Elists; use Elists;
with Lib; use Lib;
with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Restrict; use Restrict;
with Rident; use Rident;
-with Sem_Aux; use Sem_Aux;
with Sinfo.Utils; use Sinfo.Utils;
with Sem_Util; use Sem_Util;
with Snames; use Snames;
@@ -117,6 +115,7 @@ package body Tbuild is
----------------
function Convert_To (Typ : Entity_Id; Expr : Node_Id) return Node_Id is
+ pragma Assert (Is_Type (Typ));
Result : Node_Id;
begin
@@ -185,32 +184,6 @@ package body Tbuild is
return N;
end Make_Byte_Aligned_Attribute_Reference;
- --------------------
- -- Make_DT_Access --
- --------------------
-
- function Make_DT_Access
- (Loc : Source_Ptr;
- Rec : Node_Id;
- Typ : Entity_Id) return Node_Id
- is
- Full_Type : Entity_Id := Typ;
-
- begin
- if Is_Private_Type (Typ) then
- Full_Type := Underlying_Type (Typ);
- end if;
-
- return
- Unchecked_Convert_To (
- New_Occurrence_Of
- (Etype (Node (First_Elmt (Access_Disp_Table (Full_Type)))), Loc),
- Make_Selected_Component (Loc,
- Prefix => New_Copy (Rec),
- Selector_Name =>
- New_Occurrence_Of (First_Tag_Component (Full_Type), Loc)));
- end Make_DT_Access;
-
------------------------
-- Make_Float_Literal --
------------------------
@@ -906,26 +879,34 @@ package body Tbuild is
(Typ : Entity_Id;
Expr : Node_Id) return Node_Id
is
+ pragma Assert (Ekind (Typ) in E_Void | Type_Kind);
+ -- We don't really want to allow E_Void here, but existing code passes
+ -- it.
+
Loc : constant Source_Ptr := Sloc (Expr);
Result : Node_Id;
- Expr_Parent : Node_Id;
begin
-- If the expression is already of the correct type, then nothing
- -- to do, except for relocating the node in case this is required.
+ -- to do, except for relocating the node
if Present (Etype (Expr))
- and then (Base_Type (Etype (Expr)) = Typ
- or else Etype (Expr) = Typ)
+ and then (Base_Type (Etype (Expr)) = Typ or else Etype (Expr) = Typ)
then
return Relocate_Node (Expr);
- -- Case where the expression is itself an unchecked conversion to
- -- the same type, and we can thus eliminate the outer conversion.
+ -- Case where the expression is already an unchecked conversion. We
+ -- replace the type being converted to, to avoid creating an unchecked
+ -- conversion of an unchecked conversion. Extra unchecked conversions
+ -- make the .dg output less readable. We can't do this in cases
+ -- involving bitfields, because the sizes might not match. The
+ -- Is_Composite_Type checks avoid such cases.
elsif Nkind (Expr) = N_Unchecked_Type_Conversion
- and then Entity (Subtype_Mark (Expr)) = Typ
+ and then Is_Composite_Type (Etype (Expr))
+ and then Is_Composite_Type (Typ)
then
+ Set_Subtype_Mark (Expr, New_Occurrence_Of (Typ, Loc));
Result := Relocate_Node (Expr);
elsif Nkind (Expr) = N_Null
@@ -938,18 +919,10 @@ package body Tbuild is
-- All other cases
else
- -- Capture the parent of the expression before relocating it and
- -- creating the conversion, so the conversion's parent can be set
- -- to the original parent below.
-
- Expr_Parent := Parent (Expr);
-
Result :=
Make_Unchecked_Type_Conversion (Loc,
Subtype_Mark => New_Occurrence_Of (Typ, Loc),
Expression => Relocate_Node (Expr));
-
- Set_Parent (Result, Expr_Parent);
end if;
Set_Etype (Result, Typ);