ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Naked functions can't access to their parameters

Open Dadoum opened this issue 1 year ago • 2 comments

import ldc.attributes;
import ldc.llvmasm;

void test(void* del) @naked {
	__asm("jmp *$0", "{rax}", del);
}

This causes LDC to output a stacktrace without writing any readable error.

Dadoum avatar May 30 '23 06:05 Dadoum

The prologue is skipped for naked functions, so params can only be accessed via underlying register/stack slot. E.g., for Posix x86_64:

void test(void* del) @naked {
    asm { "jmp *%%rdi"; }
}

kinke avatar May 30 '23 10:05 kinke

I was curious seeing this scroll by – it only fails in SelectionDAG when optimisations are enabled; at -O0, LLVM seems happy enough to emit machine code for this. Please include the exact output and compiler version/flags when filing issues!

Seems like we should disallow parameter access in @naked functions in the frontend layer.

dnadlinger avatar May 30 '23 11:05 dnadlinger