summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGenCXX/vcall-visibility-metadata.cpp88
-rw-r--r--clang/test/CodeGenCXX/virtual-function-elimination.cpp75
-rw-r--r--clang/test/Driver/virtual-function-elimination.cpp11
3 files changed, 174 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/vcall-visibility-metadata.cpp b/clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
new file mode 100644
index 00000000000..7cf48395673
--- /dev/null
+++ b/clang/test/CodeGenCXX/vcall-visibility-metadata.cpp
@@ -0,0 +1,88 @@
+// RUN: %clang_cc1 -flto -flto-unit -triple x86_64-unknown-linux -emit-llvm -fvirtual-function-elimination -fwhole-program-vtables -o - %s | FileCheck %s
+
+
+// Anonymous namespace.
+namespace {
+// CHECK: @_ZTVN12_GLOBAL__N_11AE = {{.*}} !vcall_visibility [[VIS_TU:![0-9]+]]
+struct A {
+ A() {}
+ virtual int f() { return 1; }
+};
+}
+void *construct_A() {
+ return new A();
+}
+
+
+// Hidden visibility.
+// CHECK: @_ZTV1B = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+struct __attribute__((visibility("hidden"))) B {
+ B() {}
+ virtual int f() { return 1; }
+};
+B *construct_B() {
+ return new B();
+}
+
+
+// Default visibility.
+// CHECK-NOT: @_ZTV1C = {{.*}} !vcall_visibility
+struct __attribute__((visibility("default"))) C {
+ C() {}
+ virtual int f() { return 1; }
+};
+C *construct_C() {
+ return new C();
+}
+
+
+// Hidden visibility, public LTO visibility.
+// CHECK-NOT: @_ZTV1D = {{.*}} !vcall_visibility
+struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] D {
+ D() {}
+ virtual int f() { return 1; }
+};
+D *construct_D() {
+ return new D();
+}
+
+
+// Hidden visibility, but inherits from class with default visibility.
+// CHECK-NOT: @_ZTV1E = {{.*}} !vcall_visibility
+struct __attribute__((visibility("hidden"))) E : C {
+ E() {}
+ virtual int f() { return 1; }
+};
+E *construct_E() {
+ return new E();
+}
+
+
+// Anonymous namespace, but inherits from class with default visibility.
+// CHECK-NOT: @_ZTVN12_GLOBAL__N_11FE = {{.*}} !vcall_visibility
+namespace {
+struct __attribute__((visibility("hidden"))) F : C {
+ F() {}
+ virtual int f() { return 1; }
+};
+}
+void *construct_F() {
+ return new F();
+}
+
+
+// Anonymous namespace, but inherits from class with hidden visibility.
+// CHECK: @_ZTVN12_GLOBAL__N_11GE = {{.*}} !vcall_visibility [[VIS_DSO:![0-9]+]]
+namespace {
+struct __attribute__((visibility("hidden"))) G : B {
+ G() {}
+ virtual int f() { return 1; }
+};
+}
+void *construct_G() {
+ return new G();
+}
+
+
+// CHECK-DAG: [[VIS_DSO]] = !{i64 1}
+// CHECK-DAG: [[VIS_TU]] = !{i64 2}
diff --git a/clang/test/CodeGenCXX/virtual-function-elimination.cpp b/clang/test/CodeGenCXX/virtual-function-elimination.cpp
new file mode 100644
index 00000000000..a89e6ebceea
--- /dev/null
+++ b/clang/test/CodeGenCXX/virtual-function-elimination.cpp
@@ -0,0 +1,75 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -flto -flto-unit -fvirtual-function-elimination -fwhole-program-vtables -emit-llvm -o - %s | FileCheck %s
+
+
+struct __attribute__((visibility("default"))) A {
+ virtual void foo();
+};
+
+void test_1(A *p) {
+ // A has default visibility, so no need for type.checked.load.
+// CHECK-LABEL: define void @_Z6test_1P1A
+// CHECK: [[FN_PTR_ADDR:%.+]] = getelementptr inbounds void (%struct.A*)*, void (%struct.A*)** {{%.+}}, i64 0
+// CHECK: [[FN_PTR:%.+]] = load void (%struct.A*)*, void (%struct.A*)** [[FN_PTR_ADDR]]
+// CHECK: call void [[FN_PTR]](
+ p->foo();
+}
+
+
+struct __attribute__((visibility("hidden"))) [[clang::lto_visibility_public]] B {
+ virtual void foo();
+};
+
+void test_2(B *p) {
+ // B has public LTO visibility, so no need for type.checked.load.
+// CHECK-LABEL: define void @_Z6test_2P1B
+// CHECK: [[FN_PTR_ADDR:%.+]] = getelementptr inbounds void (%struct.B*)*, void (%struct.B*)** {{%.+}}, i64 0
+// CHECK: [[FN_PTR:%.+]] = load void (%struct.B*)*, void (%struct.B*)** [[FN_PTR_ADDR]]
+// CHECK: call void [[FN_PTR]](
+ p->foo();
+}
+
+
+struct __attribute__((visibility("hidden"))) C {
+ virtual void foo();
+ virtual void bar();
+};
+
+void test_3(C *p) {
+ // C has hidden visibility, so we generate type.checked.load to allow VFE.
+// CHECK-LABEL: define void @_Z6test_3P1C
+// CHECK: [[LOAD:%.+]] = call { i8*, i1 } @llvm.type.checked.load(i8* {{%.+}}, i32 0, metadata !"_ZTS1C")
+// CHECK: [[FN_PTR_I8:%.+]] = extractvalue { i8*, i1 } [[LOAD]], 0
+// CHECK: [[FN_PTR:%.+]] = bitcast i8* [[FN_PTR_I8]] to void (%struct.C*)*
+// CHECK: call void [[FN_PTR]](
+ p->foo();
+}
+
+void test_4(C *p) {
+ // When using type.checked.load, we pass the vtable offset to the intrinsic,
+ // rather than adding it to the pointer with a GEP.
+// CHECK-LABEL: define void @_Z6test_4P1C
+// CHECK: [[LOAD:%.+]] = call { i8*, i1 } @llvm.type.checked.load(i8* {{%.+}}, i32 8, metadata !"_ZTS1C")
+// CHECK: [[FN_PTR_I8:%.+]] = extractvalue { i8*, i1 } [[LOAD]], 0
+// CHECK: [[FN_PTR:%.+]] = bitcast i8* [[FN_PTR_I8]] to void (%struct.C*)*
+// CHECK: call void [[FN_PTR]](
+ p->bar();
+}
+
+void test_5(C *p, void (C::*q)(void)) {
+ // We also use type.checked.load for the virtual side of member function
+ // pointer calls. We use a GEP to calculate the address to load from and pass
+ // 0 as the offset to the intrinsic, because we know that the load must be
+ // from exactly the point marked by one of the function-type metadatas (in
+ // this case "_ZTSM1CFvvE.virtual"). If we passed the offset from the member
+ // function pointer to the intrinsic, this information would be lost. No
+ // codegen changes on the non-virtual side.
+// CHECK-LABEL: define void @_Z6test_5P1CMS_FvvE(
+// CHECK: [[FN_PTR_ADDR:%.+]] = getelementptr i8, i8* %vtable, i64 {{%.+}}
+// CHECK: [[LOAD:%.+]] = call { i8*, i1 } @llvm.type.checked.load(i8* [[FN_PTR_ADDR]], i32 0, metadata !"_ZTSM1CFvvE.virtual")
+// CHECK: [[FN_PTR_I8:%.+]] = extractvalue { i8*, i1 } [[LOAD]], 0
+// CHECK: [[FN_PTR:%.+]] = bitcast i8* [[FN_PTR_I8]] to void (%struct.C*)*
+
+// CHECK: [[PHI:%.+]] = phi void (%struct.C*)* {{.*}}[ [[FN_PTR]], {{.*}} ]
+// CHECK: call void [[PHI]](
+ (p->*q)();
+}
diff --git a/clang/test/Driver/virtual-function-elimination.cpp b/clang/test/Driver/virtual-function-elimination.cpp
new file mode 100644
index 00000000000..3a026bbb434
--- /dev/null
+++ b/clang/test/Driver/virtual-function-elimination.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang -target x86_64-unknown-linux -fvirtual-function-elimination -### %s 2>&1 | FileCheck --check-prefix=BAD-LTO %s
+// RUN: %clang -target x86_64-unknown-linux -fvirtual-function-elimination -flto=thin -### %s 2>&1 | FileCheck --check-prefix=BAD-LTO %s
+// BAD-LTO: invalid argument '-fvirtual-function-elimination' only allowed with '-flto=full'
+
+// RUN: %clang -target x86_64-unknown-linux -fvirtual-function-elimination -flto -### %s 2>&1 | FileCheck --check-prefix=GOOD %s
+// RUN: %clang -target x86_64-unknown-linux -fvirtual-function-elimination -flto=full -### %s 2>&1 | FileCheck --check-prefix=GOOD %s
+// RUN: %clang -target x86_64-unknown-linux -fvirtual-function-elimination -flto -fwhole-program-vtables -### %s 2>&1 | FileCheck --check-prefix=GOOD %s
+// GOOD: "-fvirtual-function-elimination" "-fwhole-program-vtables"
+
+// RUN: %clang -target x86_64-unknown-linux -fvirtual-function-elimination -fno-whole-program-vtables -flto -### %s 2>&1 | FileCheck --check-prefix=NO-WHOLE-PROGRAM-VTABLES %s
+// NO-WHOLE-PROGRAM-VTABLES: invalid argument '-fno-whole-program-vtables' not allowed with '-fvirtual-function-elimination'
OpenPOWER on IntegriCloud