[clang] [MS] Put dllexported inline global initializers in a comdat (PR #107154)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 3 14:21:41 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Reid Kleckner (rnk)
<details>
<summary>Changes</summary>
Follow-up to c19f4f8069722f6804086d4438a0254104242c46 to handle corner case of exported inline variables.
Should fix #<!-- -->56485
---
Full diff: https://github.com/llvm/llvm-project/pull/107154.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (+1-1)
- (modified) clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp (+2-3)
``````````diff
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 2f56355cff90ec..c9e0fb0d8afaba 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -586,7 +586,7 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
PrioritizedCXXGlobalInits.size());
PrioritizedCXXGlobalInits.push_back(std::make_pair(Key, Fn));
} else if (isTemplateInstantiation(D->getTemplateSpecializationKind()) ||
- getContext().GetGVALinkageForVariable(D) == GVA_DiscardableODR ||
+ !isUniqueGVALinkage(getContext().GetGVALinkageForVariable(D)) ||
D->hasAttr<SelectAnyAttr>()) {
// C++ [basic.start.init]p2:
// Definitions of explicitly specialized class template static data
diff --git a/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp b/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
index 60b48abca2f89a..871551240debfd 100644
--- a/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
+++ b/clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp
@@ -49,8 +49,6 @@ struct X {
static T ioo;
static T init();
};
-// template specialized static data don't need in llvm.used,
-// the static init routine get call from _GLOBAL__sub_I_ routines.
template <> int X<int>::ioo = X<int>::init();
template struct X<int>;
class a {
@@ -87,5 +85,6 @@ struct S1
int foo();
inline int zoo = foo();
inline static int boo = foo();
+inline __declspec(dllexport) A exported_inline{};
-// CHECK: @llvm.used = appending global [8 x ptr] [ptr @"?x at selectany_init@@3HA", ptr @"?x1 at selectany_init@@3HA", ptr @"?x@?$A at H@explicit_template_instantiation@@2HA", ptr @"?ioo@?$X_ at H@@2HA", ptr @"?aoo at S1@@2UA@@A", ptr @"?zoo@@3HA", ptr @"?s@?$ExportedTemplate at H@@2US@@A", ptr @"?x@?$A at H@implicit_template_instantiation@@2HA"], section "llvm.metadata"
+// CHECK: @llvm.used = appending global [10 x ptr] [ptr @"?x at selectany_init@@3HA", ptr @"?x1 at selectany_init@@3HA", ptr @"?x@?$A at H@explicit_template_instantiation@@2HA", ptr @"?ioo@?$X_ at H@@2HA", ptr @"?ioo@?$X at H@@2HA", ptr @"?aoo at S1@@2UA@@A", ptr @"?zoo@@3HA", ptr @"?exported_inline@@3UA@@A", ptr @"?s@?$ExportedTemplate at H@@2US@@A", ptr @"?x@?$A at H@implicit_template_instantiation@@2HA"], section "llvm.metadata"
``````````
</details>
https://github.com/llvm/llvm-project/pull/107154
More information about the cfe-commits
mailing list