Author: yrnkrn Date: Wed Jul 29 10:42:28 2015 New Revision: 243525 URL: http://llvm.org/viewvc/llvm-project?rev=243525&view=rev Log: In case of an existing GlobalVariable, the comdat is created using the name of the new GV (usually NAME.1) instead of the correct NAME of the old GV. Moving comdat creation after GV replacement solves this. Patch + testcase.
Reviewed by Reid Kleckner. http://reviews.llvm.org/D11594 Added: cfe/trunk/test/CodeGenCXX/vtable-key-function-win-comdat.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=243525&r1=243524&r2=243525&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original) +++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Wed Jul 29 10:42:28 2015 @@ -2837,9 +2837,6 @@ llvm::Constant *ItaniumRTTIBuilder::Buil new llvm::GlobalVariable(M, Init->getType(), /*Constant=*/true, Linkage, Init, Name); - if (CGM.supportsCOMDAT() && GV->isWeakForLinker()) - GV->setComdat(M.getOrInsertComdat(GV->getName())); - // If there's already an old global variable, replace it with the new one. if (OldGV) { GV->takeName(OldGV); @@ -2849,6 +2846,9 @@ llvm::Constant *ItaniumRTTIBuilder::Buil OldGV->eraseFromParent(); } + if (CGM.supportsCOMDAT() && GV->isWeakForLinker()) + GV->setComdat(M.getOrInsertComdat(GV->getName())); + // The Itanium ABI specifies that type_info objects must be globally // unique, with one exception: if the type is an incomplete class // type or a (possibly indirect) pointer to one. That exception Added: cfe/trunk/test/CodeGenCXX/vtable-key-function-win-comdat.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-key-function-win-comdat.cpp?rev=243525&view=auto ============================================================================== --- cfe/trunk/test/CodeGenCXX/vtable-key-function-win-comdat.cpp (added) +++ cfe/trunk/test/CodeGenCXX/vtable-key-function-win-comdat.cpp Wed Jul 29 10:42:28 2015 @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 %s -triple=x86_64-pc-windows-gnu -emit-llvm -o - | FileCheck %s + +namespace std { class type_info; } +extern void use(const std::type_info &rtti); + +struct Test1a { + Test1a(); + virtual void foo(); + virtual void bar(); +}; + +// V-table needs to be defined weakly. +Test1a::Test1a() { use(typeid(Test1a)); } +// This defines the key function. +inline void Test1a::foo() {} + +// CHECK: $_ZTV6Test1a = comdat any +// CHECK: $_ZTS6Test1a = comdat any +// CHECK: $_ZTI6Test1a = comdat any +// CHECK-NOT: $_ZTS6Test1a.1 = comdat any +// CHECK-NOT: $_ZTI6Test1a.1 = comdat any + +// CHECK: @_ZTV6Test1a = linkonce_odr unnamed_addr constant {{.*}} ({ i8*, i8* }* @_ZTI6Test1a to i8*) +// CHECK: @_ZTS6Test1a = linkonce_odr constant +// CHECK: @_ZTI6Test1a = linkonce_odr constant {{.*}} [8 x i8]* @_ZTS6Test1a _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits