public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Do not call null register_common in emutls
@ 2020-02-06  7:07 Alexandre Oliva
  2020-02-13 20:06 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Alexandre Oliva @ 2020-02-06  7:07 UTC (permalink / raw)
  To: gcc-patches

Thread-local variables with DECL_COMMON trigger an internal compiler
error on targets that use emulated TLS without register_common, when
we attempt to expand a call to the NULL register_common, with
testcases as simple as gcc.dg/tls/emutls-2.c.

The documentation states that, on such targets, common variables would
fall back to explicitly initialized.  This patch rearranges the code
that deals with initialization of common and non-common variables,
complementing code that is already in place to detect
register_common-less targets.


Regstrapped on x86_64-linux-gnu, tested on an affected target.
Ok to install?


for  gcc/ChangeLog

	* tree-emutls.c (new_emutls_decl, emutls_common_1): Complete
	handling of register_common-less targets.

for  gcc/testsuite/ChangeLog

	* gcc.dg/tls/emutls-3.c: New, combining emutls-2.c and
	thr-init-2.c into an execution test with explicitly common
	variables.
---
 testsuite/gcc.dg/tls/emutls-3.c |   26 ++++++++++++++++++++++++++
 tree-emutls.c                   |    4 ++--
 2 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 testsuite/gcc.dg/tls/emutls-3.c

diff --git gcc/testsuite/gcc.dg/tls/emutls-3.c gcc/testsuite/gcc.dg/tls/emutls-3.c
new file mode 100644
index 00000000..e062ba8
--- /dev/null
+++ gcc/testsuite/gcc.dg/tls/emutls-3.c
@@ -0,0 +1,26 @@
+/* { dg-do run } */
+/* { dg-require-effective-target tls } */
+/* { dg-require-effective-target global_constructor } */
+/* { dg-options "-O2" } */
+/* { dg-require-effective-target tls_runtime } */
+/* { dg-add-options tls } */
+
+__thread int i __attribute__((common));
+
+extern void abort (void);
+
+int test_code(int b)
+{
+  i += b ;
+  return i;
+}
+
+int main (int ac, char *av[])
+{
+  int a = test_code(test_code(1));
+  
+  if ((a != 2) || (i != 2))
+    abort () ;
+  
+  return 0;
+}
diff --git gcc/tree-emutls.c gcc/tree-emutls.c
index e924124..44755dd4 100644
--- gcc/tree-emutls.c
+++ gcc/tree-emutls.c
@@ -322,7 +322,7 @@ new_emutls_decl (tree decl, tree alias_of)
      control structure with size and alignment information.  Initialization
      of COMMON block variables happens elsewhere via a constructor.  */
   if (!DECL_EXTERNAL (to)
-      && (!DECL_COMMON (to)
+      && (!DECL_COMMON (to) || !targetm.emutls.register_common
           || (DECL_INITIAL (decl)
               && DECL_INITIAL (decl) != error_mark_node)))
     {
@@ -360,7 +360,7 @@ emutls_common_1 (tree tls_decl, tree control_decl, tree *pstmts)
   tree x;
   tree word_type_node;
 
-  if (! DECL_COMMON (tls_decl)
+  if (!DECL_COMMON (tls_decl) || !targetm.emutls.register_common
       || (DECL_INITIAL (tls_decl)
 	  && DECL_INITIAL (tls_decl) != error_mark_node))
     return;


-- 
Alexandre Oliva, freedom fighter   he/him   https://FSFLA.org/blogs/lxo
Free Software Evangelist           Stallman was right, but he's left :(
GNU Toolchain Engineer    FSMatrix: It was he who freed the first of us
FSF & FSFLA board member                The Savior shall return (true);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Do not call null register_common in emutls
  2020-02-06  7:07 Do not call null register_common in emutls Alexandre Oliva
@ 2020-02-13 20:06 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2020-02-13 20:06 UTC (permalink / raw)
  To: Alexandre Oliva, gcc-patches

On Thu, 2020-02-06 at 04:07 -0300, Alexandre Oliva wrote:
> Thread-local variables with DECL_COMMON trigger an internal compiler
> error on targets that use emulated TLS without register_common, when
> we attempt to expand a call to the NULL register_common, with
> testcases as simple as gcc.dg/tls/emutls-2.c.
> 
> The documentation states that, on such targets, common variables would
> fall back to explicitly initialized.  This patch rearranges the code
> that deals with initialization of common and non-common variables,
> complementing code that is already in place to detect
> register_common-less targets.
> 
> 
> Regstrapped on x86_64-linux-gnu, tested on an affected target.
> Ok to install?
> 
> 
> for  gcc/ChangeLog
> 
> 	* tree-emutls.c (new_emutls_decl, emutls_common_1): Complete
> 	handling of register_common-less targets.
> 
> for  gcc/testsuite/ChangeLog
> 
> 	* gcc.dg/tls/emutls-3.c: New, combining emutls-2.c and
> 	thr-init-2.c into an execution test with explicitly common
> 	variables.
Not strictly a regression AFAICT, but it seems OK for the trunk to me.

jeff
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-02-13 20:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06  7:07 Do not call null register_common in emutls Alexandre Oliva
2020-02-13 20:06 ` Jeff Law

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