tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Ekaitz Zarraga
Subject: [Tinycc-devel] Fwd: Miscompiled code (when building GCC)
Date: Mon, 29 Apr 2024 23:48:59 +0200

(This is an email sent Andrius Štikonas but seems that it didn't do it to the mailing list)

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]