Re: [Tinycc-devel] Miscompiled code (when building GCC)

2024-05-31 Thread Herman ten Brugge via Tinycc-devel

On 4/29/24 23:29, Andrius Štikonas wrote:

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 = };
 struct function *f = 
 ptr = &(obtain(f)->mem[obtain(f)->index]);
 return *ptr;
}


I pushed a fix for this on mob.

    Herman


___
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel


[Tinycc-devel] Miscompiled code (when building GCC)

2024-04-29 Thread Andrius Štikonas via Tinycc-devel
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 = };
struct function *f = 
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 mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel