From 4f5e5fcba8a9cbabb0e05f9cb753b549396bc2de Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 15 Feb 2017 18:09:18 +0100 Subject: [PATCH] re PR c++/79288 (TLS model wrong for static data members since r241137) PR c++/79288 * decl.c (grokdeclarator): For static data members, handle thread_p only after handling inline. * g++.dg/tls/pr79288.C: New test. From-SVN: r245488 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 17 +++++++++-------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/tls/pr79288.C | 28 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tls/pr79288.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 7b94d3b03af..74f5fc9b784 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-02-15 Jakub Jelinek + + PR c++/79288 + * decl.c (grokdeclarator): For static data members, handle thread_p + only after handling inline. + 2017-02-14 Marek Polacek PR c++/79420 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2292a3a2ac9..353e7b5d726 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -12063,14 +12063,6 @@ grokdeclarator (const cp_declarator *declarator, : input_location, VAR_DECL, unqualified_id, type); set_linkage_for_static_data_member (decl); - if (thread_p) - { - CP_DECL_THREAD_LOCAL_P (decl) = true; - if (!processing_template_decl) - set_decl_tls_model (decl, decl_default_tls_model (decl)); - if (declspecs->gnu_thread_keyword_p) - SET_DECL_GNU_TLS_P (decl); - } if (concept_p) error ("static data member %qE declared %", unqualified_id); @@ -12091,6 +12083,15 @@ grokdeclarator (const cp_declarator *declarator, definition is provided, unless this is an inline variable. */ DECL_EXTERNAL (decl) = 1; + + if (thread_p) + { + CP_DECL_THREAD_LOCAL_P (decl) = true; + if (!processing_template_decl) + set_decl_tls_model (decl, decl_default_tls_model (decl)); + if (declspecs->gnu_thread_keyword_p) + SET_DECL_GNU_TLS_P (decl); + } } else { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d95221a0d2c..5df5da8827b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-02-15 Jakub Jelinek + + PR c++/79288 + * g++.dg/tls/pr79288.C: New test. + 2017-02-15 Marek Polacek PR c/79515 diff --git a/gcc/testsuite/g++.dg/tls/pr79288.C b/gcc/testsuite/g++.dg/tls/pr79288.C new file mode 100644 index 00000000000..9f488df0274 --- /dev/null +++ b/gcc/testsuite/g++.dg/tls/pr79288.C @@ -0,0 +1,28 @@ +// PR c++/79288 +// { dg-do compile { target nonpic } } +// { dg-require-effective-target tls } +// { dg-options "-O2" } +// { dg-final { scan-assembler-not "@tpoff" { target i?86-*-* x86_64-*-* } } } + +struct S +{ + static __thread int *p; +}; + +template +struct T +{ + static __thread int *p; +}; + +int * +foo () +{ + return S::p; +} + +int * +bar () +{ + return T<0>::p; +} -- 2.30.2