diff mbox

C++ PATCH for c++/58672 (ICE with invalid thread_local)

Message ID 52EBDD88.5060703@redhat.com
State New
Headers show

Commit Message

Jason Merrill Jan. 31, 2014, 5:29 p.m. UTC
In this testcase, an error caused us to decide that a variable needs 
initialization but not a TLS init function.  We should handle that 
gracefully.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
diff mbox

Patch

commit cc60625316aa72c2142bd90a30e3756358caac23
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Jan 31 11:36:54 2014 -0500

    	PR c++/58672
    	* decl2.c (handle_tls_init): Handle null init fn.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 2216591..35707a0 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -4036,6 +4036,8 @@  handle_tls_init (void)
       if (TREE_PUBLIC (var))
 	{
           tree single_init_fn = get_tls_init_fn (var);
+	  if (single_init_fn == NULL_TREE)
+	    continue;
 	  cgraph_node *alias
 	    = cgraph_same_body_alias (cgraph_get_create_node (fn),
 				      single_init_fn, fn);
diff --git a/gcc/testsuite/g++.dg/tls/thread_local-ice2.C b/gcc/testsuite/g++.dg/tls/thread_local-ice2.C
new file mode 100644
index 0000000..53bc297
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tls/thread_local-ice2.C
@@ -0,0 +1,11 @@ 
+// PR c++/58672
+// { dg-options "-std=c++11" }
+// { dg-require-effective-target tls }
+
+struct A
+{
+  A(int);
+  i;				// { dg-error "" }
+};
+
+thread_local A a(0);