Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 1 | ; REQUIRES: x86-registered-target |
| 2 | |
| 3 | ; Test CFI devirtualization through the thin link and backend. |
| 4 | |
Teresa Johnson | 290a839 | 2019-01-11 18:31:57 +0000 | [diff] [blame] | 5 | ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 6 | |
| 7 | ; Legacy PM |
Francis Visoiu Mistrih | 0e237d3 | 2018-10-30 12:20:17 +0000 | [diff] [blame] | 8 | ; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436. |
Teresa Johnson | b0a1d3b | 2018-08-14 03:00:16 +0000 | [diff] [blame] | 9 | ; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \ |
Francis Visoiu Mistrih | 0e237d3 | 2018-10-30 12:20:17 +0000 | [diff] [blame] | 10 | ; RUN: -verify-machineinstrs=0 \ |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 11 | ; 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 Johnson | 5e1c0e7 | 2018-09-18 13:42:24 +0000 | [diff] [blame] | 16 | ; RUN: -r=%t.o,empty,p \ |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 17 | ; 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 Johnson | 0be9960 | 2019-01-17 15:49:04 +0000 | [diff] [blame] | 23 | ; 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 Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 25 | |
| 26 | ; New PM |
Francis Visoiu Mistrih | 0e237d3 | 2018-10-30 12:20:17 +0000 | [diff] [blame] | 27 | ; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436. |
Teresa Johnson | b0a1d3b | 2018-08-14 03:00:16 +0000 | [diff] [blame] | 28 | ; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm -pass-remarks=. \ |
Francis Visoiu Mistrih | 0e237d3 | 2018-10-30 12:20:17 +0000 | [diff] [blame] | 29 | ; RUN: -verify-machineinstrs=0 \ |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 30 | ; 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 Johnson | 5e1c0e7 | 2018-09-18 13:42:24 +0000 | [diff] [blame] | 35 | ; RUN: -r=%t.o,empty,p \ |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 36 | ; 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 Johnson | 0be9960 | 2019-01-17 15:49:04 +0000 | [diff] [blame] | 42 | ; 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 Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 44 | |
Teresa Johnson | b0a1d3b | 2018-08-14 03:00:16 +0000 | [diff] [blame] | 45 | ; REMARK: single-impl: devirtualized a call to _ZN1A1nEi |
| 46 | |
Teresa Johnson | 290a839 | 2019-01-11 18:31:57 +0000 | [diff] [blame] | 47 | ; 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 Johnson | 723636e | 2019-01-18 20:41:49 +0000 | [diff] [blame] | 52 | ; RUN: -verify-machineinstrs=0 -thinlto-threads=1 \ |
Teresa Johnson | 290a839 | 2019-01-11 18:31:57 +0000 | [diff] [blame] | 53 | ; 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 Johnson | 0be9960 | 2019-01-17 15:49:04 +0000 | [diff] [blame] | 65 | ; RUN: -r=%t.o,_ZTV1C,px 2>&1 | FileCheck %s --check-prefix=ERROR -dump-input=always |
Teresa Johnson | 290a839 | 2019-01-11 18:31:57 +0000 | [diff] [blame] | 66 | ; ERROR: LLVM ERROR: inconsistent LTO Unit splitting with llvm.type.test or llvm.type.checked.load |
| 67 | |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 68 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 69 | target 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 Johnson | 5e1c0e7 | 2018-09-18 13:42:24 +0000 | [diff] [blame] | 78 | ; Put declaration first to test handling of remarks when the first |
| 79 | ; function has no basic blocks. |
| 80 | declare void @empty() |
| 81 | |
Teresa Johnson | 28023db | 2018-07-19 14:51:32 +0000 | [diff] [blame] | 82 | ; CHECK-IR-LABEL: define i32 @test |
| 83 | define i32 @test(%struct.A* %obj, i32 %a) { |
| 84 | entry: |
| 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 | |
| 92 | trap: |
| 93 | tail call void @llvm.trap() |
| 94 | unreachable |
| 95 | |
| 96 | cont: |
| 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 | |
| 108 | cont2: |
| 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 | |
| 124 | declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) |
| 125 | declare void @llvm.trap() |
| 126 | |
| 127 | declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) |
| 128 | declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) |
| 129 | declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) |
| 130 | |
| 131 | !0 = !{i64 16, !"_ZTS1A"} |
| 132 | !1 = !{i64 16, !"_ZTS1B"} |
| 133 | !2 = !{i64 16, !"_ZTS1C"} |