compiler assert on `@naked` function with inline assembly and pointer
fn void main()
{
char[8] foo = {255, 0, 0, 0, 0, 0, 0, 0};
io::printn(to_ulong(&foo));
}
fn ulong to_ulong(char[8]* buf) @naked @noinline
{
asm
{
movq $rax, [buf];
ret;
}
unreachable();
}
⚠️ The compiler encountered an unexpected error: "Violated assert: decl->var.kind == VARDECL_GLOBAL || decl->var.kind == VARDECL_CONST".
- Function: llvm_get_ref(...)
- Source file: ../src/compiler/llvm_codegen.c:1283
🙏 Please consider taking the time to file an issue on GitHub, so that we can get it fixed:
https://github.com/c3lang/c3c/issues/new so that we can get it fixed.
Only asm("....") was intended to be available for these sections. If we should make more available or not is an open question, so I'm going to put this a little on hold.
Only asm("....") was intended to be available for these sections
as in asm{} blocks weren't intended to be allowed in @naked functions?
oh, do you mean that @naked functions were intended to only be used with asm blocks and not regular code (even the unreachable() would be disallowed)?
Yes
Even more, only asm("...") with strings would be allowed.
I've extended what's allowed in naked functions. Only return is disallowed now.
Please try it out.
running the example I gave at -O1 and above now causes a compiler segfault
Ok, it turns out that LLVM cannot properly support accessing those parameters, so I've completely disallowed it.
You can try this:
module test;
import std;
fn void main()
{
char[8] foo = {255, 0, 0, 0, 0, 0, 0, 0};
io::printn(to_ulong(&foo));
}
fn ulong to_ulong(char[8]*) @naked @noinline
{
asm
{
movq [$rsp - 8], $rdi;
movq $rax, [$rsp - 8];
movq $rax, [$rax];
ret;
}
unreachable();
}
it doesn't allow the unreachable() due to it using parameters under -O2, but other than that I can't get it to crash anymore, so I'll close this and #1959. Thank you!