]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Ada: Fix assertion failure for Finalizable aspect on tagged type
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 1 Jul 2025 17:17:06 +0000 (19:17 +0200)
committerEric Botcazou <ebotcazou@adacore.com>
Tue, 1 Jul 2025 17:18:46 +0000 (19:18 +0200)
This fixes an assertion failure for the Finalizable aspect applied on a
tagged type with discriminant-dependent component.

gcc/ada/
PR ada/120705
* exp_ch6.adb (Needs_BIP_Collection): Always return False if the
type has relaxed finalization.

gcc/testsuite/
* gnat.dg/specs/finalizable2.ads: New test.

gcc/ada/exp_ch6.adb
gcc/testsuite/gnat.dg/specs/finalizable2.ads [new file with mode: 0644]

index 26302baad649a3dab86c6ef174815ef5f6baea1d..621619220a0b514a66d1e14be9dce764fd6eb3d2 100644 (file)
@@ -9575,9 +9575,8 @@ package body Exp_Ch6 is
       --  such build-in-place functions, primitive or not.
 
       return not Restriction_Active (No_Finalization)
-        and then ((Needs_Finalization (Typ)
-                    and then not Has_Relaxed_Finalization (Typ))
-                  or else Is_Tagged_Type (Typ))
+        and then (Needs_Finalization (Typ) or else Is_Tagged_Type (Typ))
+        and then not Has_Relaxed_Finalization (Typ)
         and then not Has_Foreign_Convention (Typ);
    end Needs_BIP_Collection;
 
diff --git a/gcc/testsuite/gnat.dg/specs/finalizable2.ads b/gcc/testsuite/gnat.dg/specs/finalizable2.ads
new file mode 100644 (file)
index 0000000..b4a6bb1
--- /dev/null
@@ -0,0 +1,21 @@
+-- { dg-do compile }
+-- { dg-options "-gnatX0" }
+
+package Finalizable2 is
+
+   type Root is abstract tagged limited null record
+      with Finalizable => (Initialize => Initialize);
+
+   procedure Initialize (this : in out Root) is abstract;
+
+   type Ext (L : Natural) is new Root with record
+      A : String (1 .. L);
+   end record;
+
+   overriding procedure Initialize (this : in out Ext) is null;
+
+   function Make return Ext is (L => 3, A => "asd");
+
+   Obj : Ext := Make;
+
+end Finalizable2;