[PATCH] D11594: Fix NAME.1 comdat name for replaced GlobalVariable

Yaron Keren yaron.keren at gmail.com
Wed Jul 29 08:17:04 PDT 2015


yaron.keren created this revision.
yaron.keren added subscribers: hans, cfe-commits, rnk, rafael.
yaron.keren set the repository for this revision to rL LLVM.

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.


Repository:
  rL LLVM

http://reviews.llvm.org/D11594

Files:
  tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
  tools/clang/test/CodeGenCXX/vtable-key-function-win-comdat.cpp

Index: tools/clang/test/CodeGenCXX/vtable-key-function-win-comdat.cpp
===================================================================
--- tools/clang/test/CodeGenCXX/vtable-key-function-win-comdat.cpp
+++ tools/clang/test/CodeGenCXX/vtable-key-function-win-comdat.cpp
@@ -0,0 +1,18 @@
+// 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:     $_ZTS6Test1a = comdat any
+// CHECK-NOT: $_ZTI6Test1a.1 = comdat any
Index: tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
===================================================================
--- tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ tools/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -2837,9 +2837,6 @@
       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 @@
     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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11594.30906.patch
Type: text/x-patch
Size: 1746 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150729/83e5b74b/attachment.bin>


More information about the cfe-commits mailing list