[clang] [clang][CodeGen] Use dynamic init for vague-linkage variables without constant initialization (PR #226645)
Divyansh Yadav via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 27 11:56:05 PDT 2026
schizophrenicmaniac wrote:
> > Dropped the EmitGlobalVarDefinition change, which caused the dllexport-members.cpp failure. Inline variables might have a similar issue; should I handle that here or in a separate PR?
>
> Inline variables have the same issue, yes. I'd prefer to handle it now, while I still have the relevant context in my head.
Done. Static data members of class templates had the same problem, so both are handled now. A new helper, `CodeGenModule::mustDynamicallyInitialize`, is used for both static locals and globals: a C++ variable with weak/linkonce linkage whose initializer isn't a constant initializer is no longer constant-folded, and gets the regular dynamic initialization instead. I renamed the test to `vague-linkage-non-constant-init.cpp` and added the new cases.
- On ELF, the comdat keeps things consistent within a single link, but it still crashes across DSOs. I reproduced that on macOS for all three kinds of variables, and this patch fixes it.
- With the MSVC ABI, inline variables are now initialized dynamically too. That isn't strictly needed there, but it keeps the ABIs consistent. I can restrict it to Itanium if you'd prefer.
https://github.com/llvm/llvm-project/pull/226645
More information about the cfe-commits
mailing list