Hi all,

TCC semantics for the __attribute__((cleanup)) implementation are
different from GCC and Clang.

In other compilers if the cleanup function call is caused by a return
statement, it's only called after the return expression has been fully
evaluated.

In TCC instead, in at least some cases, the return expression can be
evaluated after the cleanup has already happened.

The order can be important because e.g. glib code often relies on the
GCC semantics: the return expression may try to read memory that the
cleanup function frees.

Here's a minimal test case:

#undef __attribute__

static void my_cleanup(int *p) {
    *p = 0x90;
}

int test_cleanup(void) {
    int __attribute__((cleanup(my_cleanup))) n = 42;
    return n;
}

test_cleanup() in TCC returns 0x90 while in GCC and Clang it returns 42.
Note that I've added an "#undef __attribute__" because sometimes GNU
system headers create a macro with this name and it creates confusion
during testing.

I see this issue with the latest mob branch on x86-64 but it's
probably not architecture-specific.

Thanks for this great compiler, BTW. :-)

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

Reply via email to