From: Pádraig Brady Date: Mon, 5 Mar 2018 13:48:43 +0000 (+0000) Subject: [PR c++/84497] ref to undefined tls init X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=35a313aaf210f8b4c901de178b46820383dbfd3b;p=gcc.git [PR c++/84497] ref to undefined tls init https://gcc.gnu.org/ml/gcc-patches/2018-03/msg00209.html PR c++/84497 * decl2.c (get_tls_init_fn): Check TYPE_HAS_TRIVIAL_DFLT too. PR c++/84497 * g++.dg/cpp0x/pr84497.C: New. Co-Authored-By: Jason Merrill Co-Authored-By: Nathan Sidwell From-SVN: r258244 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 942b7e89aae..e9b0e3bd28e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-03-05 Pádraig Brady + Jason Merrill + Nathan Sidwell + + PR c++/84497 + * decl2.c (get_tls_init_fn): Check TYPE_HAS_TRIVIAL_DFLT too. + 2018-03-03 Jason Merrill PR c++/84686 - missing volatile loads. diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index d2693ce458b..49d680f6e80 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -3337,7 +3337,8 @@ get_tls_init_fn (tree var) /* If the variable is defined somewhere else and might have static initialization, make the init function a weak reference. */ if ((!TYPE_NEEDS_CONSTRUCTING (obtype) - || TYPE_HAS_CONSTEXPR_CTOR (obtype)) + || TYPE_HAS_CONSTEXPR_CTOR (obtype) + || TYPE_HAS_TRIVIAL_DFLT (obtype)) && TYPE_HAS_TRIVIAL_DESTRUCTOR (obtype) && DECL_EXTERNAL (var)) declare_weak (fn); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 97ae0197d70..b4a6556a5f9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2018-03-05 Pádraig Brady + Nathan Sidwell + + PR c++/84497 + * g++.dg/cpp0x/pr84497.C: New. + 2018-03-05 Richard Biener PR tree-optimization/84670 diff --git a/gcc/testsuite/g++.dg/cpp0x/pr84497.C b/gcc/testsuite/g++.dg/cpp0x/pr84497.C new file mode 100644 index 00000000000..cb9d233bf71 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/pr84497.C @@ -0,0 +1,37 @@ +// PR 84497 mismatch with thread constructor fn weakness +// { dg-do compile { target c++11 } } +// { dg-require-weak "" } + +struct Base +{ + int m; + + Base() noexcept = default; // trivial but not constexpr + ~Base() noexcept = default; +}; + +struct Derived : Base {}; +struct Container { + Base m; +}; + +#ifdef DEF +// This bit for exposition only. +// All items placed in .tbss +// __tls_init simply sets __tls_guard +// no aliases to __tls_init generated +thread_local Base base_obj; +thread_local Derived derived_obj; +thread_local Container container_obj; +#else +// Erroneously created strong undef refs to +// _ZTH11derived_obj, _ZTH13container_obj, _ZTH8base_obj +extern thread_local Base base_obj; +extern thread_local Derived derived_obj; +extern thread_local Container container_obj; +int main() { return !(&base_obj && &derived_obj && &container_obj);} +#endif + +// { dg-final { scan-assembler ".weak\[ \t\]*_ZTH8base_obj" } } +// { dg-final { scan-assembler ".weak\[ \t\]*_ZTH11derived_obj" } } +// { dg-final { scan-assembler ".weak\[ \t\]*_ZTH13container_obj" } }