On May 29, 2025 12:35:04 AM UTC, Lino Mastrodomenico <l.mastrodomen...@gmail.com> wrote: >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.
Cases which claim to be most common should avoid to use 'cleanup' in the first place. (IMO) > >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; Because what gcc does is "required semantics"? Maybe it is just undefined behavior, like in int n=0,*p=&n; return n + (*p=1); > When looking at the source code I'm tempted to swap leave_scope and > gfunc_return as Herman did. And what if there is no 'return'? printf("... %d\n", ({ int __attribute__ ((cleanup(my_cleanup))) n = 42; n; })); -- gr _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel