ldc
ldc copied to clipboard
importC: GCC-style inline asm accepts taking the address of a register variable
void f()
{
register int ax;
asm("" : "=m" (ax));
asm("" :: "m" (ax));
}
This is illegal C code, so should be rejected at codegen time (can't be handled by the frontend parser or semantic, as it doesn't know about backend generic/target asm constraints).
Yeah well I assume importC simply ignores the register keyword, so...
Edit: I was actually expecting it to be defined to an empty macro in importc.h ;) - but we have a TOK.register indeed.
Edit: I was actually expecting it to be defined to an empty macro in
importc.h;) - but we have aTOK.registerindeed.
And an STC.register storage class. ;-)
Edit: And yes it does reach our codegen layer.
$ cat test.d
import regasm;
void main() { f(); }
$ gdc-14 test.d
regasm.c: In function ‘f’:
regasm.c:4:23: error: address of register variable ‘ax’ requested
4 | asm("" : "=m" (ax));
| ^
regasm.c:5:23: error: address of register variable ‘ax’ requested
5 | asm("" :: "m" (ax));
| ^