[Ada] Suppress_Initialization not respected for private subtypes
authorGary Dismukes <dismukes@adacore.com>
Mon, 12 Aug 2019 08:59:58 +0000 (08:59 +0000)
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>
Mon, 12 Aug 2019 08:59:58 +0000 (08:59 +0000)
The compiler fails to suppress initialization on a variable of a subtype
of a private type (such as System.Address) even though the subtype has
aspect Suppress_Initialization. This can lead to errors on object
declarations specified with Thread_Local_Storage when Initialize_Scalars
is applied (as well as leading to default initialization when it
shouldn't).

2019-08-12  Gary Dismukes  <dismukes@adacore.com>

gcc/ada/

* sem_prag.adb (Analyze_Pragma, Pragma_Suppress_Initialization):
For private types, set the Suppress_Initialization flag on the
Full_View of the entity rather than the entity's base type.

gcc/testsuite/

* gnat.dg/suppress_initialization2.adb,
gnat.dg/suppress_initialization2.ads: New testcase.

From-SVN: r274293

gcc/ada/ChangeLog
gcc/ada/sem_prag.adb
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/suppress_initialization2.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/suppress_initialization2.ads [new file with mode: 0644]

index 78d78ccf08570fc0c58fb79dca75157be1b841f8..4e76edffc17986219099f65f49d1538e3748582d 100644 (file)
@@ -1,3 +1,9 @@
+2019-08-12  Gary Dismukes  <dismukes@adacore.com>
+
+       * sem_prag.adb (Analyze_Pragma, Pragma_Suppress_Initialization):
+       For private types, set the Suppress_Initialization flag on the
+       Full_View of the entity rather than the entity's base type.
+
 2019-08-12  Yannick Moy  <moy@adacore.com>
 
        * aspects.adb, aspects.ads (Aspect_No_Caching): New aspect.
index 599ac4c963f9ed55995caf37e8aa7672278fe1f2..30b6088798f658fd75f3914b1a24699de5c7c4ea 100644 (file)
@@ -24169,7 +24169,7 @@ package body Sem_Prag is
                   Error_Pragma_Arg
                     ("argument of pragma% cannot be an incomplete type", Arg1);
                else
-                  Set_Suppress_Initialization (Full_View (Base_Type (E)));
+                  Set_Suppress_Initialization (Full_View (E));
                end if;
 
             --  For first subtype, set flag on base type
index c7ee99716d7a55421427142dbf90f0ae27c0ae0c..2918943d1aa965c632a2ab42e8560c539ff89d9f 100644 (file)
@@ -1,3 +1,8 @@
+2019-08-12  Gary Dismukes  <dismukes@adacore.com>
+
+       * gnat.dg/suppress_initialization2.adb,
+       gnat.dg/suppress_initialization2.ads: New testcase.
+
 2019-08-12  Yannick Moy  <moy@adacore.com>
 
        * gnat.dg/no_caching.adb, gnat.dg/no_caching.ads: New testcase.
diff --git a/gcc/testsuite/gnat.dg/suppress_initialization2.adb b/gcc/testsuite/gnat.dg/suppress_initialization2.adb
new file mode 100644 (file)
index 0000000..a54272e
--- /dev/null
@@ -0,0 +1,5 @@
+package body Suppress_Initialization2 is
+
+   procedure Dummy is null;
+
+end Suppress_Initialization2;
diff --git a/gcc/testsuite/gnat.dg/suppress_initialization2.ads b/gcc/testsuite/gnat.dg/suppress_initialization2.ads
new file mode 100644 (file)
index 0000000..2594ab1
--- /dev/null
@@ -0,0 +1,13 @@
+pragma Initialize_Scalars;
+
+with System;
+
+package Suppress_Initialization2 is
+
+   subtype Sub_Addr is System.Address with Suppress_Initialization;
+
+   O : Sub_Addr with Thread_Local_Storage;  -- OK: no error should be reported
+
+   procedure Dummy;
+
+end Suppress_Initialization2;