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

Pierre Vigier <pierre.vigier at ymail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pierre.vigier at ymail dot com

--- Comment #1 from Pierre Vigier <pierre.vigier at ymail dot com> ---
Hello,

I am facing the same issue with the following program:

a.h
---
#pragma once

struct A
{
    static thread_local int x;
};

a.cpp
---
#include "a.h"

thread_local int A::x = 0;

main.cpp
---
#include "a.h"

int main()
{
    A::x = 1;
    return 0;
}

When I compile with no optimization:
x86_64-w64-mingw32-g++ -c -a.cpp -o a.obj
x86_64-w64-mingw32-g++ -c main.cpp -o main.obj 
x86_64-w64-mingw32-g++ main.obj a.obj -o test.exe
The program runs fine.

But, if I use optimizations:
x86_64-w64-mingw32-g++ -c -O1 a.cpp -o a.obj
x86_64-w64-mingw32-g++ -c -O1 main.cpp -o main.obj 
x86_64-w64-mingw32-g++ -O1 main.obj a.obj -o test.exe
The program crashes when it tries to access the thread local variable.

x86_64-w64-mingw32-gcc -v:
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-w64-mingw32/11.2.1/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../configure --prefix=/usr --bindir=/usr/bin
--includedir=/usr/include --mandir=/usr/share/man --infodir=/usr/share/info
--datadir=/usr/share --build=x86_64-redhat-linux-gnu
--host=x86_64-redhat-linux-gnu --with-gnu-as --with-gnu-ld --verbose
--without-newlib --disable-multilib --disable-plugin --with-system-zlib
--disable-nls --without-included-gettext --disable-win32-registry
--enable-languages=c,c++,objc,obj-c++,fortran
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-threads=posix
--with-isl --enable-libgomp --target=x86_64-w64-mingw32
--with-sysroot=/usr/x86_64-w64-mingw32/sys-root
--with-gxx-include-dir=/usr/x86_64-w64-mingw32/sys-root/mingw/include/c++
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 11.2.1 20210728 (Fedora MinGW 11.2.1-3.fc35) (GCC) 

The same program was working fine on 10.3.1.

Reply via email to