public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/106435] New: constructor of thread_local static member is not called
@ 2022-07-25 16:37 fxcoudert at gcc dot gnu.org
  2022-07-25 16:39 ` [Bug target/106435] " fxcoudert at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu.org @ 2022-07-25 16:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106435

            Bug ID: 106435
           Summary: constructor of thread_local static member is not
                    called
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxcoudert at gcc dot gnu.org
  Target Milestone: ---

Originally reported to Homebrew at
https://github.com/Homebrew/homebrew-core/issues/105022



$ cat foo.hpp 
#pragma once

struct Foo {
  Foo();
  void func();
};

struct Bar {
  thread_local static Foo foo;
};

$ cat foo.cpp 
#include "foo.hpp"

#include <iostream>

Foo::Foo() {
  std::cout << "Foo::Foo(this=" << this << ")\n";
}

void Foo::func() {
  std::cout << "Foo::func(this=" << this << ")\n";
}

thread_local Foo Bar::foo;

$ cat main.cpp 
#include "foo.hpp"

int main() {
  Bar::foo.func();
}


Compiled with clang, the constructor is called. Compiled with gcc 11 or 12 on
aarch64-apple-darwin21, it is not:


$ g++-12 -std=c++17 foo.cpp main.cpp && ./a.out           
Foo::func(this=0x6000009e0038)
$ g++-11 -std=c++17 foo.cpp main.cpp && ./a.out
Foo::func(this=0x600001418038)
$ clang++ -std=c++17 foo.cpp main.cpp && ./a.out
Foo::Foo(this=0x60000209c000)
Foo::func(this=0x60000209c000)


$ g++-12 -v                                    
Using built-in specs.
COLLECT_GCC=g++-12
COLLECT_LTO_WRAPPER=/opt/homebrew/Cellar/gcc@12/12.1.0_1/bin/../libexec/gcc/aarch64-apple-darwin21/12/lto-wrapper
Target: aarch64-apple-darwin21
Configured with: ../configure --prefix=/opt/homebrew/opt/gcc@12
--libdir=/opt/homebrew/opt/gcc@12/lib/gcc/12 --disable-nls
--enable-checking=release --with-gcc-major-version-only
--enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-12
--with-gmp=/opt/homebrew/opt/gmp --with-mpfr=/opt/homebrew/opt/mpfr
--with-mpc=/opt/homebrew/opt/libmpc --with-isl=/opt/homebrew/opt/isl
--with-zstd=/opt/homebrew/opt/zstd --with-pkgversion='Homebrew GCC 12.1.0_1'
--with-bugurl=https://github.com/Homebrew/homebrew-core/issues
--with-system-zlib --build=aarch64-apple-darwin21
--with-native-system-header-dir=/usr/include
--with-sysroot=/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.1.0 (Homebrew GCC 12.1.0_1)

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

end of thread, other threads:[~2022-12-28  8:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-25 16:37 [Bug target/106435] New: constructor of thread_local static member is not called fxcoudert at gcc dot gnu.org
2022-07-25 16:39 ` [Bug target/106435] " fxcoudert at gcc dot gnu.org
2022-07-25 16:42 ` [Bug middle-end/106435] " pinskia at gcc dot gnu.org
2022-07-25 16:47 ` iains at gcc dot gnu.org
2022-07-25 16:49 ` pinskia at gcc dot gnu.org
2022-07-25 16:56 ` fxcoudert at gcc dot gnu.org
2022-07-25 16:59 ` iains at gcc dot gnu.org
2022-07-25 19:06 ` iains at gcc dot gnu.org
2022-07-25 22:43 ` iains at gcc dot gnu.org
2022-07-26  8:10 ` [Bug c++/106435] " iains at gcc dot gnu.org
2022-07-26 11:36 ` iains at gcc dot gnu.org
2022-12-28  8:09 ` iains at gcc dot gnu.org

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