1 // Check the -mbranch-protection=option
3 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=pac-ret 2>&1 | \
4 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-OFF
6 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=pac-ret+leaf 2>&1 | \
7 // RUN: FileCheck %s --check-prefix=RA-ALL --check-prefix=KEY-A --check-prefix=BTE-OFF
9 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=pac-ret+leaf+b-key 2>&1 | \
10 // RUN: FileCheck %s --check-prefix=RA-ALL --check-prefix=KEY-B --check-prefix=BTE-OFF
12 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=pac-ret+b-key 2>&1 | \
13 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-B --check-prefix=BTE-OFF
15 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bti 2>&1 | \
16 // RUN: FileCheck %s --check-prefix=RA-OFF --check-prefix=BTE-ON
18 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bti+pac-ret 2>&1 | \
19 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-ON
21 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bti+pac-ret+leaf 2>&1 | \
22 // RUN: FileCheck %s --check-prefix=RA-ALL --check-prefix=KEY-A --check-prefix=BTE-ON
24 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bti 2>&1 | \
25 // RUN: FileCheck %s --check-prefix=RA-OFF --check-prefix=BTE-ON
27 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bti+pac-ret+b-key 2>&1 | \
28 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-B --check-prefix=BTE-ON
30 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bti+pac-ret+leaf+b-key 2>&1 | \
31 // RUN: FileCheck %s --check-prefix=RA-ALL --check-prefix=KEY-B --check-prefix=BTE-ON
33 // -mbranch-protection with standard
34 // RUN: %clang -target arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=standard 2>&1 | \
35 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-ON
37 // RUN: not %clang --target=arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=bar 2>&1 | \
38 // RUN: FileCheck %s --check-prefix=BAD-BP-PROTECTION
40 // RUN: not %clang --target=arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=pac-ret+bti+b-key 2>&1 | \
41 // RUN: FileCheck %s --check-prefix=BAD-B-KEY-COMBINATION
43 // RUN: not %clang --target=arm-arm-none-eabi -march=armv8.1-m.main -c %s -### -mbranch-protection=pac-ret+bti+leaf 2>&1 | \
44 // RUN: FileCheck %s --check-prefix=BAD-LEAF-COMBINATION
46 // -mbranch-protection with supported architectures other than v8.1-m.main
47 // RUN: %clang -target arm-arm-none-eabi -march=armv8-m.main -c %s -### -mbranch-protection=pac-ret 2>&1 | \
48 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-OFF
50 // RUN: %clang -target arm-arm-none-eabi -march=armv7-m -c %s -### -mbranch-protection=pac-ret 2>&1 | \
51 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-OFF
53 // RUN: %clang -target arm-arm-none-eabi -march=armv7e-m -c %s -### -mbranch-protection=pac-ret 2>&1 | \
54 // RUN: FileCheck %s --check-prefix=RA-NON-LEAF --check-prefix=KEY-A --check-prefix=BTE-OFF
56 // -mbranch-protection with unsupported architectures
57 // RUN: %clang -target arm-arm-none-eabi -march=armv6-m -c %s -### -mbranch-protection=bti 2>&1 | \
58 // RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
60 // RUN: %clang -target arm-arm-none-eabi -march=armv8-m.base -c %s -### -mbranch-protection=bti 2>&1 | \
61 // RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
63 // RUN: %clang -target arm-arm-none-eabi -march=armv8-a -c %s -### -mbranch-protection=bti 2>&1 | \
64 // RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
66 // RUN: %clang -target arm-arm-none-eabi -march=armv8-r -c %s -### -mbranch-protection=bti 2>&1 | \
67 // RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
69 // RUN: %clang -target arm-arm-none-eabi -march=armv7-a -c %s -### -mbranch-protection=bti 2>&1 | \
70 // RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
72 /// RUN: %clang -target arm-arm-none-eabi -march=armv7-a -mthumb -c %s -### -mbranch-protection=bti 2>&1 | \
73 /// RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
75 // RUN: %clang -target arm-arm-none-eabi -march=armv7-r -c %s -### -mbranch-protection=bti 2>&1 | \
76 // RUN: FileCheck %s --check-prefix=INCOMPATIBLE-ARCH
78 // RA-OFF: "-msign-return-address=none"
79 // RA-NON-LEAF: "-msign-return-address=non-leaf"
80 // RA-ALL: "-msign-return-address=all"
82 // KEY-A: "-msign-return-address-key=a_key"
83 // KEY-B: "-msign-return-address-key=b_key"
85 // BTE-OFF-NOT: "-mbranch-target-enforce"
86 // BTE-ON: "-mbranch-target-enforce"
88 // BAD-BP-PROTECTION: unsupported argument 'bar' to option '-mbranch-protection='
90 // BAD-B-KEY-COMBINATION: unsupported argument 'b-key' to option '-mbranch-protection='
91 // BAD-LEAF-COMBINATION: unsupported argument 'leaf' to option '-mbranch-protection='
93 // INCOMPATIBLE-ARCH: '-mbranch-protection=' option is incompatible with the '{{.*}}' architecture