vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Assertion error in 'process_aggregate_arg' for anonymous struct/union

andy-hanson opened this issue · comments

#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 9b7aa03 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.

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

I fixed it by 62c4ece and 5ce509e.

Thanks, I confirmed it's working now.