mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Do not allow parameters in naked functions.
This commit is contained in:
@@ -1,28 +1,37 @@
|
||||
// #target: macos-x64
|
||||
module test;
|
||||
import std;
|
||||
|
||||
fn void main()
|
||||
{
|
||||
char[8] foo = {255, 0, 0, 0, 0, 0, 0, 0};
|
||||
io::printn(to_ulong(&foo));
|
||||
ulong a = to_ulong2(&foo);
|
||||
ulong b = to_ulong(&foo);
|
||||
}
|
||||
|
||||
fn ulong to_ulong(char[8]* buf) @naked @noinline
|
||||
fn ulong to_ulong(char[8]*) @naked @noinline
|
||||
{
|
||||
asm
|
||||
{
|
||||
movq $rax, [buf];
|
||||
movq [$rsp - 8], $rdi;
|
||||
movq $rax, [$rsp - 8];
|
||||
movq $rax, [$rax];
|
||||
ret;
|
||||
}
|
||||
unreachable();
|
||||
}
|
||||
|
||||
fn ulong to_ulong2(char[8]* buf)
|
||||
{
|
||||
return *(ulong*)buf;
|
||||
}
|
||||
|
||||
|
||||
/* #expect: test.ll
|
||||
|
||||
define i64 @test.to_ulong(ptr %0) #1 {
|
||||
entry:
|
||||
call void asm sideeffect alignstack "movq ($0), %rax\0Aret \0A", "r,~{rax},~{flags},~{dirflag},~{fspr}"(ptr %0)
|
||||
call void asm sideeffect alignstack "movq %rdi, -8(%rsp)\0Amovq -8(%rsp), %rax\0Amovq (%rax), %rax\0Aret \0A", "~{rax},~{flags},~{dirflag},~{fspr}"()
|
||||
unreachable
|
||||
}
|
||||
|
||||
attributes #1 = { naked noinline nounwind uwtable "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
|
||||
|
||||
@@ -10,4 +10,10 @@ fn ulong? test() @naked @noinline
|
||||
int? z;
|
||||
z!; // #error: Rethrow is not allowed in a '@naked' function
|
||||
unreachable();
|
||||
}
|
||||
|
||||
fn ulong test2(int a) @naked @noinline
|
||||
{
|
||||
int x = a; // #error: Parameters may not be directly accessed in '@naked' functions
|
||||
unreachable();
|
||||
}
|
||||
Reference in New Issue
Block a user