[clang] [MS] Put dllexported inline global initializers in a comdat (PR #107154)
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 3 14:21:08 PDT 2024
https://github.com/rnk created https://github.com/llvm/llvm-project/pull/107154
Follow-up to c19f4f8069722f6804086d4438a0254104242c46 to handle corner case of exported inline variables.
Should fix #56485
>From cfb2cea5a4d4e0c1712e038692c4c5acee6b1f27 Mon Sep 17 00:00:00 2001
From: Reid Kleckner <rnk at google.com>
Date: Tue, 3 Sep 2024 21:16:40 +0000
Subject: [PATCH] [MS] Put dllexported inline global initializers in a comdat
Follow-up to c19f4f8069722f6804086d4438a0254104242c46 to handle corner
case of exported inline variables.
Should fix #56485
---
clang/lib/CodeGen/CGDeclCXX.cpp | 2 +-
clang/test/CodeGenCXX/microsoft-abi-template-static-init.cpp | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
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"
More information about the cfe-commits
mailing list