From: Eric Botcazou <ebotca...@adacore.com>

The instantiation triggers an internal error in Gigi because of a dangling
ghost entity created by the finalization machinery.

gcc/ada/ChangeLog:

        PR ada/114300
        * exp_ch7.adb (Attach_Object_To_Master_Node): Propagate the
        Is_Ignored_Ghost_Entity flag from the finalization procedure.
        (Build_Finalizer.Process_Declarations): Move up the test on
        Is_Ignored_Ghost_Entity.
        * exp_util.adb (Requires_Cleanup_Actions): Likewise.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/exp_ch7.adb  | 17 +++++++++++------
 gcc/ada/exp_util.adb | 12 ++++++------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/gcc/ada/exp_ch7.adb b/gcc/ada/exp_ch7.adb
index f6c243086b1..e7bf0bd7f11 100644
--- a/gcc/ada/exp_ch7.adb
+++ b/gcc/ada/exp_ch7.adb
@@ -986,6 +986,11 @@ package body Exp_Ch7 is
 
       Set_Finalize_Address_For_Node (Master_Node, Fin_Id);
 
+      --  Propagate the Ghost policy from the procedure to the node
+
+      Set_Is_Ignored_Ghost_Entity
+        (Master_Node, Is_Ignored_Ghost_Entity (Fin_Id));
+
       Insert_After_And_Analyze
         (Master_Node_Ins, Master_Node_Attach, Suppress => All_Checks);
    end Attach_Object_To_Master_Node;
@@ -2529,6 +2534,12 @@ package body Exp_Ch7 is
                elsif Is_Ignored_For_Finalization (Obj_Id) then
                   null;
 
+               --  Ignored Ghost objects do not need any cleanup actions
+               --  because they will not appear in the final tree.
+
+               elsif Is_Ignored_Ghost_Entity (Obj_Id) then
+                  null;
+
                --  Conversely, if one of the above cases created a Master_Node,
                --  finalization actions are required for the associated object.
 
@@ -2537,12 +2548,6 @@ package body Exp_Ch7 is
                then
                   Processing_Actions (Decl);
 
-               --  Ignored Ghost objects do not need any cleanup actions
-               --  because they will not appear in the final tree.
-
-               elsif Is_Ignored_Ghost_Entity (Obj_Id) then
-                  null;
-
                --  The object is of the form:
                --    Obj : [constant] Typ [:= Expr];
 
diff --git a/gcc/ada/exp_util.adb b/gcc/ada/exp_util.adb
index 970af540e9c..df108918a74 100644
--- a/gcc/ada/exp_util.adb
+++ b/gcc/ada/exp_util.adb
@@ -13300,6 +13300,12 @@ package body Exp_Util is
             elsif Is_Ignored_For_Finalization (Obj_Id) then
                null;
 
+            --  Ignored Ghost objects do not need any cleanup actions because
+            --  they will not appear in the final tree.
+
+            elsif Is_Ignored_Ghost_Entity (Obj_Id) then
+               null;
+
             --  Conversely, if one of the above cases created a Master_Node,
             --  finalization actions are required for the associated object.
 
@@ -13308,12 +13314,6 @@ package body Exp_Util is
             then
                return True;
 
-            --  Ignored Ghost objects do not need any cleanup actions because
-            --  they will not appear in the final tree.
-
-            elsif Is_Ignored_Ghost_Entity (Obj_Id) then
-               null;
-
             --  The object is of the form:
             --    Obj : [constant] Typ [:= Expr];
             --
-- 
2.43.0

Reply via email to