public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Suppress_Initialization not respected for private subtypes
@ 2019-08-12  9:10 Pierre-Marie de Rodat
  0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2019-08-12  9:10 UTC (permalink / raw)
  To: gcc-patches; +Cc: Gary Dismukes

[-- Attachment #1: Type: text/plain, Size: 774 bytes --]

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).

Tested on x86_64-pc-linux-gnu, committed on trunk

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.

[-- Attachment #2: patch.diff --]
[-- Type: text/x-diff, Size: 1075 bytes --]

--- gcc/ada/sem_prag.adb
+++ gcc/ada/sem_prag.adb
@@ -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

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/suppress_initialization2.adb
@@ -0,0 +1,5 @@
+package body Suppress_Initialization2 is
+
+   procedure Dummy is null;
+
+end Suppress_Initialization2;

--- /dev/null
new file mode 100644
+++ gcc/testsuite/gnat.dg/suppress_initialization2.ads
@@ -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;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-12  9:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12  9:10 [Ada] Suppress_Initialization not respected for private subtypes Pierre-Marie de Rodat

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).