ldc icon indicating copy to clipboard operation
ldc copied to clipboard

importC: GCC-style inline asm accepts taking the address of a register variable

Open ibuclaw opened this issue 5 months ago • 2 comments

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).

ibuclaw avatar Aug 09 '25 00:08 ibuclaw

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.

kinke avatar Aug 09 '25 08:08 kinke

Edit: I was actually expecting it to be defined to an empty macro in importc.h ;) - but we have a TOK.register indeed.

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));
      |                       ^

ibuclaw avatar Aug 09 '25 09:08 ibuclaw