1# RUN: llc -verify-machineinstrs -mtriple=aarch64-none-linux-gnu \
2# RUN:     -start-before aarch64-sls-hardening \
3# RUN:     -stop-after aarch64-sls-hardening -o - %s \
4# RUN:   | FileCheck %s --check-prefixes=CHECK
5
6# Check that the BLR SLS hardening transforms a BLR into a BL with operands as
7# expected.
8--- |
9  $__llvm_slsblr_thunk_x8 = comdat any
10  @a = dso_local local_unnamed_addr global i32 (...)* null, align 8
11  @b = dso_local local_unnamed_addr global i32 0, align 4
12
13  define dso_local void @fn1() local_unnamed_addr "target-features"="+harden-sls-blr" {
14  entry:
15    %0 = load i32 ()*, i32 ()** bitcast (i32 (...)** @a to i32 ()**), align 8
16    %call = tail call i32 %0() nounwind
17    store i32 %call, i32* @b, align 4
18    ret void
19  }
20
21  ; Function Attrs: naked nounwind
22  define linkonce_odr hidden void @__llvm_slsblr_thunk_x8() naked nounwind comdat {
23  entry:
24    ret void
25  }
26...
27---
28name:            fn1
29tracksRegLiveness: true
30body:             |
31  ; CHECK-LABEL: name: fn1
32  bb.0.entry:
33    liveins: $lr
34
35    early-clobber $sp = frame-setup STRXpre killed $lr, $sp, -16 ; :: (store 8 into %stack.0)
36    frame-setup CFI_INSTRUCTION def_cfa_offset 16
37    frame-setup CFI_INSTRUCTION offset $w30, -16
38    renamable $x8 = ADRP target-flags(aarch64-page) @a
39    renamable $x8 = LDRXui killed renamable $x8, target-flags(aarch64-pageoff, aarch64-nc) @a :: (dereferenceable load 8 from `i32 ()** bitcast (i32 (...)** @a to i32 ()**)`)
40    BLRNoIP killed renamable $x8, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def $w0
41  ; CHECK:  BL <mcsymbol __llvm_slsblr_thunk_x8>, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def $w0, implicit killed $x8
42    renamable $x8 = ADRP target-flags(aarch64-page) @b
43    STRWui killed renamable $w0, killed renamable $x8, target-flags(aarch64-pageoff, aarch64-nc) @b :: (store 4 into @b)
44    early-clobber $sp, $lr = frame-destroy LDRXpost $sp, 16 ; :: (load 8 from %stack.0)
45    RET undef $lr
46
47
48...
49---
50name:            __llvm_slsblr_thunk_x8
51tracksRegLiveness: true
52body:             |
53  bb.0.entry:
54    liveins: $x8
55
56    BR $x8
57    SpeculationBarrierISBDSBEndBB
58...
59