r197060 - [ms-cxxabi] Fix linkage of dtor thunks for anonymous classes
Reid Kleckner
reid at kleckner.net
Wed Dec 11 11:21:27 PST 2013
Author: rnk
Date: Wed Dec 11 13:21:27 2013
New Revision: 197060
URL: http://llvm.org/viewvc/llvm-project?rev=197060&view=rev
Log:
[ms-cxxabi] Fix linkage of dtor thunks for anonymous classes
We were mistakengly giving linkonce_odr linkage instead of internal
linkage to the deleting and complete destructor thunks for classes in
anonymous namespaces.
Fixes PR17273.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=197060&r1=197059&r2=197060&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Dec 11 13:21:27 2013
@@ -585,11 +585,6 @@ llvm::GlobalValue::LinkageTypes
CodeGenModule::getFunctionLinkage(GlobalDecl GD) {
const FunctionDecl *D = cast<FunctionDecl>(GD.getDecl());
- if (isa<CXXDestructorDecl>(D) &&
- getCXXABI().useThunkForDtorVariant(cast<CXXDestructorDecl>(D),
- GD.getDtorType()))
- return llvm::Function::LinkOnceODRLinkage;
-
GVALinkage Linkage = getContext().GetGVALinkageForFunction(D);
if (Linkage == GVA_Internal)
@@ -630,7 +625,14 @@ CodeGenModule::getFunctionLinkage(Global
return !Context.getLangOpts().AppleKext
? llvm::Function::WeakODRLinkage
: llvm::Function::ExternalLinkage;
-
+
+ // Destructor variants in the Microsoft C++ ABI are always linkonce_odr thunks
+ // emitted on an as-needed basis.
+ if (isa<CXXDestructorDecl>(D) &&
+ getCXXABI().useThunkForDtorVariant(cast<CXXDestructorDecl>(D),
+ GD.getDtorType()))
+ return llvm::Function::LinkOnceODRLinkage;
+
// Otherwise, we have strong external linkage.
assert(Linkage == GVA_StrongExternal);
return llvm::Function::ExternalLinkage;
Modified: cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp?rev=197060&r1=197059&r2=197060&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-structors.cpp Wed Dec 11 13:21:27 2013
@@ -299,3 +299,18 @@ void call_nv_deleting_dtor(D *d) {
}
}
+
+// Dtor thunks for classes in anonymous namespaces should be internal, not
+// linkonce_odr.
+namespace {
+struct A {
+ virtual ~A() { }
+};
+}
+void *getA() {
+ return (void*)new A();
+}
+// CHECK: define internal x86_thiscallcc void @"\01??_GA@?A@@UAEPAXI at Z"
+// CHECK: (%"struct.<anonymous namespace>::A"* %this, i32 %should_call_delete)
+// CHECK: define internal x86_thiscallcc void @"\01??1A@?A@@UAE at XZ"
+// CHECK: (%"struct.<anonymous namespace>::A"* %this)
More information about the cfe-commits
mailing list