[clang] [ItaniumCXXABI] Mark RTTI type name as global unnamed_addr (PR #111343)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 7 00:30:47 PDT 2024
https://github.com/luxufan created https://github.com/llvm/llvm-project/pull/111343
The RTTI type name global variable should be marked as global unnamed_addr since the address of RTTI type name global variable
is not significant.
>From cabe9e1ac1305d970d944183ebf10effe783f5fc Mon Sep 17 00:00:00 2001
From: luxufan <luxufan981014 at gmail.com>
Date: Mon, 7 Oct 2024 07:14:06 +0000
Subject: [PATCH] [ItaniumCXXABI] Mark RTTI type name as global unnamed_addr
The RTTI type name global variable should be marked as global
unnamed_addr since the address of RTTI type name global variable
is not significant.
---
clang/lib/CodeGen/ItaniumCXXABI.cpp | 1 +
clang/test/CodeGen/split-lto-unit-input.cpp | 4 ++--
.../RelativeVTablesABI/parent-vtable-in-comdat.cpp | 2 +-
clang/test/CodeGenCXX/anonymous-namespaces.cpp | 2 +-
clang/test/CodeGenCXX/arm64.cpp | 12 ++++++------
clang/test/CodeGenCXX/armv7k.cpp | 14 ++++----------
.../test/CodeGenCXX/windows-itanium-type-info.cpp | 14 ++++----------
7 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 965e09a7a760ec..4b9cd70ce4d55d 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3532,6 +3532,7 @@ llvm::GlobalVariable *ItaniumRTTIBuilder::GetAddrOfTypeName(
Name, Init->getType(), Linkage, Align.getAsAlign());
GV->setInitializer(Init);
+ GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
return GV;
}
diff --git a/clang/test/CodeGen/split-lto-unit-input.cpp b/clang/test/CodeGen/split-lto-unit-input.cpp
index adfc9ac3e0f446..99de0f68f84978 100644
--- a/clang/test/CodeGen/split-lto-unit-input.cpp
+++ b/clang/test/CodeGen/split-lto-unit-input.cpp
@@ -12,8 +12,8 @@
// CHECK-NEXT: V _ZTV1A
// CHECK-NEXT: V _ZTV1B
-// CHECK-IR-DAG: _ZTS1B = linkonce_odr constant
-// CHECK-IR-DAG: _ZTS1A = linkonce_odr constant
+// CHECK-IR-DAG: _ZTS1B = linkonce_odr unnamed_addr constant
+// CHECK-IR-DAG: _ZTS1A = linkonce_odr unnamed_addr constant
// CHECK-IR-DAG: _ZTV1B = linkonce_odr unnamed_addr constant
// CHECK-IR-DAG: _ZTI1A = linkonce_odr constant
// CHECK-IR-DAG: _ZTI1B = linkonce_odr constant
diff --git a/clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp b/clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
index 341c53146d476d..6a833cf3884546 100644
--- a/clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
+++ b/clang/test/CodeGenCXX/RelativeVTablesABI/parent-vtable-in-comdat.cpp
@@ -16,7 +16,7 @@
// The VTable for A is emitted here and in a comdat section since it has no key function, and is used in this module when creating an instance of A.
// CHECK: @_ZTV1A.local = linkonce_odr hidden unnamed_addr constant { [3 x i32] } { [3 x i32] [i32 0, i32 trunc (i64 sub (i64 ptrtoint (ptr @_ZTI1A.rtti_proxy to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @_ZN1A3fooEv to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32)] }, comdat($_ZTV1A), align 4
// CHECK: @_ZTVN10__cxxabiv117__class_type_infoE = external global [0 x ptr]
-// CHECK: @_ZTS1A = linkonce_odr constant [3 x i8] c"1A\00", comdat, align 1
+// CHECK: @_ZTS1A = linkonce_odr unnamed_addr constant [3 x i8] c"1A\00", comdat, align 1
// CHECK: @_ZTI1A = linkonce_odr constant { ptr, ptr } { ptr getelementptr inbounds (i8, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i32 8), ptr @_ZTS1A }, comdat, align 8
// CHECK: @_ZTI1A.rtti_proxy = linkonce_odr hidden unnamed_addr constant ptr @_ZTI1A, comdat
// CHECK: @_ZTV1A = linkonce_odr unnamed_addr alias { [3 x i32] }, ptr @_ZTV1A.local
diff --git a/clang/test/CodeGenCXX/anonymous-namespaces.cpp b/clang/test/CodeGenCXX/anonymous-namespaces.cpp
index f40039c2a4f400..eb185be52c15a4 100644
--- a/clang/test/CodeGenCXX/anonymous-namespaces.cpp
+++ b/clang/test/CodeGenCXX/anonymous-namespaces.cpp
@@ -29,7 +29,7 @@ namespace {
int D::d = f();
// Check for generation of a VTT with internal linkage
- // CHECK-1: @_ZTSN12_GLOBAL__N_11X1EE = internal constant
+ // CHECK-1: @_ZTSN12_GLOBAL__N_11X1EE = internal unnamed_addr constant
struct X {
struct EBase { };
struct E : public virtual EBase { virtual ~E() {} };
diff --git a/clang/test/CodeGenCXX/arm64.cpp b/clang/test/CodeGenCXX/arm64.cpp
index 338b7db9e001f2..f452cf9a8b5072 100644
--- a/clang/test/CodeGenCXX/arm64.cpp
+++ b/clang/test/CodeGenCXX/arm64.cpp
@@ -48,20 +48,20 @@ namespace test2 {
struct __attribute__((visibility("hidden"))) B {};
const std::type_info &b0 = typeid(B);
- // CHECK-GLOBALS-DAG: @_ZTSN5test21BE = linkonce_odr hidden constant
+ // CHECK-GLOBALS-DAG: @_ZTSN5test21BE = linkonce_odr hidden unnamed_addr constant
// CHECK-GLOBALS-DAG: @_ZTIN5test21BE = linkonce_odr hidden constant { {{.*}}, ptr @_ZTSN5test21BE }
const std::type_info &b1 = typeid(B*);
- // CHECK-GLOBALS-DAG: @_ZTSPN5test21BE = linkonce_odr hidden constant
+ // CHECK-GLOBALS-DAG: @_ZTSPN5test21BE = linkonce_odr hidden unnamed_addr constant
// CHECK-GLOBALS-DAG: @_ZTIPN5test21BE = linkonce_odr hidden constant { {{.*}}, ptr @_ZTSPN5test21BE, i32 0, ptr @_ZTIN5test21BE
struct C {};
const std::type_info &c0 = typeid(C);
- // CHECK-GLOBALS-DAG: @_ZTSN5test21CE = linkonce_odr hidden constant
+ // CHECK-GLOBALS-DAG: @_ZTSN5test21CE = linkonce_odr hidden unnamed_addr constant
// CHECK-GLOBALS-DAG: @_ZTIN5test21CE = linkonce_odr hidden constant { {{.*}}, ptr inttoptr (i64 add (i64 ptrtoint (ptr @_ZTSN5test21CE to i64), i64 -9223372036854775808) to ptr) }
const std::type_info &c1 = typeid(C*);
- // CHECK-GLOBALS-DAG: @_ZTSPN5test21CE = linkonce_odr hidden constant
+ // CHECK-GLOBALS-DAG: @_ZTSPN5test21CE = linkonce_odr hidden unnamed_addr constant
// CHECK-GLOBALS-DAG: @_ZTIPN5test21CE = linkonce_odr hidden constant { {{.*}}, ptr inttoptr (i64 add (i64 ptrtoint (ptr @_ZTSPN5test21CE to i64), i64 -9223372036854775808) to ptr), i32 0, ptr @_ZTIN5test21CE
// This class is explicitly-instantiated, but that instantiation
@@ -69,7 +69,7 @@ namespace test2 {
template <class T> class D {};
template class D<int>;
const std::type_info &d0 = typeid(D<int>);
- // CHECK-GLOBALS-DAG: @_ZTSN5test21DIiEE = linkonce_odr hidden constant
+ // CHECK-GLOBALS-DAG: @_ZTSN5test21DIiEE = linkonce_odr hidden unnamed_addr constant
// CHECK-GLOBALS-DAG: @_ZTIN5test21DIiEE = linkonce_odr hidden constant { {{.*}}, ptr inttoptr (i64 add (i64 ptrtoint (ptr @_ZTSN5test21DIiEE to i64), i64 -9223372036854775808) to ptr) }
// This class is explicitly-instantiated and *does* guarantee to
@@ -78,7 +78,7 @@ namespace test2 {
virtual void foo() {}
};
template class E<int>;
- // CHECK-GLOBALS-DAG: @_ZTSN5test21EIiEE = weak_odr constant [14 x i8]
+ // CHECK-GLOBALS-DAG: @_ZTSN5test21EIiEE = weak_odr unnamed_addr constant [14 x i8]
// CHECK-GLOBALS-DAG: @_ZTIN5test21EIiEE = weak_odr constant { {{.*}}, ptr inttoptr (i64 add (i64 ptrtoint (ptr @_ZTSN5test21EIiEE to i64), i64 -9223372036854775808) to ptr) }
}
diff --git a/clang/test/CodeGenCXX/armv7k.cpp b/clang/test/CodeGenCXX/armv7k.cpp
index a4a243c162ea3f..a8496c85bc0733 100644
--- a/clang/test/CodeGenCXX/armv7k.cpp
+++ b/clang/test/CodeGenCXX/armv7k.cpp
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
// RUN: %clang_cc1 %s -triple=thumbv7k-apple-watchos -emit-llvm -o - -target-abi aapcs16 | FileCheck %s
// RUN: %clang_cc1 %s -triple=thumbv7k-apple-watchos -emit-llvm -o - -target-abi aapcs16 | FileCheck -check-prefix=CHECK-GLOBALS %s
@@ -10,7 +11,6 @@ struct A {
};
void f() {
- // CHECK: call i32 @__cxa_guard_acquire(ptr
static A a;
}
@@ -31,8 +31,6 @@ namespace test1 {
int test() {
return sizeof(B);
}
- // CHECK: define{{.*}} i32 @_ZN5test14testEv()
- // CHECK: ret i32 12
}
namespace std {
@@ -50,20 +48,16 @@ namespace test2 {
struct __attribute__((visibility("hidden"))) B {};
const std::type_info &b0 = typeid(B);
- // CHECK-GLOBALS: @_ZTSN5test21BE = linkonce_odr hidden constant
- // CHECK-GLOBALS: @_ZTIN5test21BE = linkonce_odr hidden constant { {{.*}}, ptr @_ZTSN5test21BE }
const std::type_info &b1 = typeid(B*);
- // CHECK-GLOBALS: @_ZTSPN5test21BE = linkonce_odr hidden constant
- // CHECK-GLOBALS: @_ZTIPN5test21BE = linkonce_odr hidden constant { {{.*}}, ptr @_ZTSPN5test21BE, i32 0, ptr @_ZTIN5test21BE
struct C {};
const std::type_info &c0 = typeid(C);
- // CHECK-GLOBALS: @_ZTSN5test21CE = linkonce_odr constant [11 x i8] c"N5test21CE\00"
- // CHECK-GLOBALS: @_ZTIN5test21CE = linkonce_odr constant { {{.*}}, ptr @_ZTSN5test21CE }
}
// va_list should be based on "char *" rather than "ptr".
-// CHECK: define{{.*}} void @_Z11whatsVaListPc
void whatsVaList(__builtin_va_list l) {}
+//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+// CHECK: {{.*}}
+// CHECK-GLOBALS: {{.*}}
diff --git a/clang/test/CodeGenCXX/windows-itanium-type-info.cpp b/clang/test/CodeGenCXX/windows-itanium-type-info.cpp
index 20bd78df509837..709059cc7f06c6 100644
--- a/clang/test/CodeGenCXX/windows-itanium-type-info.cpp
+++ b/clang/test/CodeGenCXX/windows-itanium-type-info.cpp
@@ -1,3 +1,4 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5
// RUN: %clang_cc1 -triple i686-windows-itanium -fdeclspec -fcxx-exceptions -emit-llvm %s -o - | FileCheck %s
// RUN: %clang_cc1 -triple i686-windows-itanium -fdeclspec -fcxx-exceptions -fno-rtti -emit-llvm %s -o - | FileCheck %s -check-prefix CHECK-EH-IMPORT
@@ -24,17 +25,9 @@ void f() {
throw base();
}
-// CHECK-DAG: @_ZTIi = dso_local dllexport constant
-// CHECK-DAG: @_ZTSi = dso_local dllexport constant
-// CHECK-DAG: @_ZTI7derived = dso_local dllexport constant
-// CHECK-DAG: @_ZTS7derived = dso_local dllexport constant
-// CHECK-DAG: @_ZTV7derived = dso_local dllexport unnamed_addr constant
-// CHECK-DAG: @_ZTI4base = external dllimport constant
-// CHECK-EH-IMPORT: @_ZTS4base = linkonce_odr dso_local constant
-// CHECK-EH-IMPORT: @_ZTI4base = linkonce_odr dso_local constant
struct __declspec(dllimport) gatekeeper {};
struct zuul : gatekeeper {
@@ -42,5 +35,6 @@ struct zuul : gatekeeper {
};
zuul::~zuul() {}
-// CHECK-DAG: @_ZTI10gatekeeper = linkonce_odr dso_local constant
-// CHECK-DAG: @_ZTS10gatekeeper = linkonce_odr dso_local constant
+//// NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
+// CHECK: {{.*}}
+// CHECK-EH-IMPORT: {{.*}}
More information about the cfe-commits
mailing list