The CParser only supports parsing DMD-style or GDC-style inline assembly. Both of which are not related to GCC.
E.g: This fails.
---
void asmtest()
{
asm("");
}
---
But this (weirdly) works:
---
void asmtest()
{
asm @safe { nop; }
}
---
... and with the gdc compiler, the D language equivalent would also compile:
---
void asmtest()
{
asm { ""; }
}
---
Comment #1 by bugzilla — 2021-09-26T09:38:01Z
That's unsurprising as the D asm parser is being used here. Not really sure what to do about it, as duplicating the gcc asm behavior would be a big job.
I'm going to mark this as an Enhancement, as ImportC's mission is to compile C11.
Comment #2 by ibuclaw — 2021-09-26T13:14:51Z
(In reply to Walter Bright from comment #1)
> That's unsurprising as the D asm parser is being used here. Not really sure
> what to do about it, as duplicating the gcc asm behavior would be a big job.
>
> I'm going to mark this as an Enhancement, as ImportC's mission is to compile
> C11.
The focus for DMD itself may be to make importC follow DMC asm as closely as it makes sense to do so.
https://www.digitalmars.com/ctg/ctgInlineAsm.html
This bug report is more for me (and ldc) though, as all asm code in Posix C headers and sources would be in the GCC style.
Comment #3 by bugzilla — 2021-09-28T05:38:23Z
(In reply to Iain Buclaw from comment #2)
> This bug report is more for me (and ldc) though, as all asm code in Posix C
> headers and sources would be in the GCC style.
I'm surprised the GDC inline asm isn't the same as GCC. I just presumed they were the same. DMC and DMD inline asm differs mainly because I didn't backport the improvements to DMC.
(In reply to TheGag96 from comment #4)
> Link to Mosquitto library: https://github.com/eclipse/mosquitto
Woops, posted this in the wrong bug. Sorry!!
Comment #6 by ibuclaw — 2022-11-26T11:17:46Z
(In reply to Walter Bright from comment #3)
> (In reply to Iain Buclaw from comment #2)
> > This bug report is more for me (and ldc) though, as all asm code in Posix C
> > headers and sources would be in the GCC style.
>
> I'm surprised the GDC inline asm isn't the same as GCC. I just presumed they
> were the same. DMC and DMD inline asm differs mainly because I didn't
> backport the improvements to DMC.
In D, asm is a statement, in C/C++ its an expression.
Comment #7 by bugzilla — 2023-04-01T21:05:13Z
DMD now supports parsing GCC style inline assembler, although it doesn't actually turn it into assembler code - it replaces it with an assert(0).
DMD's inline assembler is derived from DMC's, although the latter does not support 64 bit code or SIMD instructions. I don't recall how different it is for ordinary 32 bit code.
At this point it is not worth worrying about DMC inline asm compatibility, so deferring a decision about it until an actual issue crops up about it.