Bug 22722 – ImportC: parser doesn’t understand `asm volatile` syntax

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-01-31T22:27:31Z
Last change time
2023-03-22T23:58:28Z
Keywords
ImportC
Assigned to
No Owner
Creator
dave287091
See also
https://issues.dlang.org/show_bug.cgi?id=22161

Comments

Comment #0 by dave287091 — 2022-01-31T22:27:31Z
<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)`
Comment #5 by dlang-bot — 2023-02-16T17:45:58Z
@ibuclaw created dlang/dmd pull request #14890 "partial fix Issue 22722 - ImportC: parser doesn’t understand 'asm volatile' syntax" mentioning this issue: - partial fix Issue 22722 - ImportC: parser doesn’t understand 'asm volatile' syntax https://github.com/dlang/dmd/pull/14890
Comment #6 by dlang-bot — 2023-03-20T20:37:21Z
dlang/dmd pull request #14890 "partial fix Issue 22722 - ImportC: parser doesn’t understand 'asm volatile' syntax" was merged into master: - a7af3a05452ac5ad8c70996f1eae18f196228b9c by Iain Buclaw: partial fix Issue 22722 - ImportC: parser doesn’t understand 'asm volatile' syntax https://github.com/dlang/dmd/pull/14890
Comment #7 by dave287091 — 2023-03-22T23:58:28Z