171 lines · plain
1; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs < %s | FileCheck %s --check-prefix=ASM2; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=finalize-isel < %s | FileCheck %s --check-prefixes=MIR,ISEL3; RUN: llc -mtriple=x86_64-unknown-linux-gnu -verify-machineinstrs -stop-after=kcfi < %s | FileCheck %s --check-prefixes=MIR,KCFI4 5; ASM: .p2align 46; ASM: .type __cfi_f1,@function7; ASM-LABEL: __cfi_f1:8; ASM-NEXT: nop9; ASM-NEXT: nop10; ASM-NEXT: nop11; ASM-NEXT: nop12; ASM-NEXT: nop13; ASM-NEXT: nop14; ASM-NEXT: nop15; ASM-NEXT: nop16; ASM-NEXT: nop17; ASM-NEXT: nop18; ASM-NEXT: nop19; ASM-NEXT: movl $12345678, %eax20; ASM-LABEL: .Lcfi_func_end0:21; ASM-NEXT: .size __cfi_f1, .Lcfi_func_end0-__cfi_f122define void @f1(ptr noundef %x) !kcfi_type !1 {23; ASM-LABEL: f1:24; ASM: # %bb.0:25; ASM: movl $4282621618, %r10d # imm = 0xFF439EB226; ASM-NEXT: addl -4(%rdi), %r10d27; ASM-NEXT: je .Ltmp028; ASM-NEXT: .Ltmp1:29; ASM-NEXT: ud230; ASM-NEXT: .section .kcfi_traps,"ao",@progbits,.text31; ASM-NEXT: .Ltmp2:32; ASM-NEXT: .long .Ltmp1-.Ltmp233; ASM-NEXT: .text34; ASM-NEXT: .Ltmp0:35; ASM-NEXT: callq *%rdi36 37; MIR-LABEL: name: f138; MIR: body:39; ISEL: CALL64r %0, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, cfi-type 1234567840; KCFI: BUNDLE{{.*}} {41; KCFI-NEXT: KCFI_CHECK $rdi, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags42; KCFI-NEXT: CALL64r killed $rdi, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp43; KCFI-NEXT: }44 call void %x() [ "kcfi"(i32 12345678) ]45 ret void46}47 48; ASM-NOT: __cfi_f2:49define void @f2(ptr noundef %x) {50; ASM-LABEL: f2:51 52; MIR-LABEL: name: f253; MIR: body:54; ISEL: TCRETURNri64 %0, 0, csr_64, implicit $rsp, implicit $ssp, cfi-type 1234567855; KCFI: BUNDLE{{.*}} {56; KCFI-NEXT: KCFI_CHECK $rdi, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags57; KCFI-NEXT: TAILJMPr64 killed $rdi, csr_64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp58; KCFI-NEXT: }59 tail call void %x() [ "kcfi"(i32 12345678) ]60 ret void61}62 63; ASM-NOT: __cfi_f3:64define void @f3(ptr noundef %x) #0 {65; ASM-LABEL: f3:66; MIR-LABEL: name: f367; MIR: body:68; ISEL: CALL64pcrel32 &__llvm_retpoline_r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit killed $r11, cfi-type 1234567869; KCFI: BUNDLE{{.*}} {70; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags71; KCFI-NEXT: CALL64pcrel32 &__llvm_retpoline_r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, implicit internal killed $r1172; KCFI-NEXT: }73 call void %x() [ "kcfi"(i32 12345678) ]74 ret void75}76 77; ASM-NOT: __cfi_f4:78define void @f4(ptr noundef %x) #0 {79; ASM-LABEL: f4:80; MIR-LABEL: name: f481; MIR: body:82; ISEL: TCRETURNdi64 &__llvm_retpoline_r11, 0, csr_64, implicit $rsp, implicit $ssp, implicit killed $r11, cfi-type 1234567883; KCFI: BUNDLE{{.*}} {84; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags85; KCFI-NEXT: TAILJMPd64 &__llvm_retpoline_r11, csr_64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp, implicit internal killed $r1186; KCFI-NEXT: }87 tail call void %x() [ "kcfi"(i32 12345678) ]88 ret void89}90 91;; Ensure we emit Value + 1 for unwanted values (e.g. endbr64 == 4196274163).92; ASM-LABEL: __cfi_f5:93; ASM: movl $4196274164, %eax # imm = 0xFA1E0FF494define void @f5(ptr noundef %x) !kcfi_type !2 {95; ASM-LABEL: f5:96; ASM: movl $98693132, %r10d # imm = 0x5E1F00C97 tail call void %x() [ "kcfi"(i32 4196274163) ]98 ret void99}100 101;; Ensure we emit Value + 1 for unwanted values (e.g. -endbr64 == 98693133).102; ASM-LABEL: __cfi_f6:103; ASM: movl $98693134, %eax # imm = 0x5E1F00E104define void @f6(ptr noundef %x) !kcfi_type !3 {105; ASM-LABEL: f6:106; ASM: movl $4196274162, %r10d # imm = 0xFA1E0FF2107 tail call void %x() [ "kcfi"(i32 98693133) ]108 ret void109}110 111@g = external local_unnamed_addr global ptr, align 8112 113define void @f7() {114; MIR-LABEL: name: f7115; MIR: body:116; ISEL: TCRETURNmi64 killed %0, 1, $noreg, 0, $noreg, 0, csr_64, implicit $rsp, implicit $ssp, cfi-type 12345678117; KCFI: $r11 = MOV64rm killed renamable $rax, 1, $noreg, 0, $noreg118; KCFI-NEXT: BUNDLE{{.*}} {119; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags120; KCFI-NEXT: TAILJMPr64 internal $r11, csr_64, implicit $rsp, implicit $ssp, implicit $rsp, implicit $ssp121; KCFI-NEXT: }122 %1 = load ptr, ptr @g, align 8123 tail call void %1() [ "kcfi"(i32 12345678) ]124 ret void125}126 127define void @f8() {128; MIR-LABEL: name: f8129; MIR: body:130; ISEL: CALL64m killed %0, 1, $noreg, 0, $noreg, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, cfi-type 12345678131; KCFI: $r11 = MOV64rm killed renamable $rax, 1, $noreg, 0, $noreg132; KCFI-NEXT: BUNDLE{{.*}} {133; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags134; KCFI-NEXT: CALL64r internal $r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp135; KCFI-NEXT: }136 %1 = load ptr, ptr @g, align 8137 call void %1() [ "kcfi"(i32 12345678) ]138 ret void139}140 141declare i32 @__gxx_personality_v0(...)142 143define void @f9() personality ptr @__gxx_personality_v0 {144; MIR-LABEL: name: f9145; MIR: body:146; ISEL: CALL64m killed %0, 1, $noreg, 0, $noreg, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp, cfi-type 12345678147; KCFI: $r11 = MOV64rm killed renamable $rax, 1, $noreg, 0, $noreg148; KCFI-NEXT: BUNDLE{{.*}} {149; KCFI-NEXT: KCFI_CHECK $r11, 12345678, implicit-def $r10, implicit-def $r11, implicit-def $eflags150; KCFI-NEXT: CALL64r internal $r11, csr_64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp151; KCFI-NEXT: }152 %1 = load ptr, ptr @g, align 8153 invoke void %1() [ "kcfi"(i32 12345678) ]154 to label %cont155 unwind label %err156cont:157 ret void158err:159 %exn = landingpad { i8*, i32 }160 catch i8* null161 resume { i8*, i32 } %exn162}163 164attributes #0 = { "target-features"="+retpoline-indirect-branches,+retpoline-indirect-calls" }165 166!llvm.module.flags = !{!0}167!0 = !{i32 4, !"kcfi", i32 1}168!1 = !{i32 12345678}169!2 = !{i32 4196274163}170!3 = !{i32 98693133}171