~mcf/cproc#77: 
Miscompilation and assertion failure on initialization of flexible array member

Howdy,

Some other small compilers (TinyCC and maybe ChibiCC) support automatic allocation of flexible array members upon initialization, and it would be really nice if cproc would support this as well, or at least error upon trying to use this construct.

On my x86_64 Debian Bookworm GNU/Linux system, the following program compiles successfully but segfaults at runtime:

int main(void) {
	struct {
		int i;
		char s[];
	} w = { .s = "Hello, world" };
}

With TinyCC, this does the common sense thing of allocating space for the string on the stack. GCC and Clang only support this construct if the struct is static. In this case though, we get a nifty assertion failure:

cproc-qbe: qbe.c:1449: emitdata: Assertion `offset <= d->type->size' failed.
cproc: compile: process signaled: Aborted
Status
REPORTED
Submitter
~jscott
Assigned to
No-one
Submitted
3 years ago
Updated
3 years ago
Labels
No labels applied.