|
| 1 | +// REQUIRES: aarch64-registered-target |
| 2 | + |
| 3 | +// Test that features requiring FEAT_PAuth fail early if the requirement is not met: |
| 4 | +// Specifying the precise target triples here to prevent accidentally enabling unexpected |
| 5 | +// -fptrauth-* options as target defaults (would violate NO-UNEXPECTED check lines). |
| 6 | +// |
| 7 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pauthabi 2>&1 \ |
| 8 | +// RUN: | FileCheck %s --check-prefixes=FAIL-INTRINSICS,FAIL-CALLS,FAIL-RETURNS,NO-UNEXPECTED |
| 9 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-intrinsics 2>&1 \ |
| 10 | +// RUN: | FileCheck %s --check-prefixes=FAIL-INTRINSICS,NO-UNEXPECTED |
| 11 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-calls 2>&1 \ |
| 12 | +// RUN: | FileCheck %s --check-prefixes=FAIL-CALLS,NO-UNEXPECTED |
| 13 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-returns 2>&1 \ |
| 14 | +// RUN: | FileCheck %s --check-prefixes=FAIL-RETURNS,NO-UNEXPECTED |
| 15 | +// RUN: not %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-objc-isa 2>&1 \ |
| 16 | +// RUN: | FileCheck %s --check-prefixes=FAIL-OBJC-ISA,NO-UNEXPECTED |
| 17 | +// |
| 18 | +// Test that no errors and warnings are generated if FEAT_PAUTH is supported: |
| 19 | +// RUN: %clang %s -S -o - -target aarch64 -mcpu=apple-a12 -mbranch-protection=pauthabi 2>&1 \ |
| 20 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 21 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv8.3-a -mbranch-protection=pauthabi 2>&1 \ |
| 22 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 23 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv9-a -mbranch-protection=pauthabi 2>&1 \ |
| 24 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 25 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv8.2-a+pauth -mbranch-protection=pauthabi 2>&1 \ |
| 26 | +// RUN: | FileCheck %s --check-prefix=PAUTH --implicit-check-not=error --implicit-check-not=warning |
| 27 | +// |
| 28 | +// Test a few combinations of options that should not generate warnings: |
| 29 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv8.3-a -fptrauth-returns 2>&1 \ |
| 30 | +// RUN: | FileCheck %s --check-prefix=NO-UNEXPECTED |
| 31 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv8.3-a -fptrauth-objc-isa 2>&1 \ |
| 32 | +// RUN: | FileCheck %s --check-prefix=NO-UNEXPECTED |
| 33 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv8.3-a -fptrauth-init-fini -fptrauth-calls 2>&1 \ |
| 34 | +// RUN: | FileCheck %s --check-prefix=NO-UNEXPECTED |
| 35 | +// RUN: %clang %s -S -o - -target aarch64 -march=armv8.3-a -fptrauth-init-fini -mbranch-protection=pauthabi 2>&1 \ |
| 36 | +// RUN: | FileCheck %s --check-prefix=NO-UNEXPECTED |
| 37 | + |
| 38 | +// Test that the following options are still gated on -fptrauth-calls. |
| 39 | +// If they are not, in assertion builds they would usually fail at asm printing time. |
| 40 | +// These tests rely on -fptrauth-calls not being implicitly enabled, so |
| 41 | +// specifying the precise target triple. |
| 42 | +// |
| 43 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-init-fini 2>&1 \ |
| 44 | +// RUN: | FileCheck %s --check-prefixes=NO-PTRAUTH-CALLS,NO-UNEXPECTED -DOPTION=-fptrauth-init-fini |
| 45 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-function-pointer-type-discrimination 2>&1 \ |
| 46 | +// RUN: | FileCheck %s --check-prefixes=NO-PTRAUTH-CALLS,NO-UNEXPECTED -DOPTION=-fptrauth-function-pointer-type-discrimination |
| 47 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-address-discrimination 2>&1 \ |
| 48 | +// RUN: | FileCheck %s --check-prefixes=NO-PTRAUTH-CALLS,NO-UNEXPECTED -DOPTION=-fptrauth-vtable-pointer-address-discrimination |
| 49 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-vtable-pointer-type-discrimination 2>&1 \ |
| 50 | +// RUN: | FileCheck %s --check-prefixes=NO-PTRAUTH-CALLS,NO-UNEXPECTED -DOPTION=-fptrauth-vtable-pointer-type-discrimination |
| 51 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -fptrauth-block-descriptor-pointers -fblocks -DBLOCKS 2>&1 \ |
| 52 | +// RUN: | FileCheck %s --check-prefixes=NO-PTRAUTH-CALLS,NO-UNEXPECTED -DOPTION=-fptrauth-block-descriptor-pointers |
| 53 | + |
| 54 | +// Test that v8.2-compatible code is generated, if possible: |
| 55 | +// |
| 56 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -msign-return-address=all 2>&1 \ |
| 57 | +// RUN: | FileCheck %s --check-prefix=COMPAT |
| 58 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pac-ret 2>&1 \ |
| 59 | +// RUN: | FileCheck %s --check-prefix=COMPAT |
| 60 | +// RUN: %clang %s -S -o - -target aarch64-linux-gnu -mcpu=cortex-a72 -mbranch-protection=pac-ret+b-key 2>&1 \ |
| 61 | +// RUN: | FileCheck %s --check-prefix=COMPAT |
| 62 | + |
| 63 | +// arm64e has ptrauth enabled and assumes modern enough CPU by default: |
| 64 | +// |
| 65 | +// RUN: %clang %s -S -o - -target arm64e-apple-ios 2>&1 \ |
| 66 | +// RUN: | FileCheck %s --check-prefix=PAUTH |
| 67 | +// RUN: not %clang %s -S -o - -target arm64e-apple-ios -mcpu=cortex-a72 2>&1 \ |
| 68 | +// RUN: | FileCheck %s --check-prefixes=FAIL-INTRINSICS,FAIL-CALLS,FAIL-RETURNS,FAIL-OBJC-ISA,NO-UNEXPECTED |
| 69 | + |
| 70 | +volatile int counter; |
| 71 | + |
| 72 | +void ext(void); |
| 73 | + |
| 74 | +// Basically check the code generated for `caller`, other functions and classes |
| 75 | +// are provided just to check that assertion-enabled builds do not crash when |
| 76 | +// generating code for constructors, vtable, etc. |
| 77 | + |
| 78 | +extern "C" int caller(void) { |
| 79 | + ext(); |
| 80 | + return 0; |
| 81 | +} |
| 82 | + |
| 83 | +#ifdef BLOCKS |
| 84 | +int g(int (^bptr)(int)) { |
| 85 | + return bptr(42); |
| 86 | +} |
| 87 | +#endif |
| 88 | + |
| 89 | +class Base { |
| 90 | +public: |
| 91 | + virtual void f() {} |
| 92 | + virtual ~Base() {} |
| 93 | +}; |
| 94 | + |
| 95 | +class Derived : public Base { |
| 96 | + void f() override { |
| 97 | + counter += 1; |
| 98 | + } |
| 99 | +}; |
| 100 | + |
| 101 | +__attribute__((constructor)) void constr(void) { |
| 102 | + counter = 42; |
| 103 | +} |
| 104 | + |
| 105 | +__attribute__((destructor)) void destr(void) { |
| 106 | + counter = 0; |
| 107 | +} |
| 108 | + |
| 109 | +// Make Base and Derived usable from outside of this compilation unit |
| 110 | +// to prevent superfluous optimization. |
| 111 | +extern "C" void call_virtual(Base *B) { |
| 112 | + B->f(); |
| 113 | +} |
| 114 | +extern "C" void *create(bool f) { |
| 115 | + if (f) |
| 116 | + return new Base(); |
| 117 | + else |
| 118 | + return new Derived(); |
| 119 | +} |
| 120 | + |
| 121 | +// NO-PTRAUTH-CALLS: warning: [[OPTION]] is ignored because neither -fptrauth-calls nor -mbranch-protection=pauthabi is specified |
| 122 | +// FAIL-INTRINSICS: error: -fptrauth-intrinsics or -mbranch-protection=pauthabi is passed that require either enabling PAuth CPU feature or passing -fptrauth-soft option |
| 123 | +// FAIL-CALLS: error: -fptrauth-calls or -mbranch-protection=pauthabi is passed that require either enabling PAuth CPU feature or passing -fptrauth-soft option |
| 124 | +// FAIL-RETURNS: error: -fptrauth-returns or -mbranch-protection=pauthabi is passed that require either enabling PAuth CPU feature or passing -fptrauth-soft option |
| 125 | +// FAIL-OBJC-ISA: error: -fptrauth-objc-isa=... or -mbranch-protection=pauthabi is passed that require either enabling PAuth CPU feature or passing -fptrauth-soft option |
| 126 | +// NO-UNEXPECTED-NOT: error: |
| 127 | +// NO-UNEXPECTED-NOT: warning: |
| 128 | + |
| 129 | +// COMPAT: caller: |
| 130 | +// COMPAT: hint {{#25|#27}} |
| 131 | +// |
| 132 | +// COMPAT: hint {{#29|#31}} |
| 133 | +// COMPAT: ret |
| 134 | +// COMPAT: -- End function |
| 135 | + |
| 136 | +// PAUTH: caller: |
| 137 | +// PAUTH: paci{{[ab]}}sp |
| 138 | +// |
| 139 | +// PAUTH: reta{{[ab]}} |
| 140 | +// PAUTH: -- End function |
| 141 | + |
| 142 | +// Just check that some assembler output is printed and -fptrauth-init-fini |
| 143 | +// is disabled. |
| 144 | +// |
| 145 | +// NO-PTRAUTH-CALLS-NOT: @AUTH |
| 146 | +// |
| 147 | +// NO-PTRAUTH-CALLS: caller: |
| 148 | +// |
| 149 | +// NO-PTRAUTH-CALLS-NOT: @AUTH |
0 commit comments