Thanks to both of you. The semantics of __attribute__((cleanup)) require that the entire return expression is evaluated before the cleanup functions are called. So saving the cleanup symbol solves most common cases but not all of them.
E.g. this slightly modified test case returns 42 on GCC and Clang but 0x90 on the current TCC mob: static void my_cleanup(int **p) { **p = 0x90; } int test_cleanup(void) { int n = 42; int __attribute__((cleanup(my_cleanup))) *p = &n; return n; } When looking at the source code I'm tempted to swap leave_scope and gfunc_return as Herman did. Il giorno sab 24 mag 2025 alle ore 23:28 grischka via Tinycc-devel < tinycc-devel@nongnu.org> ha scritto: > On 22.05.2025 17:29, Herman ten Brugge via Tinycc-devel wrote: > > On 5/11/25 23:11, Lino Mastrodomenico wrote: > >> Hi all, > >> > >> TCC semantics for the __attribute__((cleanup)) implementation are > >> different from GCC and Clang. > >> [...] > > > I pushed a fix for this. > > > > Herman > > I'd think we better don't switch those statements > > leave_scope(root_scope); > if (b) > gfunc_return(&func_vt); > > and instead save only the cleanup symbol, specifically if it is > a SValue on vstack. See > > https://repo.or.cz/tinycc.git/commitdiff/83de532563c6d922c6262dea757a22cb90d06101 > > --- gr > > _______________________________________________ > Tinycc-devel mailing list > Tinycc-devel@nongnu.org > https://lists.nongnu.org/mailman/listinfo/tinycc-devel >
_______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel