Closed fuhsnn closed 6 months ago
Assembly is needed to test reliably, since the compiler is free to not use the rax value.
rax
main.c
struct S { char t[600]; }; extern struct S fn(void); #include <stdio.h> int main(void) { struct S s; void* ptr = &s; asm ( "mov %0, %%rdi;" "call fn;" "mov %%rax, %0;" : "+r"(ptr) : : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9" ); printf("expect 1, got %d\n", ((void*)&s == ptr)); }
fn.c
struct S { char t[600]; }; struct S fn(void) { return (struct S){0}; }
test
cc main.c -c chibicc main.o fn.c
Assembly is needed to test reliably, since the compiler is free to not use the
rax
value.main.c
fn.c
test