https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64843
--- Comment #3 from joseph at codesourcery dot com <joseph at codesourcery dot com> --- The first question is whether this code is actually valid. C11 says "All of these operations are applicable to an object of any atomic integer type.", not mentioning pointer types as valid, but then refers to address types. Then, if it's valid to use pointer types here, something like the following (untested, and all four of the _add and _sub macros would need similar changes) should work without changing the built-in function semantics: /* EXPR1 if it has a pointer type, otherwise EXPR2. */ #define __atomic_ptr_choose(EXPR1, EXPR2) \ __builtin_choose_expr (__builtin_classify_type (EXPR1) == 5, \ (EXPR1), (EXPR2)) /* The size of *EXPR if EXPR has a pointer type, 1 otherwise. */ #define __atomic_ptr_size(EXPR) \ ((__PTRDIFF_TYPE__) \ sizeof (*(__typeof (__atomic_ptr_choose (EXPR, (char *) 0))) 0)) #define atomic_fetch_add(PTR, VAL) \ __extension__ \ ({ \ __auto_type __atomic_fetch_add_ptr = (PTR); \ __atomic_fetch_add (__atomic_fetch_add_ptr, \ (VAL) * __atomic_ptr_size (*__atomic_fetch_add_ptr), \ __ATOMIC_SEQ_CST); \ })