<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/135126>135126</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[llvm] [unknown-windows-msvc] The [[__gnu__::__init_priority__]]attribute causes the constructor of the global function to be called multiple times
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MacroModel
</td>
</tr>
</table>
<pre>
The [[__gnu__::__init_priority__]]attribute causes the constructor of the global function to be called multiple times
```ps
clang version 21.0.0git (git@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
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsV01v4zYQ_TX0haBBUZKjHHywrbhw0c2iG2fT9iJQFCWxS5ECPxzn3xeUlMTxOsC2QNEeEgix9GaGIh_fDDXUWtEozpcgXYM0n1HvWm2Wnygz-pOuuJyVunpa7lsOB491UTTKFwWIVyBeF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