From: Jason Merrill Date: Wed, 15 Oct 2014 16:46:11 +0000 (-0400) Subject: re PR middle-end/58624 (gcc internal compiler error: Segmentaion fault in insert_to_a... X-Git-Tag: releases/gcc-4.8.4~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0d310f450b92f4b081480a909d4104c8529bffab;p=thirdparty%2Fgcc.git re PR middle-end/58624 (gcc internal compiler error: Segmentaion fault in insert_to_assembler_name_hash) PR c++/58624 * pt.c (tsubst_copy_and_build) [VAR_DECL]: Use TLS wrapper. * semantics.c (finish_id_expression): Don't call TLS wrapper in a template. From-SVN: r216273 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 82e61f5f6b7e..d289bba4f328 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2014-10-15 Jason Merrill + + PR c++/58624 + * pt.c (tsubst_copy_and_build) [VAR_DECL]: Use TLS wrapper. + * semantics.c (finish_id_expression): Don't call TLS wrapper in a + template. + 2014-08-07 Jason Merrill PR c++/61959 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index c03af2e93e08..83aedd78dba8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -14499,6 +14499,16 @@ tsubst_copy_and_build (tree t, case PARM_DECL: { tree r = tsubst_copy (t, args, complain, in_decl); + if (TREE_CODE (r) == VAR_DECL + && !processing_template_decl + && !cp_unevaluated_operand + && DECL_THREAD_LOCAL_P (r)) + { + if (tree wrap = get_tls_wrapper_fn (r)) + /* Replace an evaluated use of the thread_local variable with + a call to its wrapper. */ + r = build_cxx_call (wrap, 0, NULL, tf_warning_or_error); + } if (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE) /* If the original type was a reference, we'll be wrapped in diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 9825dbe6aa40..cc9c550e19cc 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -3343,6 +3343,7 @@ finish_id_expression (tree id_expression, tree wrap; if (TREE_CODE (decl) == VAR_DECL && !cp_unevaluated_operand + && !processing_template_decl && DECL_THREAD_LOCAL_P (decl) && (wrap = get_tls_wrapper_fn (decl))) { diff --git a/gcc/testsuite/g++.dg/tls/thread_local10.C b/gcc/testsuite/g++.dg/tls/thread_local10.C new file mode 100644 index 000000000000..48c1b861c78d --- /dev/null +++ b/gcc/testsuite/g++.dg/tls/thread_local10.C @@ -0,0 +1,23 @@ +// PR c++/58624 + +// { dg-do run { target c++11 } } +// { dg-add-options tls } +// { dg-require-effective-target tls_runtime } + +int i; + +template struct A +{ + static thread_local int s; + + A () { i = s; } +}; + +int f() { return 42; } +template thread_local int A::s = f(); + +int main () { + A a; + if (i != 42) + __builtin_abort(); +}