[PATCH] D58010: [CodeGen] Set construction vtable visibility after creating initialize

Petr Hosek via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 9 19:50:51 PST 2019


phosek created this revision.
phosek added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

We must only set the construction vtable visibility after we create the
vtable initializer, otherwise the global value will be treated as
declaration rather than definition and the visibility won't be set.


Repository:
  rC Clang

https://reviews.llvm.org/D58010

Files:
  clang/lib/CodeGen/CGVTables.cpp
  clang/test/CodeGen/construction-vtable-visibility.cpp


Index: clang/test/CodeGen/construction-vtable-visibility.cpp
===================================================================
--- /dev/null
+++ clang/test/CodeGen/construction-vtable-visibility.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-linux-unknown -fvisibility hidden -emit-llvm %s -o - | FileCheck %s
+
+struct Base {};
+
+class Parent1 : virtual public Base {};
+
+class Parent2 : virtual public Base {};
+
+class Child : public Parent1, public Parent2 {};
+
+void test() {
+  Child x;
+}
+
+// CHECK: @_ZTC5Child0_7Parent1 = linkonce_odr hidden unnamed_addr constant
+// CHECK: @_ZTC5Child8_7Parent2 = linkonce_odr hidden unnamed_addr constant
Index: clang/lib/CodeGen/CGVTables.cpp
===================================================================
--- clang/lib/CodeGen/CGVTables.cpp
+++ clang/lib/CodeGen/CGVTables.cpp
@@ -761,7 +761,6 @@
   // Create the variable that will hold the construction vtable.
   llvm::GlobalVariable *VTable =
       CGM.CreateOrReplaceCXXRuntimeVariable(Name, VTType, Linkage, Align);
-  CGM.setGVProperties(VTable, RD);
 
   // V-tables are always unnamed_addr.
   VTable->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
@@ -775,6 +774,8 @@
   createVTableInitializer(components, *VTLayout, RTTI);
   components.finishAndSetAsInitializer(VTable);
 
+  CGM.setGVProperties(VTable, RD);
+
   CGM.EmitVTableTypeMetadata(VTable, *VTLayout.get());
 
   return VTable;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58010.186141.patch
Type: text/x-patch
Size: 1428 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190210/011a4ed4/attachment.bin>


More information about the cfe-commits mailing list