aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada
diff options
context:
space:
mode:
authorEd Schonberg <schonberg@adacore.com>2018-05-30 08:58:27 +0000
committerPierre-Marie de Rodat <pmderodat@gcc.gnu.org>2018-05-30 08:58:27 +0000
commitd7db3f4f65563632493aa82c1cf12c7ed3f89eff (patch)
treeb86c167e1d1ba886d72b5d2fa6a449d906126372 /gcc/ada
parentf2a3c2fa828ced9f08597def430b3149ff9a4961 (diff)
downloadgcc-d7db3f4f65563632493aa82c1cf12c7ed3f89eff.zip
gcc-d7db3f4f65563632493aa82c1cf12c7ed3f89eff.tar.gz
gcc-d7db3f4f65563632493aa82c1cf12c7ed3f89eff.tar.bz2
[Ada] Extend the applicability of Thread_Local_Storage to composite types
This patch allows the GNAT-specific Thread_Local_Storage to be applied to variables of a composite type initiallized with an aggregate with static components that requires no elaboration code. 2018-05-30 Ed Schonberg <schonberg@adacore.com> gcc/ada/ * freeze.adb (Freeze_Object_Declaration): A pragma Thread_Local_Storage is now legal on a variable of composite type initialized with an aggregate that is fully static and requires no elaboration code. * exp_aggr.adb (Convert_To_Positional): Recognize additional cases of nested aggregates that are compile-time static, so they can be used to initialize variables declared with Threqd_Local_Storage. * doc/gnat_rm/implementation_defined_pragmas.rst: Add documentation on Thread_Local_Storage. * gnat_rm.texi: Regenerate. gcc/testsuite/ * gnat.dg/tls1.adb, gnat.dg/tls1_pkg.ads: New testcase. From-SVN: r260944
Diffstat (limited to 'gcc/ada')
-rw-r--r--gcc/ada/ChangeLog12
-rw-r--r--gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst12
-rw-r--r--gcc/ada/exp_aggr.adb18
-rw-r--r--gcc/ada/freeze.adb19
-rw-r--r--gcc/ada/gnat_rm.texi14
5 files changed, 60 insertions, 15 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog
index 258c4ac..f9a9eca 100644
--- a/gcc/ada/ChangeLog
+++ b/gcc/ada/ChangeLog
@@ -1,3 +1,15 @@
+2018-05-30 Ed Schonberg <schonberg@adacore.com>
+
+ * freeze.adb (Freeze_Object_Declaration): A pragma Thread_Local_Storage
+ is now legal on a variable of composite type initialized with an
+ aggregate that is fully static and requires no elaboration code.
+ * exp_aggr.adb (Convert_To_Positional): Recognize additional cases of
+ nested aggregates that are compile-time static, so they can be used to
+ initialize variables declared with Threqd_Local_Storage.
+ * doc/gnat_rm/implementation_defined_pragmas.rst: Add documentation on
+ Thread_Local_Storage.
+ * gnat_rm.texi: Regenerate.
+
2018-05-30 Yannick Moy <moy@adacore.com>
* sem_util.adb (Policy_In_Effect): Take into account CodePeer and
diff --git a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
index 353a9a5..aec0d84 100644
--- a/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
+++ b/gcc/ada/doc/gnat_rm/implementation_defined_pragmas.rst
@@ -6613,13 +6613,17 @@ Syntax:
This pragma specifies that the specified entity, which must be
a variable declared in a library-level package, is to be marked as
"Thread Local Storage" (``TLS``). On systems supporting this (which
-include Windows, Solaris, GNU/Linux and VxWorks 6), this causes each
+include Windows, Solaris, GNU/Linux, and VxWorks 6), this causes each
thread (and hence each Ada task) to see a distinct copy of the variable.
-The variable may not have default initialization, and if there is
+The variable must not have default initialization, and if there is
an explicit initialization, it must be either ``null`` for an
-access variable, or a static expression for a scalar variable.
-This provides a low level mechanism similar to that provided by
+access variable, a static expression for a scalar variable, or a fully
+static aggregate for a composite type, that is to say, an aggregate all
+of whose components are static, and which does not include packed or
+discriminated components.
+
+This provides a low-level mechanism similar to that provided by
the ``Ada.Task_Attributes`` package, but much more efficient
and is also useful in writing interface code that will interact
with foreign threads.
diff --git a/gcc/ada/exp_aggr.adb b/gcc/ada/exp_aggr.adb
index e01d374..e587c17 100644
--- a/gcc/ada/exp_aggr.adb
+++ b/gcc/ada/exp_aggr.adb
@@ -4727,7 +4727,25 @@ package body Exp_Aggr is
return;
end if;
+ -- A subaggregate may have been flattened but is not known to be
+ -- Compile_Time_Known. Set that flag in cases that cannot require
+ -- elaboration code, so that the aggregate can be used as the
+ -- initial value of a thread-local variable.
+
if Is_Flat (N, Number_Dimensions (Typ)) then
+ Check_Static_Components;
+ if Static_Components then
+ if Is_Packed (Etype (N))
+ or else
+ (Is_Record_Type (Component_Type (Etype (N)))
+ and then Has_Discriminants (Component_Type (Etype (N))))
+ then
+ null;
+ else
+ Set_Compile_Time_Known_Aggregate (N);
+ end if;
+ end if;
+
return;
end if;
diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb
index 5987149..4d7fe26 100644
--- a/gcc/ada/freeze.adb
+++ b/gcc/ada/freeze.adb
@@ -3441,12 +3441,19 @@ package body Freeze is
(Is_OK_Static_Expression (Expression (Decl))
or else Nkind (Expression (Decl)) = N_Null)))
then
- Error_Msg_NE
- ("Thread_Local_Storage variable& is "
- & "improperly initialized", Decl, E);
- Error_Msg_NE
- ("\only allowed initialization is explicit "
- & "NULL or static expression", Decl, E);
+ if Nkind (Expression (Decl)) = N_Aggregate
+ and then Compile_Time_Known_Aggregate (Expression (Decl))
+ then
+ null;
+ else
+ Error_Msg_NE
+ ("Thread_Local_Storage variable& is "
+ & "improperly initialized", Decl, E);
+ Error_Msg_NE
+ ("\only allowed initialization is explicit "
+ & "NULL, static expression or static aggregate",
+ Decl, E);
+ end if;
end if;
end;
end if;
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index b6cad4e..7647865 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -21,7 +21,7 @@
@copying
@quotation
-GNAT Reference Manual , Apr 24, 2018
+GNAT Reference Manual , May 22, 2018
AdaCore
@@ -8070,13 +8070,17 @@ pragma Thread_Local_Storage ([Entity =>] LOCAL_NAME);
This pragma specifies that the specified entity, which must be
a variable declared in a library-level package, is to be marked as
"Thread Local Storage" (@code{TLS}). On systems supporting this (which
-include Windows, Solaris, GNU/Linux and VxWorks 6), this causes each
+include Windows, Solaris, GNU/Linux, and VxWorks 6), this causes each
thread (and hence each Ada task) to see a distinct copy of the variable.
-The variable may not have default initialization, and if there is
+The variable must not have default initialization, and if there is
an explicit initialization, it must be either @code{null} for an
-access variable, or a static expression for a scalar variable.
-This provides a low level mechanism similar to that provided by
+access variable, a static expression for a scalar variable, or a fully
+static aggregate for a composite type, that is to say, an aggregate all
+of whose components are static, and which does not include packed or
+discriminated components.
+
+This provides a low-level mechanism similar to that provided by
the @code{Ada.Task_Attributes} package, but much more efficient
and is also useful in writing interface code that will interact
with foreign threads.