1 // Test distributed ThinLTO backend handling of type tests
2 
3 // REQUIRES: x86-registered-target
4 
5 // Ensure that a distributed backend invocation of ThinLTO lowers the type test
6 // as expected.
7 // RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux -fwhole-program-vtables -emit-llvm-bc -o %t.o %s
8 // RUN: llvm-dis %t.o -o - | FileCheck --check-prefix=TT %s
9 // RUN: llvm-lto -thinlto -o %t2 %t.o
10 // RUN: %clang -target x86_64-unknown-linux -O2 -o %t3.o -x ir %t.o -c -fthinlto-index=%t2.thinlto.bc -save-temps=obj
11 // RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
12 // llvm-nm %t3.o | FileCheck --check-prefix=NM %s
13 
14 // The pre-link bitcode produced by clang should contain a type test assume
15 // sequence.
16 // TT: [[TTREG:%[0-9]+]] = call i1 @llvm.type.test({{.*}}, metadata !"_ZTS1A")
17 // TT: void @llvm.assume(i1 [[TTREG]])
18 
19 // The ThinLTO backend optimized bitcode should not have any type test assume
20 // sequences.
21 // OPT-NOT: @llvm.type.test
22 // OPT-NOT: call void @llvm.assume
23 // We should have only one @llvm.assume call, the one that was expanded
24 // from the builtin in the IR below, not the one fed by the type test.
25 // OPT: %cmp = icmp ne %struct.A* %{{.*}}, null
26 // OPT: void @llvm.assume(i1 %cmp)
27 // Check after the builtin assume again that we don't have a type test assume
28 // sequence.
29 // OPT-NOT: @llvm.type.test
30 // OPT-NOT: call void @llvm.assume
31 
32 // NM: T _Z2afP1A
33 
34 // Also check type test are lowered when the distributed ThinLTO backend clang
35 // invocation is passed an empty index file, in which case a non-ThinLTO
36 // compilation pipeline is invoked. If not lowered then LLVM CodeGen may assert.
37 // RUN: touch %t4.thinlto.bc
38 // O2 old PM
39 // RUN: %clang -target x86_64-unknown-linux -O2 -o %t4.o -x ir %t.o -c -fthinlto-index=%t4.thinlto.bc -save-temps=obj
40 // RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
41 // llvm-nm %t4.o | FileCheck --check-prefix=NM %s
42 // O2 new PM
43 // RUN: %clang -target x86_64-unknown-linux -O2 -o %t4.o -x ir %t.o -c -fthinlto-index=%t4.thinlto.bc -fexperimental-new-pass-manager -save-temps=obj
44 // RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
45 // llvm-nm %t4.o | FileCheck --check-prefix=NM %s
46 // O0 new PM
47 // RUN: %clang -target x86_64-unknown-linux -O0 -o %t4.o -x ir %t.o -c -fthinlto-index=%t4.thinlto.bc -fexperimental-new-pass-manager -save-temps=obj
48 // RUN: llvm-dis %t.s.4.opt.bc -o - | FileCheck --check-prefix=OPT %s
49 // llvm-nm %t4.o | FileCheck --check-prefix=NM %s
50 
51 struct A {
52   A();
53   virtual void f();
54 };
55 
56 struct B : virtual A {
57   B();
58 };
59 
A()60 A::A() {}
B()61 B::B() {}
62 
f()63 void A::f() {
64 }
65 
af(A * a)66 void af(A *a) {
67   __builtin_assume(a != 0);
68   a->f();
69 }
70