c3c icon indicating copy to clipboard operation
c3c copied to clipboard

Asm block instructions corrupted by safe-mode pointer checks

Open rickyadastra opened this issue 2 weeks ago • 3 comments

Using a dereferenced pointer as an argument inside an asm block having safe-mode enabled causes a compilation error. It appears that the code for generating runtime safety checks on the pointer deference interferes with the assembly instruction string passed to LLVM.

The compilation error does not happen with safe-mode disabled (--safe=no) and when the deference is done outside the asm block, like ptrDeref does in the example.

Example and actual behavior

fn void main() {
    long l = 0xbeef;
    long* ptr = &l;
    long ptrDeref = *ptr;

    asm {
        movq $rax, (*ptr);
        // movq $rax, ptrDeref; // works
    }
}

Compiling outputs the following:

error: <inline asm>:1:2: invalid instruction mnemonic 'std.core.builtin.panicf'
        std.core.builtin.panicf
        ^~~~~~~~~~~~~~~~~~~~~~~

Tested on latest pre-release 0.7.9 (18e28387722e3740b8786d964caaac375a0282bd)

rickyadastra avatar Dec 06 '25 19:12 rickyadastra

I am afraid this needs to wait until the asm fixes, when all these are addressed.

lerno avatar Dec 07 '25 22:12 lerno

The workaround will be the only allowed solution anyway.

lerno avatar Dec 07 '25 22:12 lerno

Oh okay, it's fine.

I'm assuming there will be a subset of expressions not allowed in asm blocks then, is that correct?

rickyadastra avatar Dec 07 '25 23:12 rickyadastra