ldc
ldc copied to clipboard
No error when using params in @naked functions
On x86_64: https://godbolt.org/z/dEaaqPh7v
import ldc.attributes;
import ldc.llvmasm;
@naked long spawnLinuxThread1(void* data) {
return __asm!long("syscall",
"={eax}, {rax}, {rdi}, {rsi}",
56, 0x50f00, data);
}
produces:
mov rsi, qword ptr [rdi]
mov eax, 56
mov edi, 331520
syscall
ret
instead of
mov rsi, rdi
mov eax, 56
mov edi, 331520
syscall
ret
Changing void* to ulong causes LLVM ERROR:
Invalid bitcast
%2 = bitcast i64 %0 to ptr, !dbg !7
LLVM ERROR: Broken module found, compilation aborted!
Same happens on arm64: https://godbolt.org/z/7Eb3Pqabd
This bug is due to using @naked and the resulting IR generation not dealing with that properly. With @naked we load from passed parameter address instead of the usual loading from the temp storage address (where the passed parameter is stored).
Compare the output of this code with/without @naked:
//@naked
size_t foo(void* data) {
return cast(size_t) data;
}
I see. Should I expect this to be fixed?
Not sure how much we want/should support with @naked.
I do consider it a bug. If we don't support this usage / it's buggy, then it's better to emit a compile error for it than to leave it unfixed.