164 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 62; RUN: llc -mtriple=thumbv7-linux-gnueabi -verify-machineinstrs < %s | FileCheck %s --check-prefix=ASM3; RUN: llc -mtriple=thumbv7-linux-gnueabi -verify-machineinstrs -stop-after=finalize-isel < %s | FileCheck %s --check-prefixes=MIR,ISEL4; RUN: llc -mtriple=thumbv7-linux-gnueabi -verify-machineinstrs -stop-after=kcfi < %s | FileCheck %s --check-prefixes=MIR,KCFI5 6; MIR checks for all functions (grouped here to prevent update_llc_test_checks.py from removing them)7 8; MIR-LABEL: name: f19; MIR: body:10 11; ISEL: tBLXr 14 /* CC::al */, $noreg, %0, csr_aapcs,{{.*}} cfi-type 1234567812 13; KCFI: BUNDLE{{.*}} {14; KCFI-NEXT: KCFI_CHECK_Thumb2 $r0, 1234567815; KCFI-NEXT: tBLXr 14 /* CC::al */, $noreg, {{(killed )?}}$r0, csr_aapcs,{{.*}}16; KCFI-NEXT: }17 18; MIR-LABEL: name: f219; MIR: body:20 21; ISEL: TCRETURNri %0, 0, csr_aapcs, implicit $sp, cfi-type 1234567822 23; KCFI: BUNDLE{{.*}} {24; KCFI-NEXT: KCFI_CHECK_Thumb2 $r0, 1234567825; KCFI-NEXT: tTAILJMPr {{(killed )?}}$r0, csr_aapcs, implicit $sp, implicit $sp26; KCFI-NEXT: }27 28; Test function without KCFI annotation29; ASM-LABEL: .globl nosan30; ASM-NEXT: .p2align 131; ASM-NEXT: .type nosan,%function32; ASM-NEXT: .code 1633; ASM-NEXT: .thumb_func34define dso_local void @nosan() nounwind {35; ASM-LABEL: nosan:36; ASM: @ %bb.0:37; ASM-NEXT: bx lr38 ret void39}40 41; Test function with KCFI annotation - verifies type hash emission42;; The alignment is at least 4 to avoid unaligned type hash loads when this43;; instrumented function is indirectly called.44; ASM-LABEL: .globl target_func45; ASM-NEXT: .p2align 246; ASM-NEXT: .type target_func,%function47; ASM-NEXT: .long 1234567848; ASM-NEXT: .code 1649; ASM-NEXT: .thumb_func50define void @target_func() !kcfi_type !1 {51; ASM-LABEL: target_func:52; ASM: @ %bb.0:53; ASM-NEXT: bx lr54 ret void55}56 57; Test indirect call with KCFI check58; ASM: .long 1234567859define void @f1(ptr noundef %x) !kcfi_type !1 {60; ASM-LABEL: f1:61; ASM: @ %bb.0:62; ASM-NEXT: .save {r7, lr}63; ASM-NEXT: push {r7, lr}64; ASM-NEXT: bic r12, r0, #165; ASM-NEXT: ldr r12, [r12, #-4]66; ASM-NEXT: eor r12, r12, #7867; ASM-NEXT: eor r12, r12, #2483268; ASM-NEXT: eor r12, r12, #1232076869; ASM-NEXT: eors r12, r12, #070; ASM-NEXT: beq.w .Ltmp071; ASM-NEXT: udf #12872; ASM-NEXT: .Ltmp0:73; ASM-NEXT: blx r074; ASM-NEXT: pop {r7, pc}75 76 call void %x() [ "kcfi"(i32 12345678) ]77 ret void78}79 80; Test with tail call81define void @f2(ptr noundef %x) !kcfi_type !1 {82; ASM-LABEL: f2:83; ASM: @ %bb.0:84; ASM-NEXT: bic r12, r0, #185; ASM-NEXT: ldr r12, [r12, #-4]86; ASM-NEXT: eor r12, r12, #7887; ASM-NEXT: eor r12, r12, #2483288; ASM-NEXT: eor r12, r12, #1232076889; ASM-NEXT: eors r12, r12, #090; ASM-NEXT: beq.w .Ltmp191; ASM-NEXT: udf #12892; ASM-NEXT: .Ltmp1:93; ASM-NEXT: bx r094 95 tail call void %x() [ "kcfi"(i32 12345678) ]96 ret void97}98 99; Test r3 spill/reload when target is r12 and r3 is a call argument (Thumb2)100define void @f3_r3_spill(ptr noundef %target, i32 %a, i32 %b, i32 %c, i32 %d) !kcfi_type !1 {101; ASM-LABEL: f3_r3_spill:102; ASM: @ %bb.0:103; ASM-NEXT: .save {r7, lr}104; ASM-NEXT: push {r7, lr}105; ASM-NEXT: mov lr, r3106; ASM-NEXT: ldr r3, [sp, #8]107; ASM-NEXT: mov r12, r0108; ASM-NEXT: mov r0, r1109; ASM-NEXT: mov r1, r2110; ASM-NEXT: mov r2, lr111; ASM-NEXT: push {r3}112; ASM-NEXT: bic r3, r12, #1113; ASM-NEXT: ldr r3, [r3, #-4]114; ASM-NEXT: eor r3, r3, #78115; ASM-NEXT: eor r3, r3, #24832116; ASM-NEXT: eor r3, r3, #12320768117; ASM-NEXT: eors r3, r3, #0118; ASM-NEXT: pop {r3}119; ASM-NEXT: beq.w .Ltmp2120; ASM-NEXT: udf #140121; ASM-NEXT: .Ltmp2:122; ASM-NEXT: blx r12123; ASM-NEXT: pop {r7, pc}124; Arguments: r0=%target, r1=%a, r2=%b, r3=%c, [sp+8]=%d125; Call needs: r0=%a, r1=%b, r2=%c, r3=%d, target in r12126; r3 is live as 4th argument, so push it before KCFI check127 call void %target(i32 %a, i32 %b, i32 %c, i32 %d) [ "kcfi"(i32 12345678) ]128 ret void129}130 131; Test with 3 arguments - r3 not live, target in r12 or elsewhere, r12 used as scratch132define void @f4_r3_unused(ptr noundef %target, i32 %a, i32 %b) !kcfi_type !1 {133; ASM-LABEL: f4_r3_unused:134; ASM: @ %bb.0:135; ASM-NEXT: .save {r7, lr}136; ASM-NEXT: push {r7, lr}137; ASM-NEXT: mov r3, r0138; ASM-NEXT: mov r0, r1139; ASM-NEXT: mov r1, r2140; ASM-NEXT: bic r12, r3, #1141; ASM-NEXT: ldr r12, [r12, #-4]142; ASM-NEXT: eor r12, r12, #78143; ASM-NEXT: eor r12, r12, #24832144; ASM-NEXT: eor r12, r12, #12320768145; ASM-NEXT: eors r12, r12, #0146; ASM-NEXT: beq.w .Ltmp3147; ASM-NEXT: udf #131148; ASM-NEXT: .Ltmp3:149; ASM-NEXT: blx r3150; ASM-NEXT: pop {r7, pc}151; Only 3 arguments total, so r3 is not used as call argument152; Target might be in r3, using r12 as scratch (no spill needed)153 call void %target(i32 %a, i32 %b) [ "kcfi"(i32 12345678) ]154 ret void155}156 157!llvm.module.flags = !{!0}158!0 = !{i32 4, !"kcfi", i32 1}159!1 = !{i32 12345678}160;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:161; ISEL: {{.*}}162; KCFI: {{.*}}163; MIR: {{.*}}164