1; REQUIRES: x86-registered-target
2
3; Backend test for distribute ThinLTO with CFI.
4
5; RUN: opt -thinlto-bc -o %t.o %s
6
7; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
8; RUN:   -o %t2.index \
9; RUN:   -r=%t.o,test,px \
10; RUN:   -r=%t.o,_ZTV1B, \
11; RUN:   -r=%t.o,_ZN1B1fEi, \
12; RUN:   -r=%t.o,_ZTV1B,px
13
14; Check that typeids are in the index.
15; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s
16; CHECK-LABEL: <GLOBALVAL_SUMMARY_BLOCK
17; CHECK: <TYPE_ID op0=0 op1=6 op2=3 op3=0 op4=0 op5=0 op6=0 op7=0/>
18; CHECK-LABEL: </GLOBALVAL_SUMMARY_BLOCK
19; CHECK-LABEL: <STRTAB_BLOCK
20; CHECK: blob data = '_ZTS1A'
21; CHECK-LABEL: </STRTAB_BLOCK
22
23; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
24; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
25; RUN:   -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR
26
27; Ensure that backend does not fail generating native code.
28; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
29; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
30; RUN:   -o %t.native.o -x ir %t.o
31
32target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
33target triple = "x86_64-grtev4-linux-gnu"
34
35%struct.B = type { %struct.A }
36%struct.A = type { i32 (...)** }
37
38@_ZTV1B = constant { [3 x i8*] } { [3 x i8*] [i8* undef, i8* undef, i8* undef] }, !type !0
39
40; CHECK-IR-LABEL: define void @test
41define void @test(i8* %b) {
42entry:
43  ; Ensure that traps are conditional. Invalid TYPE_ID can cause
44  ; unconditional traps.
45  ; CHECK-IR: br i1 {{.*}}, label %trap
46  %0 = bitcast i8* %b to i8**
47  %vtable2 = load i8*, i8** %0
48  %1 = tail call i1 @llvm.type.test(i8* %vtable2, metadata !"_ZTS1A")
49  br i1 %1, label %cont, label %trap
50
51trap:
52  tail call void @llvm.trap()
53  unreachable
54
55cont:
56  ; CHECK-IR-LABEL: ret void
57  ret void
58}
59; CHECK-IR-LABEL: }
60
61declare i1 @llvm.type.test(i8*, metadata)
62declare void @llvm.trap()
63
64declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a)
65
66!0 = !{i64 16, !"_ZTS1A"}
67!1 = !{i64 16, !"_ZTS1B"}
68