1; REQUIRES: x86-registered-target
2
3; Test CFI devirtualization through the thin link and backend when
4; a type id is Unsat (not used on any global's type metadata).
5;
6; In this test case, the first module is split and will import a resolution
7; for its type test. The resolution would be exported by the second
8; module, which is set up so that it does not get split (treated as regular
9; LTO because it does not have any external globals from which to create
10; a unique module ID). We should not actually get any resolution for the
11; type id in this case, since no globals include it in their type metadata,
12; so the resolution is Unsat and the type.checked.load instructions are
13; converted to type tests that evaluate to false.
14
15; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
16; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t1.o %p/Inputs/cfi-unsat.ll
17
18; RUN: llvm-lto2 run %t.o %t1.o -save-temps -use-new-pm -pass-remarks=. \
19; RUN:   -whole-program-visibility \
20; RUN:   -o %t3 \
21; RUN:   -r=%t.o,test2,px \
22; RUN:   -r=%t1.o,_ZTV1B,px \
23; RUN:   -r=%t1.o,test,px \
24; RUN:   -r=%t1.o,testb,px
25; RUN: llvm-dis %t3.index.bc -o - | FileCheck %s --check-prefix=INDEX
26; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR0
27; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
28
29; INDEX-NOT: "typeid:"
30
31target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
32target triple = "x86_64-grtev4-linux-gnu"
33
34%struct.A = type { i32 (...)** }
35
36$test2 = comdat any
37
38define linkonce_odr i32 @test2(%struct.A* %obj, i32 %a) comdat {
39entry:
40  %0 = bitcast %struct.A* %obj to i8**
41  %vtable5 = load i8*, i8** %0
42
43  %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A")
44  %2 = extractvalue { i8*, i1 } %1, 1
45  br i1 %2, label %cont, label %trap
46
47trap:
48  tail call void @llvm.trap()
49  unreachable
50
51cont:
52  %3 = extractvalue { i8*, i1 } %1, 0
53  %4 = bitcast i8* %3 to i32 (%struct.A*, i32)*
54
55  %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a)
56
57  ret i32 %call
58}
59
60; CHECK-IR0: define weak_odr i32 @test
61; CHECK-IR0-NEXT: entry:
62; CHECK-IR0-NEXT: %0 = bitcast
63; CHECK-IR0-NEXT: %vtable5 =
64; CHECK-IR0-NEXT: tail call void @llvm.trap()
65; CHECK-IR0-NEXT: unreachable
66; CHECK-IR0-NEXT: }
67; CHECK-IR0: define weak_odr i32 @testb
68; CHECK-IR0-NEXT: entry:
69; CHECK-IR0-NEXT: %0 = bitcast
70; CHECK-IR0-NEXT: %vtable5 =
71; CHECK-IR0-NEXT: tail call void @llvm.trap()
72; CHECK-IR0-NEXT: unreachable
73; CHECK-IR0-NEXT: }
74
75; CHECK-IR1: define weak_odr i32 @test2
76; CHECK-IR1-NEXT:   entry:
77; CHECK-IR1-NEXT:     tail call void @llvm.trap()
78; CHECK-IR1-NEXT:     unreachable
79; CHECK-IR1-NEXT:   }
80
81declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
82declare void @llvm.trap()
83