vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.24k stars 145 forks source link

Assertion error in 'process_aggregate_arg' for anonymous struct/union #392

Closed andy-hanson closed 1 month ago

andy-hanson commented 3 months ago
#include <stdio.h>
struct S {
    int filler;
    struct {
        const char* str;
    };
};
void f(struct S a) {
    printf("%s\n", a.str);
}
void main(void) {
    f((struct S) {.str = "foo"});
}

Running c2m a.c -eg: This should print "foo". Instead there is an internal assertion error:

c2m: c2mir/x86_64/cx86_64-ABI-code.c:314: process_aggregate_arg: Assertion `FALSE' failed.

Tested using a local build of commit 9b7aa035d97ab3b8e7b3e04d995c19794de1d0e6 with make debug then sudo make install.

The error seems to happen if there is any anonymous struct or union that contains a pointer member. There's no error if I break it out to a named type, remove int filler;, or use char str[4] instead.

vnmakarov commented 1 month ago

Thank you for reporting this. It revealed wrong passing such structures as arguments for x86-64 and riscv64 call ABI.

I fixed it by 62c4eced208353514ed303ef1ecb051d563cbc05 and 5ce509e30070cd074697c7ba92ce8bae988d378c.

andy-hanson commented 1 month ago

Thanks, I confirmed it's working now.