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 -thinlto-split-lto-unit -o %t.o %s 8 9; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436. 10; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \ 11; RUN: -verify-machineinstrs=0 \ 12; RUN: -o %t2.index \ 13; RUN: -r=%t.o,test,px \ 14; RUN: -r=%t.o,_ZN1A1nEi,p \ 15; RUN: -r=%t.o,_ZN1B1fEi,p \ 16; RUN: -r=%t.o,_ZN1C1fEi,p \ 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 \ 23; RUN: -r=%t.o,_ZTV1C,px 24 25; Ensure that typeids are in the index. 26; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s 27; CHECK-LABEL: <GLOBALVAL_SUMMARY_BLOCK 28; CHECK: <TYPE_ID op0=0 op1=6 op2=4 op3=7 op4=0 op5=0 op6=0 op7=0 op8=0 op9=2 op10=6 op11=0 op12=0 op13=8 op14=1 op15=6 op16=9 op17=0/> 29; CHECK-LABEL: </GLOBALVAL_SUMMARY_BLOCK 30; CHECK-LABEL: <STRTAB_BLOCK 31; CHECK: blob data = '_ZTS1A_ZN1A1nEi' 32; CHECK-LABEL: </STRTAB_BLOCK 33 34; RUN: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=CHECK-DIS 35; Round trip it through llvm-as 36; RUN: llvm-dis %t.o.thinlto.bc -o - | llvm-as -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-DIS 37; CHECK-DIS: ^0 = module: (path: "{{.*}}thinlto-distributed-cfi-devirt.ll.tmp.o", hash: ({{.*}}, {{.*}}, {{.*}}, {{.*}}, {{.*}})) 38; CHECK-DIS: ^1 = gv: (guid: 8346051122425466633, summaries: (function: (module: ^0, flags: (linkage: external, notEligibleToImport: 0, live: 1, dsoLocal: 0), insts: 18, typeIdInfo: (typeTests: (^2), typeCheckedLoadVCalls: (vFuncId: (^2, offset: 8), vFuncId: (^2, offset: 0)))))) 39; CHECK-DIS: ^2 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: allOnes, sizeM1BitWidth: 7), wpdResolutions: ((offset: 0, wpdRes: (kind: branchFunnel)), (offset: 8, wpdRes: (kind: singleImpl, singleImplName: "_ZN1A1nEi"))))) ; guid = 7004155349499253778 40 41; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ 42; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ 43; RUN: -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR 44 45; Check that backend does not fail generating native code. 46; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ 47; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ 48; RUN: -o %t.native.o -x ir %t.o 49 50target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 51target triple = "x86_64-grtev4-linux-gnu" 52 53%struct.A = type { i32 (...)** } 54%struct.B = type { %struct.A } 55%struct.C = type { %struct.A } 56 57@_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 58@_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 59 60; CHECK-IR-LABEL: define i32 @test 61define i32 @test(%struct.A* %obj, i32 %a) { 62entry: 63 %0 = bitcast %struct.A* %obj to i8** 64 %vtable5 = load i8*, i8** %0 65 66 %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A") 67 %2 = extractvalue { i8*, i1 } %1, 1 68 br i1 %2, label %cont, label %trap 69 70trap: 71 tail call void @llvm.trap() 72 unreachable 73 74cont: 75 %3 = extractvalue { i8*, i1 } %1, 0 76 %4 = bitcast i8* %3 to i32 (%struct.A*, i32)* 77 78 ; Check that the call was devirtualized. 79 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi 80 %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a) 81 %vtable16 = load i8*, i8** %0 82 %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A") 83 %6 = extractvalue { i8*, i1 } %5, 1 84 br i1 %6, label %cont2, label %trap 85 86cont2: 87 %7 = extractvalue { i8*, i1 } %5, 0 88 %8 = bitcast i8* %7 to i32 (%struct.A*, i32)* 89 90 ; Check that traps are conditional. Invalid TYPE_ID can cause 91 ; unconditional traps. 92 ; CHECK-IR: br i1 {{.*}}, label %trap 93 94 ; We still have to call it as virtual. 95 ; CHECK-IR: %call3 = tail call i32 %8 96 %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call) 97 ret i32 %call3 98} 99; CHECK-IR-LABEL: ret i32 100; CHECK-IR-LABEL: } 101 102declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) 103declare void @llvm.trap() 104 105declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) 106declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) 107declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) 108 109!0 = !{i64 16, !"_ZTS1A"} 110!1 = !{i64 16, !"_ZTS1B"} 111!2 = !{i64 16, !"_ZTS1C"} 112