-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[ItaniumCXXABI] Mark RTTI type name as global unnamed_addr #111343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
|
@llvm/pr-subscribers-clang-codegen Author: None (luxufan) ChangesThe RTTI type name global variable should be marked as global unnamed_addr since the address of RTTI type name global variable Full diff: https://github.com/llvm/llvm-project/pull/111343.diff 7 Files Affected:
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: {{.*}}
|
|
@llvm/pr-subscribers-clang Author: None (luxufan) ChangesThe RTTI type name global variable should be marked as global unnamed_addr since the address of RTTI type name global variable Full diff: https://github.com/llvm/llvm-project/pull/111343.diff 7 Files Affected:
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: {{.*}}
|
|
The failed test files have not been addressed for all. I will update them once this change can be approved. |
|
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-rtti and https://itanium-cxx-abi.github.io/cxx-abi/abi.html#typeid in the ABI require the type name string to be globally unique, and some |
|
Specifically: we do perform address comparisons between these strings, so the address is significant. And we can have identical string content but different types:
so in a few cases allowing merging could be bad. Most of that only applies during dynamic linking. Do we have a guarantee that |
Thanks for your reply! Yes, you are right. I checked the llvm's libcxx code, Here https://github.com/llvm/llvm-project/blob/main/libcxx/include/typeinfo#L320, it compares the equality of two types by the address of type name string. But, I have a question: now that it has ensured the uniqueness of typeinfo's address, why does the implementation still compare the type equality by the address of type name string?
For symbols with internal linkage or hidden visibility, I don't think there would be problems if they were allowed to be merged. For example, considering there are 2 translation units 0.cpp and 1.cpp, and we defined internal For dynamic loading, if there are two same symbols in different DSOs, the symbol would be interposed. So in this case, even if there is no unnamed_addr, the address uniqueness still could not be ensured. |
The uniqueness of the address of the
Such comparisons can happen in valid C++ code. For example: // a.cc
namespace { class A {}; }
void throwA() { throw A(); }// b.cc
namespace { class A {}; }
void throwA();
int main() {
try { throwA(); }
catch (A) { return 1; }
catch (...) { return 2; }
}This program is valid and
Not in the cases I mentioned. (I think we can probably get away with marking type name strings as You can still apply I think it's also correct and safe to apply |
|
Thanks for your detailed explanation! I have updated the PR.
I think it is also safe to apply |
zygoloid
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. Looking at https://reviews.llvm.org/D20348 it seems like unnamed_addr and local_unnamed_addr don't just permit merging, but also cloning of the global (so that the same global could have different addresses in different modules). Cloning wouldn't be correct in the unique RTTI case, and would be a (potentially large) performance regression in the non-unique case.
But I'm not certain about that. @pcc, can you confirm the intent here? Is there a way we can permit ICF without also permitting duplication of the constant?
| // And the name. | ||
| llvm::GlobalVariable *TypeName = GetAddrOfTypeName(Ty, Linkage); | ||
| llvm::Constant *TypeNameField; | ||
| llvm::GlobalValue::UnnamedAddr Scope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scope isn't a very clear name here. Maybe rename this to something like UnnamedAddrScope?
|
unnamed_addr doesn't allow cloning; there's no way to make it work in a reasonable way even if we wanted it. See, for example, #32127 . |
OK. The LangRef is very vague on its semantics, would be nice to get that clarified by someone who knows the intent. Is the same true for |
|
Oh... GlobalValue::canBeOmittedFromSymbolTable is a rabbit-hole I didn't know existed. Apparently I don't know how unnamed_addr works. (canBeOmittedFromSymbolTable is completely inconsistent with the way everything else in the compiler reasons about unnamed_addr.) |
|
@luxufan I think we may need changes on the LLVM side before we can make progress here -- either to clarify what But before we go down that path, this PR doesn't describe the motivation for this change, so it'd be useful to get an idea of how much of a difference you expect this to make. Are you seeing a lot of duplicated symbols containing type manglings? |
@zygoloid In our downstream project, we are trying to remove redundant RTTI data (type info and type name strings) in ThinLTO. To avoid some undefined symbols errors after elimination, I need to check the CanAutoHide flag https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/ModuleSummaryIndex.h#L500 to decide if the symbol can be eliminated. The CanAutoHide flag is implied by function https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/IR/ModuleSummaryIndex.h#L500 which is partly implied by the unnamed_addr attribute. So if type info or type name string can be marked as unnamed_addr or local_unnamed_addr, it makes our implementation simple and correct. Of course, mark as unnamed_addr or local_unnamed_addr is one of the solution, I can also add an extra flags in the module summary index to solve our problem. |
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.