[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] Miscompiled code (when building GCC)
From: |
Andrius Štikonas |
Subject: |
[Tinycc-devel] Miscompiled code (when building GCC) |
Date: |
Mon, 29 Apr 2024 22:29:58 +0100 |
Hi,
When trying to compile gcc, we stumbled upon strange segfault that seem to be
coming from tcc.
This is the reproducer:
struct thing {
unsigned index;
char mem[1];
};
struct function {
struct thing* t;
};
static inline struct thing* obtain (const struct function *f) {
return f->t;
}
int main () {
char *ptr;
struct thing u = {.index = 0, .mem = {'a'}};
struct function g = {.t = &u};
struct function *f = &g;
ptr = &(obtain(f)->mem[obtain(f)->index]);
return *ptr;
}
When tcc (mob) is used to build it we get a segfault. On the other hand, GCC
returns 97 ('a').
Some curious observation. Replacing the ptr line with
struct thing * x = obtain(f);
ptr = &(x->mem[x->index]);
or with
int x = obtain(f)->index;
ptr = &(obtain(f)->mem[x]);
Seems to workaround the crash on tcc-riscv64 but not on tcc-amd64.
Kind regards,
Andrius
- [Tinycc-devel] Miscompiled code (when building GCC),
Andrius Štikonas <=