Issue |
135126
|
Summary |
[llvm] [unknown-windows-msvc] The [[__gnu__::__init_priority__]]attribute causes the constructor of the global function to be called multiple times
|
Labels |
new issue
|
Assignees |
|
Reporter |
MacroModel
|
The [[__gnu__::__init_priority__]]attribute causes the constructor of the global function to be called multiple times
```ps
clang version 21.0.0git (g...@github.com:trcrsired/llvm-project.git 38b0c053bae7fdb45b185e1b3c1a43eae50dfdca)
Target: x86_64-unknown-windows-gnu
Thread model: posix
InstalledDir: D:/tool-chain/x86_64-windows-gnu/llvm/bin
```
global.cppm:
```cpp
module;
#include <iostream>
export module global;
export namespace global {
struct Test
{
Test()
{
::std::cout<<"test\n";
}
};
[[__gnu__::__init_priority__(500)]] // This attribute causes a bug, if you remove this attribute everything works fine!
inline Test test{};
}
```
```ps
clang -c -Qunused-arguments -m64 --target=x86_64-windows-msvc -g -Wall -Wextra -Werror -O0 -std=c++26 -fms-runtime-lib=dll_dbg -Ithird-parties\fast_io\include -Isrc -DUWVM_VERSION_X=2 -DUWVM_VERSION_Y=0 -DUWVM_VERSION_Z=0 -DUWVM_VERSION_S=0 -DUWVM_USE_DEFAULT_INT -DUWVM_USE_DEFAULT_JIT -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DDEBUG -D_DEBUG -fexceptions -fcxx-exceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -Wno-braced-scalar-init --sysroot=D:\tool-chain\windows-msvc-sysroot -fno-rtti -fno-unwind-tables -march=native -fmodule-output=global.pcm .\global.cppm
```
global1.cpp:
```cpp
import global;
void test() {}
```
```ps
clang -c -Qunused-arguments -m64 --target=x86_64-windows-msvc -g -Wall -Wextra -Werror -O0 -std=c++26 -fms-runtime-lib=dll_dbg -Ithird-parties\fast_io\include -Isrc -DUWVM_VERSION_X=2 -DUWVM_VERSION_Y=0 -DUWVM_VERSION_Z=0 -DUWVM_VERSION_S=0 -DUWVM_USE_DEFAULT_INT -DUWVM_USE_DEFAULT_JIT -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DDEBUG -D_DEBUG -fexceptions -fcxx-exceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -Wno-braced-scalar-init --sysroot=D:\tool-chain\windows-msvc-sysroot -fno-rtti -fno-unwind-tables -march=native -fmodule-file=global=global.pcm .\global1.cpp
```
global2.cpp:
```cpp
import global;
int main()
{
void test();
test();
}
```
```ps
clang -c -Qunused-arguments -m64 --target=x86_64-windows-msvc -g -Wall -Wextra -Werror -O0 -std=c++26 -fms-runtime-lib=dll_dbg -Ithird-parties\fast_io\include -Isrc -DUWVM_VERSION_X=2 -DUWVM_VERSION_Y=0 -DUWVM_VERSION_Z=0 -DUWVM_VERSION_S=0 -DUWVM_USE_DEFAULT_INT -DUWVM_USE_DEFAULT_JIT -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DDEBUG -D_DEBUG -fexceptions -fcxx-exceptions -finput-charset=UTF-8 -fexec-charset=UTF-8 -Wno-braced-scalar-init --sysroot=D:\tool-chain\windows-msvc-sysroot -fno-rtti -fno-unwind-tables -march=native -fmodule-file=global=global.pcm .\global2.cpp
```
link
```ps
clang++ -o test.exe .\global.o .\global1.o .\global2.o -m64 --target=x86_64-windows-msvc -g -nostdlib -lntdll -lShell32 -fuse-ld=lld --sysroot=D:\tool-chain\windows-msvc-sysroot
```
run
```ps
test
test
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs