Vitaly Buka | 44396fa | 2018-02-14 22:41:15 +0000 | [diff] [blame] | 1 | ; REQUIRES: x86-registered-target |
| 2 | |
| 3 | ; Backend test for distribute ThinLTO with CFI. |
| 4 | ; It additionally enables -fwhole-program-vtables to get more information in |
| 5 | ; TYPE_IDs of GLOBALVAL_SUMMARY_BLOCK. |
| 6 | |
| 7 | ; RUN: opt -thinlto-bc -o %t.o %s |
| 8 | |
| 9 | ; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \ |
| 10 | ; RUN: -o %t2.index \ |
| 11 | ; RUN: -r=%t.o,test,px \ |
| 12 | ; RUN: -r=%t.o,_ZN1A1nEi,p \ |
| 13 | ; RUN: -r=%t.o,_ZN1B1fEi,p \ |
| 14 | ; RUN: -r=%t.o,_ZN1C1fEi,p \ |
| 15 | ; 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 \ |
| 21 | ; RUN: -r=%t.o,_ZTV1C,px |
| 22 | |
| 23 | ; Ensure that typeids are in the index. |
| 24 | ; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s |
| 25 | ; CHECK-LABEL: <GLOBALVAL_SUMMARY_BLOCK |
| 26 | ; CHECK: <TYPE_ID op0=0 op1=6 op2=4 op3=7 op4=0 op5=0 op6=0 op7=0 op8=0 op9=0 op10=6 op11=0 op12=0 op13=8 op14=1 op15=6 op16=9 op17=0/> |
| 27 | ; CHECK-LABEL: </GLOBALVAL_SUMMARY_BLOCK |
| 28 | ; CHECK-LABEL: <STRTAB_BLOCK |
| 29 | ; CHECK: blob data = '_ZTS1A_ZN1A1nEi' |
| 30 | ; CHECK-LABEL: </STRTAB_BLOCK |
| 31 | |
| 32 | ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ |
| 33 | ; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ |
| 34 | ; RUN: -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR |
| 35 | |
| 36 | ; Check that backend does not fail generating native code. |
| 37 | ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ |
| 38 | ; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ |
| 39 | ; RUN: -o %t.native.o -x ir %t.o |
| 40 | |
| 41 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" |
| 42 | target triple = "x86_64-grtev4-linux-gnu" |
| 43 | |
| 44 | %struct.A = type { i32 (...)** } |
| 45 | %struct.B = type { %struct.A } |
| 46 | %struct.C = type { %struct.A } |
| 47 | |
| 48 | @_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 |
| 49 | @_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 |
| 50 | |
| 51 | ; CHECK-IR-LABEL: define i32 @test |
| 52 | define i32 @test(%struct.A* %obj, i32 %a) { |
| 53 | entry: |
| 54 | %0 = bitcast %struct.A* %obj to i8** |
| 55 | %vtable5 = load i8*, i8** %0 |
| 56 | |
Vitaly Buka | 44396fa | 2018-02-14 22:41:15 +0000 | [diff] [blame] | 57 | %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A") |
| 58 | %2 = extractvalue { i8*, i1 } %1, 1 |
| 59 | br i1 %2, label %cont, label %trap |
| 60 | |
| 61 | trap: |
| 62 | tail call void @llvm.trap() |
| 63 | unreachable |
| 64 | |
| 65 | cont: |
| 66 | %3 = extractvalue { i8*, i1 } %1, 0 |
| 67 | %4 = bitcast i8* %3 to i32 (%struct.A*, i32)* |
Vitaly Buka | 0465e2a | 2018-02-14 22:52:49 +0000 | [diff] [blame^] | 68 | |
| 69 | ; Check that the call was devirtualized. |
| 70 | ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi |
Vitaly Buka | 44396fa | 2018-02-14 22:41:15 +0000 | [diff] [blame] | 71 | %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a) |
| 72 | %vtable16 = load i8*, i8** %0 |
| 73 | %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A") |
| 74 | %6 = extractvalue { i8*, i1 } %5, 1 |
| 75 | br i1 %6, label %cont2, label %trap |
| 76 | |
| 77 | cont2: |
| 78 | %7 = extractvalue { i8*, i1 } %5, 0 |
| 79 | %8 = bitcast i8* %7 to i32 (%struct.A*, i32)* |
| 80 | |
| 81 | ; Check that traps are conditional. Invalid TYPE_ID can cause |
| 82 | ; unconditional traps. |
| 83 | ; CHECK-IR: br i1 {{.*}}, label %trap |
| 84 | |
| 85 | ; We still have to call it as virtual. |
| 86 | ; CHECK-IR: %call3 = tail call i32 %8 |
| 87 | %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call) |
| 88 | ret i32 %call3 |
| 89 | } |
| 90 | ; CHECK-IR-LABEL: ret i32 |
| 91 | ; CHECK-IR-LABEL: } |
| 92 | |
| 93 | declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) |
| 94 | declare void @llvm.trap() |
| 95 | |
| 96 | declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) |
| 97 | declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) |
| 98 | declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) |
| 99 | |
| 100 | !0 = !{i64 16, !"_ZTS1A"} |
| 101 | !1 = !{i64 16, !"_ZTS1B"} |
| 102 | !2 = !{i64 16, !"_ZTS1C"} |