xref: /llvm-project/llvm/test/CodeGen/X86/nocf_check.ll (revision ad94b5c54f82e7bddc4253ccbf0bdaa9442411cf)
1; RUN: llc -mtriple=x86_64-unknown-unknown -x86-indirect-branch-tracking < %s | FileCheck %s
2
3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4;; This test verify the handling of ''nocf_check'' attribute by the backend. ;;
5;; The file was generated using the following C code:                        ;;
6;;                                                                           ;;
7;; void __attribute__((nocf_check)) NoCfCheckFunc(void) {}                   ;;
8;;                                                                           ;;
9;; typedef void(*FuncPointer)(void);                                         ;;
10;; void NoCfCheckCall(FuncPointer f) {                                       ;;
11;;   __attribute__((nocf_check)) FuncPointer p = f;                          ;;
12;;   (*p)();                                                                 ;;
13;;   NoCfCheckFunc();                                                        ;;
14;; }                                                                         ;;
15;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16
17; Make sure that a function with ''nocf_check'' attribute is not instrumented
18; with endbr instruction at the beginning.
19define void @NoCfCheckFunc() #0 {
20; CHECK-LABEL: NoCfCheckFunc
21; CHECK-NOT:   endbr64
22; CHECK:       retq
23entry:
24  ret void
25}
26
27; Ensure the notrack prefix is added before an indirect call using a pointer
28; with ''nocf_check'' attribute. Also ensure a direct call to a function with
29; the ''nocf_check'' attribute is correctly generated without notrack prefix.
30define void @NoCfCheckCall(ptr %f) #1 {
31; CHECK-LABEL: NoCfCheckCall
32; CHECK:       notrack call
33; CHECK:       callq NoCfCheckFunc
34entry:
35  %f.addr = alloca ptr, align 4
36  %p = alloca ptr, align 4
37  store ptr %f, ptr %f.addr, align 4
38  %0 = load ptr, ptr %f.addr, align 4
39  store ptr %0, ptr %p, align 4
40  %1 = load ptr, ptr %p, align 4
41  call void %1() #2
42	call void @NoCfCheckFunc() #2
43  ret void
44}
45
46attributes #0 = { nocf_check noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
47attributes #1 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
48attributes #2 = { nocf_check }
49
50!llvm.module.flags = !{!0}
51
52!0 = !{i32 8, !"cf-protection-branch", i32 1}
53