r353742 - [CodeGen] Set construction vtable visibility after creating initializer
Petr Hosek via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 11 12:13:42 PST 2019
Author: phosek
Date: Mon Feb 11 12:13:42 2019
New Revision: 353742
URL: http://llvm.org/viewvc/llvm-project?rev=353742&view=rev
Log:
[CodeGen] Set construction vtable visibility after creating initializer
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.
Differential Revision: https://reviews.llvm.org/D58010
Added:
cfe/trunk/test/CodeGen/construction-vtable-visibility.cpp
Modified:
cfe/trunk/lib/CodeGen/CGVTables.cpp
Modified: cfe/trunk/lib/CodeGen/CGVTables.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVTables.cpp?rev=353742&r1=353741&r2=353742&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGVTables.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVTables.cpp Mon Feb 11 12:13:42 2019
@@ -761,7 +761,6 @@ CodeGenVTables::GenerateConstructionVTab
// 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,11 @@ CodeGenVTables::GenerateConstructionVTab
createVTableInitializer(components, *VTLayout, RTTI);
components.finishAndSetAsInitializer(VTable);
+ // Set properties only after the initializer has been set to ensure that the
+ // GV is treated as definition and not declaration.
+ assert(!VTable->isDeclaration() && "Shouldn't set properties on declaration");
+ CGM.setGVProperties(VTable, RD);
+
CGM.EmitVTableTypeMetadata(VTable, *VTLayout.get());
return VTable;
Added: cfe/trunk/test/CodeGen/construction-vtable-visibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/construction-vtable-visibility.cpp?rev=353742&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/construction-vtable-visibility.cpp (added)
+++ cfe/trunk/test/CodeGen/construction-vtable-visibility.cpp Mon Feb 11 12:13:42 2019
@@ -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
More information about the cfe-commits
mailing list