blob: 134da52857aae736cbd2387c1acf9619e6e98066 [file] [log] [blame]
Teresa Johnson28023db2018-07-19 14:51:32 +00001; REQUIRES: x86-registered-target
2
3; Test CFI devirtualization through the thin link and backend.
4
5; RUN: opt -thinlto-bc -o %t.o %s
6
7; Legacy PM
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +00008; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \
Teresa Johnson28023db2018-07-19 14:51:32 +00009; RUN: -o %t3 \
10; RUN: -r=%t.o,test,px \
11; RUN: -r=%t.o,_ZN1A1nEi,p \
12; RUN: -r=%t.o,_ZN1B1fEi,p \
13; RUN: -r=%t.o,_ZN1C1fEi,p \
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000014; RUN: -r=%t.o,empty,p \
Teresa Johnson28023db2018-07-19 14:51:32 +000015; RUN: -r=%t.o,_ZTV1B, \
16; RUN: -r=%t.o,_ZTV1C, \
17; RUN: -r=%t.o,_ZN1A1nEi, \
18; RUN: -r=%t.o,_ZN1B1fEi, \
19; RUN: -r=%t.o,_ZN1C1fEi, \
20; RUN: -r=%t.o,_ZTV1B,px \
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000021; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK
Teresa Johnson28023db2018-07-19 14:51:32 +000022; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
23
24; New PM
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000025; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm -pass-remarks=. \
Teresa Johnson28023db2018-07-19 14:51:32 +000026; RUN: -o %t3 \
27; RUN: -r=%t.o,test,px \
28; RUN: -r=%t.o,_ZN1A1nEi,p \
29; RUN: -r=%t.o,_ZN1B1fEi,p \
30; RUN: -r=%t.o,_ZN1C1fEi,p \
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000031; RUN: -r=%t.o,empty,p \
Teresa Johnson28023db2018-07-19 14:51:32 +000032; RUN: -r=%t.o,_ZTV1B, \
33; RUN: -r=%t.o,_ZTV1C, \
34; RUN: -r=%t.o,_ZN1A1nEi, \
35; RUN: -r=%t.o,_ZN1B1fEi, \
36; RUN: -r=%t.o,_ZN1C1fEi, \
37; RUN: -r=%t.o,_ZTV1B,px \
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000038; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK
Teresa Johnson28023db2018-07-19 14:51:32 +000039; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
40
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000041; REMARK: single-impl: devirtualized a call to _ZN1A1nEi
42
Teresa Johnson28023db2018-07-19 14:51:32 +000043target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
44target triple = "x86_64-grtev4-linux-gnu"
45
46%struct.A = type { i32 (...)** }
47%struct.B = type { %struct.A }
48%struct.C = type { %struct.A }
49
50@_ZTV1B = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1
51@_ZTV1C = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2
52
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000053; Put declaration first to test handling of remarks when the first
54; function has no basic blocks.
55declare void @empty()
56
Teresa Johnson28023db2018-07-19 14:51:32 +000057; CHECK-IR-LABEL: define i32 @test
58define i32 @test(%struct.A* %obj, i32 %a) {
59entry:
60 %0 = bitcast %struct.A* %obj to i8**
61 %vtable5 = load i8*, i8** %0
62
63 %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A")
64 %2 = extractvalue { i8*, i1 } %1, 1
65 br i1 %2, label %cont, label %trap
66
67trap:
68 tail call void @llvm.trap()
69 unreachable
70
71cont:
72 %3 = extractvalue { i8*, i1 } %1, 0
73 %4 = bitcast i8* %3 to i32 (%struct.A*, i32)*
74
75 ; Check that the call was devirtualized.
76 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
77 %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a)
78 %vtable16 = load i8*, i8** %0
79 %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A")
80 %6 = extractvalue { i8*, i1 } %5, 1
81 br i1 %6, label %cont2, label %trap
82
83cont2:
84 %7 = extractvalue { i8*, i1 } %5, 0
85 %8 = bitcast i8* %7 to i32 (%struct.A*, i32)*
86
87 ; Check that traps are conditional. Invalid TYPE_ID can cause
88 ; unconditional traps.
89 ; CHECK-IR: br i1 {{.*}}, label %trap
90
91 ; We still have to call it as virtual.
92 ; CHECK-IR: %call3 = tail call i32 %8
93 %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
94 ret i32 %call3
95}
96; CHECK-IR-LABEL: ret i32
97; CHECK-IR-LABEL: }
98
99declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
100declare void @llvm.trap()
101
102declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a)
103declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a)
104declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a)
105
106!0 = !{i64 16, !"_ZTS1A"}
107!1 = !{i64 16, !"_ZTS1B"}
108!2 = !{i64 16, !"_ZTS1C"}