Skip to content

[llvm 20.1.2] [unknown-windows-msvc] The [[__gnu__::__init_priority__]]attribute causes the constructor of the global function to be called multiple times #135126

Open
@MacroModel

Description

@MacroModel

The [[__gnu__::__init_priority__]] attribute causes the constructor of the global function to be called multiple times
This phenomenon only exists with target = unknown-windows-msvc.
In contrast unknown-windows-gnu (mingw) has no problems at all!

clang version:

clang version 20.1.2
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: D:\test\20250410\clang+llvm-20.1.2-x86_64-pc-windows-msvc\bin

global.cppm:

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{};
}
 .\clang+llvm-20.1.2-x86_64-pc-windows-msvc\bin\clang -c -Qunused-arguments -m64 --target=x86_64-windows-msvc -g -Wall -Wextra -Werror -O0 -std=c++26 -fms-runtime-lib=dll_dbg -Isrc -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:

import global;

void test() {}
.\clang+llvm-20.1.2-x86_64-pc-windows-msvc\bin\clang -c -Qunused-arguments -m64 --target=x86_64-windows-msvc -g -Wall -Wextra -Werror -O0 -std=c++26 -fms-runtime-lib=dll_dbg -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:

import global;

int main()
{
    void test();
    test();
}
.\clang+llvm-20.1.2-x86_64-pc-windows-msvc\bin\clang -c -Qunused-arguments -m64 --target=x86_64-windows-msvc -g -Wall -Wextra -Werror -O0 -std=c++26 -fms-runtime-lib=dll_dbg -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

.\clang+llvm-20.1.2-x86_64-pc-windows-msvc\bin\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

test
test

Metadata

Metadata

Assignees

No one assigned

    Labels

    c++20clangClang issues not falling into any other categoryclang:modulesC++20 modules and Clang Header ModulesconfirmedVerified by a second partyplatform:windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions