blob: 7ade794d498b6e726863e3cec738f0e49fa39599 [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
Francis Visoiu Mistrih0e237d32018-10-30 12:20:17 +00008; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436.
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +00009; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \
Francis Visoiu Mistrih0e237d32018-10-30 12:20:17 +000010; RUN: -verify-machineinstrs=0 \
Teresa Johnson28023db2018-07-19 14:51:32 +000011; RUN: -o %t3 \
12; RUN: -r=%t.o,test,px \
13; RUN: -r=%t.o,_ZN1A1nEi,p \
14; RUN: -r=%t.o,_ZN1B1fEi,p \
15; RUN: -r=%t.o,_ZN1C1fEi,p \
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000016; RUN: -r=%t.o,empty,p \
Teresa Johnson28023db2018-07-19 14:51:32 +000017; RUN: -r=%t.o,_ZTV1B, \
18; RUN: -r=%t.o,_ZTV1C, \
19; RUN: -r=%t.o,_ZN1A1nEi, \
20; RUN: -r=%t.o,_ZN1B1fEi, \
21; RUN: -r=%t.o,_ZN1C1fEi, \
22; RUN: -r=%t.o,_ZTV1B,px \
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000023; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK
Teresa Johnson28023db2018-07-19 14:51:32 +000024; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
25
26; New PM
Francis Visoiu Mistrih0e237d32018-10-30 12:20:17 +000027; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436.
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000028; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm -pass-remarks=. \
Francis Visoiu Mistrih0e237d32018-10-30 12:20:17 +000029; RUN: -verify-machineinstrs=0 \
Teresa Johnson28023db2018-07-19 14:51:32 +000030; RUN: -o %t3 \
31; RUN: -r=%t.o,test,px \
32; RUN: -r=%t.o,_ZN1A1nEi,p \
33; RUN: -r=%t.o,_ZN1B1fEi,p \
34; RUN: -r=%t.o,_ZN1C1fEi,p \
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000035; RUN: -r=%t.o,empty,p \
Teresa Johnson28023db2018-07-19 14:51:32 +000036; RUN: -r=%t.o,_ZTV1B, \
37; RUN: -r=%t.o,_ZTV1C, \
38; RUN: -r=%t.o,_ZN1A1nEi, \
39; RUN: -r=%t.o,_ZN1B1fEi, \
40; RUN: -r=%t.o,_ZN1C1fEi, \
41; RUN: -r=%t.o,_ZTV1B,px \
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000042; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK
Teresa Johnson28023db2018-07-19 14:51:32 +000043; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
44
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000045; REMARK: single-impl: devirtualized a call to _ZN1A1nEi
46
Teresa Johnson28023db2018-07-19 14:51:32 +000047target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
48target triple = "x86_64-grtev4-linux-gnu"
49
50%struct.A = type { i32 (...)** }
51%struct.B = type { %struct.A }
52%struct.C = type { %struct.A }
53
54@_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
55@_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
56
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000057; Put declaration first to test handling of remarks when the first
58; function has no basic blocks.
59declare void @empty()
60
Teresa Johnson28023db2018-07-19 14:51:32 +000061; CHECK-IR-LABEL: define i32 @test
62define i32 @test(%struct.A* %obj, i32 %a) {
63entry:
64 %0 = bitcast %struct.A* %obj to i8**
65 %vtable5 = load i8*, i8** %0
66
67 %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A")
68 %2 = extractvalue { i8*, i1 } %1, 1
69 br i1 %2, label %cont, label %trap
70
71trap:
72 tail call void @llvm.trap()
73 unreachable
74
75cont:
76 %3 = extractvalue { i8*, i1 } %1, 0
77 %4 = bitcast i8* %3 to i32 (%struct.A*, i32)*
78
79 ; Check that the call was devirtualized.
80 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
81 %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a)
82 %vtable16 = load i8*, i8** %0
83 %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A")
84 %6 = extractvalue { i8*, i1 } %5, 1
85 br i1 %6, label %cont2, label %trap
86
87cont2:
88 %7 = extractvalue { i8*, i1 } %5, 0
89 %8 = bitcast i8* %7 to i32 (%struct.A*, i32)*
90
91 ; Check that traps are conditional. Invalid TYPE_ID can cause
92 ; unconditional traps.
93 ; CHECK-IR: br i1 {{.*}}, label %trap
94
95 ; We still have to call it as virtual.
96 ; CHECK-IR: %call3 = tail call i32 %8
97 %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
98 ret i32 %call3
99}
100; CHECK-IR-LABEL: ret i32
101; CHECK-IR-LABEL: }
102
103declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
104declare void @llvm.trap()
105
106declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a)
107declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a)
108declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a)
109
110!0 = !{i64 16, !"_ZTS1A"}
111!1 = !{i64 16, !"_ZTS1B"}
112!2 = !{i64 16, !"_ZTS1C"}