[clang] [clang codegen][regression] Add dso_local/hidden/etc. markings to VTT definitions and declarations (PR #72452)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 20 16:55:47 PST 2023
https://github.com/bd1976bris updated https://github.com/llvm/llvm-project/pull/72452
>From f6e400224b3a90b4ec47bce2212a8e760b0fe9d8 Mon Sep 17 00:00:00 2001
From: Ben Dunbobbin <Ben.Dunbobbin at sony.com>
Date: Wed, 15 Nov 2023 23:09:41 +0000
Subject: [PATCH 1/2] [clang codegen] Add dso_local/hidden/etc. markings to VTT
definitions and declarations
https://reviews.llvm.org/D128482 regressed certain cases of VTT
emission which are no longer hidden with -fvisibility=hidden.
Fix this regression by marking both declarations and definitions.
---
clang/lib/CodeGen/CGVTT.cpp | 3 +++
clang/test/CodeGenCXX/visibility.cpp | 9 +++++++++
2 files changed, 12 insertions(+)
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index 22790147c6f5a9f..0eab677ca68a85a 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -93,6 +93,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
+
+ // Set the right visibility.
+ CGM.setGVProperties(VTT, RD);
}
llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTT(const CXXRecordDecl *RD) {
diff --git a/clang/test/CodeGenCXX/visibility.cpp b/clang/test/CodeGenCXX/visibility.cpp
index b017bc8b52d5a5d..e307b8747c84779 100644
--- a/clang/test/CodeGenCXX/visibility.cpp
+++ b/clang/test/CodeGenCXX/visibility.cpp
@@ -206,6 +206,9 @@ namespace test27 {
// CHECK: @_ZGVZN6test681fC1EvE4test = linkonce_odr global
// CHECK-HIDDEN: @_ZGVZN6test681fC1EvE4test = linkonce_odr hidden global
+// CHECK-HIDDEN: @_ZTVN6test701DE = linkonce_odr hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZTIN6test701DE] }, align 8
+// CHECK-HIDDEN: @_ZTTN6test701DE = linkonce_odr hidden unnamed_addr constant [1 x ptr] [ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTVN6test701DE, i32 0, inrange i32 0, i32 3)], align 8
+
// CHECK: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr global
// CHECK-HIDDEN: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr hidden global
@@ -1422,6 +1425,12 @@ namespace test70 {
~B();
};
B::~B() {}
+
+ // Make sure both the vtable and VTT declarations are marked "hidden"
+ // when "-fvisibilty=hidden" is in use.
+ class C {};
+ class D : virtual C {};
+ D d;
// Check lines at top of file.
}
>From af47d617be5bdbd2b6cbf438a9a5c2f89fe8f3f8 Mon Sep 17 00:00:00 2001
From: Ben Dunbobbin <Ben.Dunbobbin at sony.com>
Date: Tue, 21 Nov 2023 00:55:26 +0000
Subject: [PATCH 2/2] Add comment to explain why the visibility is recomputed
for VTT definitions
---
clang/lib/CodeGen/CGVTT.cpp | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/clang/lib/CodeGen/CGVTT.cpp b/clang/lib/CodeGen/CGVTT.cpp
index 0eab677ca68a85a..1d3f14f1c5344d7 100644
--- a/clang/lib/CodeGen/CGVTT.cpp
+++ b/clang/lib/CodeGen/CGVTT.cpp
@@ -94,7 +94,9 @@ CodeGenVTables::EmitVTTDefinition(llvm::GlobalVariable *VTT,
if (CGM.supportsCOMDAT() && VTT->isWeakForLinker())
VTT->setComdat(CGM.getModule().getOrInsertComdat(VTT->getName()));
- // Set the right visibility.
+ // Set the visibility. This will already have been set on the VTT declaration.
+ // Set it again, now that we have a definition, as the implicit visibility can
+ // apply differently to definitions.
CGM.setGVProperties(VTT, RD);
}
More information about the cfe-commits
mailing list