| 1 |
// RUN: %clang_cc1 -triple arm64-apple-ios -fsyntax-only -verify -fptrauth-intrinsics %s |
| 2 |
// RUN: %clang_cc1 -triple aarch64-linux-gnu -fsyntax-only -verify -fptrauth-intrinsics %s |
| 3 |
|
| 4 |
#include <stdatomic.h> |
| 5 |
|
| 6 |
int i; |
| 7 |
int *__ptrauth(2, 1, 100) authenticated_ptr = &i; |
| 8 |
int *__ptrauth(2, 0, 200) non_addr_discriminatedauthenticated_ptr = &i; |
| 9 |
int * wat = &i; |
| 10 |
#define ATOMIZE(p) (__typeof__(p) volatile _Atomic *)(long)(&p) |
| 11 |
|
| 12 |
void f() { |
| 13 |
static int j = 1; |
| 14 |
__c11_atomic_init(ATOMIZE(authenticated_ptr), 5); |
| 15 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 16 |
__c11_atomic_store(ATOMIZE(authenticated_ptr), 0, memory_order_relaxed); |
| 17 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 18 |
__c11_atomic_load(ATOMIZE(authenticated_ptr), memory_order_seq_cst); |
| 19 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 20 |
__c11_atomic_store(ATOMIZE(authenticated_ptr), 1, memory_order_seq_cst); |
| 21 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 22 |
__atomic_store_n(ATOMIZE(authenticated_ptr), 4, memory_order_release); |
| 23 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 24 |
__atomic_store(ATOMIZE(authenticated_ptr), j, memory_order_release); |
| 25 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 26 |
__c11_atomic_exchange(ATOMIZE(authenticated_ptr), 1, memory_order_seq_cst); |
| 27 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 28 |
__atomic_exchange(ATOMIZE(authenticated_ptr), &j, &j, memory_order_seq_cst); |
| 29 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 30 |
__c11_atomic_fetch_add(ATOMIZE(authenticated_ptr), 1, memory_order_seq_cst); |
| 31 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 32 |
__atomic_fetch_add(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 33 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 34 |
__atomic_fetch_sub(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 35 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 36 |
__atomic_fetch_min(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 37 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 38 |
__atomic_fetch_max(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 39 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 40 |
__c11_atomic_fetch_and(ATOMIZE(authenticated_ptr), 1, memory_order_seq_cst); |
| 41 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 42 |
__atomic_fetch_and(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 43 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 44 |
__atomic_fetch_or(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 45 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 46 |
__atomic_fetch_xor(ATOMIZE(authenticated_ptr), 3, memory_order_seq_cst); |
| 47 |
// expected-error@-1 {{address argument to atomic operation must be a pointer to a non address discriminated type ('volatile __ptrauth(2,1,100) _Atomic(int *) *' invalid)}} |
| 48 |
|
| 49 |
__c11_atomic_init(ATOMIZE(non_addr_discriminatedauthenticated_ptr), &j); |
| 50 |
__c11_atomic_store(ATOMIZE(non_addr_discriminatedauthenticated_ptr), 0, memory_order_relaxed); |
| 51 |
__c11_atomic_load(ATOMIZE(non_addr_discriminatedauthenticated_ptr), memory_order_seq_cst); |
| 52 |
__atomic_store(&j, ATOMIZE(non_addr_discriminatedauthenticated_ptr), memory_order_release); |
| 53 |
// expected-error@-1 {{incompatible pointer types passing 'volatile __ptrauth(2,0,200) _Atomic(int *) *' to parameter of type 'int *'}} |
| 54 |
__c11_atomic_exchange(ATOMIZE(j), ATOMIZE(non_addr_discriminatedauthenticated_ptr), memory_order_seq_cst); |
| 55 |
// expected-error@-1 {{incompatible pointer to integer conversion passing 'volatile __ptrauth(2,0,200) _Atomic(int *) *' to parameter of type 'typeof (j)' (aka 'int')}} |
| 56 |
__c11_atomic_fetch_add(ATOMIZE(non_addr_discriminatedauthenticated_ptr), ATOMIZE(j), memory_order_seq_cst); |
| 57 |
// expected-error@-1 {{incompatible pointer to integer conversion passing 'volatile _Atomic(typeof (j)) *' to parameter of type '__ptrdiff_t'}} |
| 58 |
__c11_atomic_fetch_and(ATOMIZE(j), ATOMIZE(non_addr_discriminatedauthenticated_ptr), memory_order_seq_cst); |
| 59 |
// expected-error@-1 {{incompatible pointer to integer conversion passing 'volatile __ptrauth(2,0,200) _Atomic(int *) *' to parameter of type 'typeof (j)' (aka 'int')}} |
| 60 |
|
| 61 |
|
| 62 |
__sync_fetch_and_add(&authenticated_ptr, 1); |
| 63 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 64 |
__sync_fetch_and_sub(&authenticated_ptr, 1); |
| 65 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 66 |
__sync_fetch_and_or(&authenticated_ptr, 1); |
| 67 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 68 |
__sync_fetch_and_and(&authenticated_ptr, 1); |
| 69 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 70 |
__sync_fetch_and_xor(&authenticated_ptr, 1); |
| 71 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 72 |
__sync_fetch_and_nand(&authenticated_ptr, 1); |
| 73 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 74 |
|
| 75 |
__sync_add_and_fetch(&authenticated_ptr, 1); |
| 76 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 77 |
__sync_sub_and_fetch(&authenticated_ptr, 1); |
| 78 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 79 |
__sync_or_and_fetch(&authenticated_ptr, 1); |
| 80 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 81 |
__sync_and_and_fetch(&authenticated_ptr, 1); |
| 82 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 83 |
__sync_xor_and_fetch(&authenticated_ptr, 1); |
| 84 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 85 |
__sync_nand_and_fetch(&authenticated_ptr, 1); |
| 86 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 87 |
|
| 88 |
__sync_bool_compare_and_swap(&authenticated_ptr, 1, 0); |
| 89 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 90 |
__sync_val_compare_and_swap(&authenticated_ptr, 1, 1); |
| 91 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 92 |
|
| 93 |
__sync_lock_test_and_set(&authenticated_ptr, 1); |
| 94 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 95 |
__sync_lock_release(&authenticated_ptr); |
| 96 |
// expected-error@-1 {{address argument to __sync operation must be a pointer to a non address discriminated type ('int *__ptrauth(2,1,100)' invalid)}} |
| 97 |
|
| 98 |
|
| 99 |
int i = 0; |
| 100 |
|
| 101 |
__sync_fetch_and_add(&non_addr_discriminatedauthenticated_ptr, &i); |
| 102 |
__sync_fetch_and_sub(&non_addr_discriminatedauthenticated_ptr, &i); |
| 103 |
__sync_fetch_and_or(&non_addr_discriminatedauthenticated_ptr, &i); |
| 104 |
__sync_fetch_and_and(&non_addr_discriminatedauthenticated_ptr, &i); |
| 105 |
__sync_fetch_and_xor(&non_addr_discriminatedauthenticated_ptr, &i); |
| 106 |
|
| 107 |
__sync_add_and_fetch(&non_addr_discriminatedauthenticated_ptr, &i); |
| 108 |
__sync_sub_and_fetch(&non_addr_discriminatedauthenticated_ptr, &i); |
| 109 |
__sync_or_and_fetch(&non_addr_discriminatedauthenticated_ptr, &i); |
| 110 |
__sync_and_and_fetch(&non_addr_discriminatedauthenticated_ptr, &i); |
| 111 |
__sync_xor_and_fetch(&non_addr_discriminatedauthenticated_ptr, &i); |
| 112 |
|
| 113 |
__sync_bool_compare_and_swap(&non_addr_discriminatedauthenticated_ptr, &i, &i); |
| 114 |
__sync_val_compare_and_swap(&non_addr_discriminatedauthenticated_ptr, &i, &i); |
| 115 |
|
| 116 |
__sync_lock_test_and_set(&non_addr_discriminatedauthenticated_ptr, &i); |
| 117 |
__sync_lock_release(&non_addr_discriminatedauthenticated_ptr); |
| 118 |
} |