[clang] [Clang] Re-write codegen for atomic_test_and_set and atomic_clear (PR #121943)
Oliver Stannard via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 15 02:57:52 PST 2025
================
@@ -284,11 +284,26 @@ void f(_Atomic(int) *i, const _Atomic(int) *ci,
const volatile int flag_k = 0;
volatile int flag = 0;
- (void)(int)__atomic_test_and_set(&flag_k, memory_order_seq_cst); // expected-warning {{passing 'const volatile int *' to parameter of type 'volatile void *'}}
+ (void)(int)__atomic_test_and_set(&flag_k, memory_order_seq_cst); // expected-error {{address argument to atomic operation must be a pointer to non-const type ('const volatile int *' invalid)}}
(void)(int)__atomic_test_and_set(&flag, memory_order_seq_cst);
- __atomic_clear(&flag_k, memory_order_seq_cst); // expected-warning {{passing 'const volatile int *' to parameter of type 'volatile void *'}}
+ __atomic_clear(&flag_k, memory_order_seq_cst); // expected-error {{address argument to atomic operation must be a pointer to non-const type ('const volatile int *' invalid)}}
__atomic_clear(&flag, memory_order_seq_cst);
(int)__atomic_clear(&flag, memory_order_seq_cst); // expected-error {{operand of type 'void'}}
+ __atomic_clear(0x8000, memory_order_seq_cst); // expected-error {{address argument to atomic builtin must be a pointer ('int' invalid)}}
+ __atomic_clear(&flag, memory_order_consume); // expected-warning {{memory order argument to atomic operation is invalid}}
+ __atomic_clear(&flag, memory_order_acquire); // expected-warning {{memory order argument to atomic operation is invalid}}
+ __atomic_clear(&flag, memory_order_acq_rel); // expected-warning {{memory order argument to atomic operation is invalid}}
+
+ // These intrinsics accept any non-const pointer type (including
+ // pointer-to-incomplete), and access the first byte.
+ __atomic_test_and_set((void*)0x8000, memory_order_seq_cst);
+ __atomic_test_and_set((char*)0x8000, memory_order_seq_cst);
+ __atomic_test_and_set((int*)0x8000, memory_order_seq_cst);
+ __atomic_test_and_set((struct incomplete*)0x8000, memory_order_seq_cst);
+ __atomic_clear((void*)0x8000, memory_order_seq_cst);
+ __atomic_clear((char*)0x8000, memory_order_seq_cst);
+ __atomic_clear((int*)0x8000, memory_order_seq_cst);
+ __atomic_clear((struct incomplete*)0x8000, memory_order_seq_cst);
----------------
ostannard wrote:
Done
https://github.com/llvm/llvm-project/pull/121943
More information about the cfe-commits
mailing list