xref: /llvm-project/llvm/test/CodeGen/RISCV/kcfi-patchable-function-prefix.ll (revision afd20587f9952654a9a9ec427052220b5e3a6982)
1; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,NOC
2; RUN: llc -mtriple=riscv64 -mattr=+c -verify-machineinstrs < %s | FileCheck %s --check-prefixes=CHECK,C
3
4;; The alignment is at least 4 to avoid unaligned type hash loads when this
5;; instrumented function is indirectly called.
6; CHECK-LABEL:    .globl f1
7; CHECK:          .p2align 2
8; CHECK-NOT:        nop
9; CHECK:          .word   12345678
10; CHECK-LABEL:    f1:
11define void @f1(ptr noundef %x) !kcfi_type !1 {
12; CHECK:            lw      t1, -4(a0)
13  call void %x() [ "kcfi"(i32 12345678) ]
14  ret void
15}
16
17; CHECK-LABEL:    .globl f2
18; NOC:            .p2align 2
19; C:              .p2align 1
20; CHECK-NOT:       .word
21; CHECK-NOT:        nop
22; CHECK-LABEL:    f2:
23define void @f2(ptr noundef %x) {
24; CHECK:            lw      t1, -4(a0)
25  call void %x() [ "kcfi"(i32 12345678) ]
26  ret void
27}
28
29; CHECK-LABEL:    .globl f3
30; CHECK:          .p2align 2
31; CHECK:          .word   12345678
32; CHECK-COUNT-11:   nop
33; CHECK-LABEL:    f3:
34define void @f3(ptr noundef %x) #0 !kcfi_type !1 {
35; NOC:              lw      t1, -48(a0)
36; C:                lw      t1, -26(a0)
37  call void %x() [ "kcfi"(i32 12345678) ]
38  ret void
39}
40
41; CHECK-LABEL:    .globl f4
42; NOC:            .p2align 2
43; C:              .p2align 1
44; CHECK-NOT:      .word
45; CHECK-COUNT-11:   nop
46; CHECK-LABEL:    f4:
47define void @f4(ptr noundef %x) #0 {
48; NOC:            lw      t1, -48(a0)
49; C:              lw      t1, -26(a0)
50  call void %x() [ "kcfi"(i32 12345678) ]
51  ret void
52}
53
54attributes #0 = { "patchable-function-prefix"="11" }
55
56!llvm.module.flags = !{!0}
57!0 = !{i32 4, !"kcfi", i32 1}
58!1 = !{i32 12345678}
59