blob: 3fd0486c7e801b15789d51a4b779f8fbfc6cdc2e [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
Teresa Johnson290a8392019-01-11 18:31:57 +00005; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
Teresa Johnson28023db2018-07-19 14:51:32 +00006
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 Johnson0be99602019-01-17 15:49:04 +000023; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK -dump-input=always
24; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR -dump-input=always
Teresa Johnson28023db2018-07-19 14:51:32 +000025
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 Johnson0be99602019-01-17 15:49:04 +000042; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=REMARK -dump-input=always
43; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR -dump-input=always
Teresa Johnson28023db2018-07-19 14:51:32 +000044
Teresa Johnsonb0a1d3b2018-08-14 03:00:16 +000045; REMARK: single-impl: devirtualized a call to _ZN1A1nEi
46
Teresa Johnson290a8392019-01-11 18:31:57 +000047; Next check that we emit an error when trying to LTO link this module
48; containing an llvm.type.checked.load (with a split LTO Unit) with one
49; that does not have a split LTO Unit.
50; RUN: opt -thinlto-bc -o %t2.o %S/Inputs/empty.ll
51; RUN: not llvm-lto2 run %t.o %t2.o -save-temps -pass-remarks=. \
Teresa Johnson723636e2019-01-18 20:41:49 +000052; RUN: -verify-machineinstrs=0 -thinlto-threads=1 \
Teresa Johnson290a8392019-01-11 18:31:57 +000053; RUN: -o %t3 \
54; RUN: -r=%t.o,test,px \
55; RUN: -r=%t.o,_ZN1A1nEi,p \
56; RUN: -r=%t.o,_ZN1B1fEi,p \
57; RUN: -r=%t.o,_ZN1C1fEi,p \
58; RUN: -r=%t.o,empty,p \
59; RUN: -r=%t.o,_ZTV1B, \
60; RUN: -r=%t.o,_ZTV1C, \
61; RUN: -r=%t.o,_ZN1A1nEi, \
62; RUN: -r=%t.o,_ZN1B1fEi, \
63; RUN: -r=%t.o,_ZN1C1fEi, \
64; RUN: -r=%t.o,_ZTV1B,px \
Teresa Johnson0be99602019-01-17 15:49:04 +000065; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=ERROR -dump-input=always
Teresa Johnson290a8392019-01-11 18:31:57 +000066; ERROR: LLVM ERROR: inconsistent LTO Unit splitting with llvm.type.test or llvm.type.checked.load
67
Teresa Johnson28023db2018-07-19 14:51:32 +000068target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
69target triple = "x86_64-grtev4-linux-gnu"
70
71%struct.A = type { i32 (...)** }
72%struct.B = type { %struct.A }
73%struct.C = type { %struct.A }
74
75@_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
76@_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
77
Teresa Johnson5e1c0e72018-09-18 13:42:24 +000078; Put declaration first to test handling of remarks when the first
79; function has no basic blocks.
80declare void @empty()
81
Teresa Johnson28023db2018-07-19 14:51:32 +000082; CHECK-IR-LABEL: define i32 @test
83define i32 @test(%struct.A* %obj, i32 %a) {
84entry:
85 %0 = bitcast %struct.A* %obj to i8**
86 %vtable5 = load i8*, i8** %0
87
88 %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A")
89 %2 = extractvalue { i8*, i1 } %1, 1
90 br i1 %2, label %cont, label %trap
91
92trap:
93 tail call void @llvm.trap()
94 unreachable
95
96cont:
97 %3 = extractvalue { i8*, i1 } %1, 0
98 %4 = bitcast i8* %3 to i32 (%struct.A*, i32)*
99
100 ; Check that the call was devirtualized.
101 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
102 %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a)
103 %vtable16 = load i8*, i8** %0
104 %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A")
105 %6 = extractvalue { i8*, i1 } %5, 1
106 br i1 %6, label %cont2, label %trap
107
108cont2:
109 %7 = extractvalue { i8*, i1 } %5, 0
110 %8 = bitcast i8* %7 to i32 (%struct.A*, i32)*
111
112 ; Check that traps are conditional. Invalid TYPE_ID can cause
113 ; unconditional traps.
114 ; CHECK-IR: br i1 {{.*}}, label %trap
115
116 ; We still have to call it as virtual.
117 ; CHECK-IR: %call3 = tail call i32 %8
118 %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call)
119 ret i32 %call3
120}
121; CHECK-IR-LABEL: ret i32
122; CHECK-IR-LABEL: }
123
124declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
125declare void @llvm.trap()
126
127declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a)
128declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a)
129declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a)
130
131!0 = !{i64 16, !"_ZTS1A"}
132!1 = !{i64 16, !"_ZTS1B"}
133!2 = !{i64 16, !"_ZTS1C"}