1; 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 8; RUN: llvm-lto2 run %t.o -save-temps \ 9; RUN: -o %t3 \ 10; RUN: -r=%t.o,test,px \ 11; RUN: -r=%t.o,_ZN1A1nEi,p \ 12; RUN: -r=%t.o,_ZN1B1fEi,p \ 13; RUN: -r=%t.o,_ZN1C1fEi,p \ 14; RUN: -r=%t.o,_ZTV1B, \ 15; RUN: -r=%t.o,_ZTV1C, \ 16; RUN: -r=%t.o,_ZN1A1nEi, \ 17; RUN: -r=%t.o,_ZN1B1fEi, \ 18; RUN: -r=%t.o,_ZN1C1fEi, \ 19; RUN: -r=%t.o,_ZTV1B,px \ 20; RUN: -r=%t.o,_ZTV1C,px 21; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 22 23; New PM 24; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm \ 25; RUN: -o %t3 \ 26; RUN: -r=%t.o,test,px \ 27; RUN: -r=%t.o,_ZN1A1nEi,p \ 28; RUN: -r=%t.o,_ZN1B1fEi,p \ 29; RUN: -r=%t.o,_ZN1C1fEi,p \ 30; RUN: -r=%t.o,_ZTV1B, \ 31; RUN: -r=%t.o,_ZTV1C, \ 32; RUN: -r=%t.o,_ZN1A1nEi, \ 33; RUN: -r=%t.o,_ZN1B1fEi, \ 34; RUN: -r=%t.o,_ZN1C1fEi, \ 35; RUN: -r=%t.o,_ZTV1B,px \ 36; RUN: -r=%t.o,_ZTV1C,px 37; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 38 39target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 40target triple = "x86_64-grtev4-linux-gnu" 41 42%struct.A = type { i32 (...)** } 43%struct.B = type { %struct.A } 44%struct.C = type { %struct.A } 45 46@_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 47@_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 48 49; CHECK-IR-LABEL: define i32 @test 50define i32 @test(%struct.A* %obj, i32 %a) { 51entry: 52 %0 = bitcast %struct.A* %obj to i8** 53 %vtable5 = load i8*, i8** %0 54 55 %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, metadata !"_ZTS1A") 56 %2 = extractvalue { i8*, i1 } %1, 1 57 br i1 %2, label %cont, label %trap 58 59trap: 60 tail call void @llvm.trap() 61 unreachable 62 63cont: 64 %3 = extractvalue { i8*, i1 } %1, 0 65 %4 = bitcast i8* %3 to i32 (%struct.A*, i32)* 66 67 ; Check that the call was devirtualized. 68 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi 69 %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a) 70 %vtable16 = load i8*, i8** %0 71 %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A") 72 %6 = extractvalue { i8*, i1 } %5, 1 73 br i1 %6, label %cont2, label %trap 74 75cont2: 76 %7 = extractvalue { i8*, i1 } %5, 0 77 %8 = bitcast i8* %7 to i32 (%struct.A*, i32)* 78 79 ; Check that traps are conditional. Invalid TYPE_ID can cause 80 ; unconditional traps. 81 ; CHECK-IR: br i1 {{.*}}, label %trap 82 83 ; We still have to call it as virtual. 84 ; CHECK-IR: %call3 = tail call i32 %8 85 %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call) 86 ret i32 %call3 87} 88; CHECK-IR-LABEL: ret i32 89; CHECK-IR-LABEL: } 90 91declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) 92declare void @llvm.trap() 93 94declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) 95declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) 96declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) 97 98!0 = !{i64 16, !"_ZTS1A"} 99!1 = !{i64 16, !"_ZTS1B"} 100!2 = !{i64 16, !"_ZTS1C"} 101