<dispatch/dispatch.h> on macOS, which is included by <CoreFoundation/CoreFoundation.h>, has an inline function which has a macro defined:
#define dispatch_compiler_barrier() __asm__ __volatile__("" ::: "memory”)
Where it is used, it is expanded to:
typedef void (*dispatch_function_t)(void *);
typedef intptr_t dispatch_once_t;
extern void dispatch_once_f(dispatch_once_t *predicate, void * context, dispatch_function_t function);
static inline /* several attributes omitted */
void
_dispatch_once_f(dispatch_once_t *predicate, void * context, dispatch_function_t function)
{
if (__builtin_expect((*predicate), (~0l)) != ~0l) {
dispatch_once_f(predicate, context, function);
} else {
asm volatile("" ::: "memory");
}
__builtin_assume(*predicate == ~0l);
}
gcc docs on the use of volatile with asm: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
Comment #1 by bugzilla — 2022-02-02T09:22:47Z
It does more than not accept the `volatile`, it also does not accept the `( ... )` construct. I'm not sure what to do about it. There are no plans to implement the gnu assembler syntax.
Comment #2 by dave287091 — 2022-02-02T16:55:47Z
(In reply to Walter Bright from comment #1)
> It does more than not accept the `volatile`, it also does not accept the `(
> ... )` construct. I'm not sure what to do about it. There are no plans to
> implement the gnu assembler syntax.
It’s unfortunate as it is not even using the asm, it’s just to inhibit compiler optimizations. If __GNUC__ is not defined it defines it as do { } while(0).
Comment #3 by bugzilla — 2022-09-23T08:52:51Z
> If __GNUC__ is not defined it defines it as do { } while(0)
__GNUC__ is for compiling with gcc. It's not a good idea for ImportC to pretend to be gcc.
Comment #4 by dave287091 — 2022-09-26T19:45:36Z
(In reply to Walter Bright from comment #3)
> > If __GNUC__ is not defined it defines it as do { } while(0)
>
> __GNUC__ is for compiling with gcc. It's not a good idea for ImportC to
> pretend to be gcc.
clang also defines __GNUC__. There are other ways extensions like gnu asm can make it into headers, like `#if __has_extension(gnu_asm)`