From aa37a5a0c4e5a74aebc029c6513f762da2208658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 27 Jan 2025 09:51:51 +0100 Subject: [PATCH] zig.h: Add some casts to __atomic macros to shut Clang warnings up. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a stupid Clang-ism: ❯ cat test.c int main() { int value = 42; int const *value_ptr = &value; int location; __atomic_store(&location, value_ptr, __ATOMIC_SEQ_CST); } ❯ gcc test.c -fsyntax-only ❯ clang test.c -fsyntax-only test.c:5:31: warning: passing 'const int *' to parameter of type 'int *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers] 5 | __atomic_store(&location, value_ptr, __ATOMIC_SEQ_CST); | ^~~~~~~~~ 1 warning generated. I have no idea why Clang doesn't define these builtins as taking const pointers for the parameters that are only read from. Anyway, after the next zig1.wasm update, this change should shut up these warnings that we've been seeing in CI during bootstrap for ages. --- lib/zig.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/zig.h b/lib/zig.h index e636785f1e..41b33af7c6 100644 --- a/lib/zig.h +++ b/lib/zig.h @@ -3765,9 +3765,9 @@ typedef int zig_memory_order; #define zig_memory_order_acq_rel __ATOMIC_ACQ_REL #define zig_memory_order_seq_cst __ATOMIC_SEQ_CST #define zig_atomic(Type) Type -#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), false, succ, fail) -#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, &(expected), &(desired), true, succ, fail) -#define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, &(arg), &(res), order) +#define zig_cmpxchg_strong( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), false, succ, fail) +#define zig_cmpxchg_weak( obj, expected, desired, succ, fail, Type, ReprType) __atomic_compare_exchange(obj, (ReprType *)&(expected), (ReprType *)&(desired), true, succ, fail) +#define zig_atomicrmw_xchg(res, obj, arg, order, Type, ReprType) __atomic_exchange(obj, (ReprType *)&(arg), &(res), order) #define zig_atomicrmw_add(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_add (obj, arg, order) #define zig_atomicrmw_sub(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_sub (obj, arg, order) #define zig_atomicrmw_or(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_or (obj, arg, order) @@ -3776,7 +3776,7 @@ typedef int zig_memory_order; #define zig_atomicrmw_nand(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_nand(obj, arg, order) #define zig_atomicrmw_min(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_min (obj, arg, order) #define zig_atomicrmw_max(res, obj, arg, order, Type, ReprType) res = __atomic_fetch_max (obj, arg, order) -#define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, &(arg), order) +#define zig_atomic_store( obj, arg, order, Type, ReprType) __atomic_store (obj, (ReprType *)&(arg), order) #define zig_atomic_load(res, obj, order, Type, ReprType) __atomic_load (obj, &(res), order) #undef zig_atomicrmw_xchg_float #define zig_atomicrmw_xchg_float zig_atomicrmw_xchg