From 5f08561e10bc7a91d901f43e1676e24219b0bfb7 Mon Sep 17 00:00:00 2001 From: grischka Date: Sat, 11 Mar 2023 21:35:12 +0100 Subject: [PATCH] Revert ""Fix" nocode_wanted in expr_landor" instead in vcheck_cmp(), pass the CODE_OFF_BIT to generators unless other nocode purposes are set. This reverts commit cad873959410ddacfcd1a61d59755adf870dd592. Also in 128_run_atexit.c: avoid line output disorder which may happen on windows when tcc itself and runned code are using two different printf implementations and tcc would print the "[Returns 1]" above any output from the runned test. --- tccgen.c | 16 +++++++++++----- tests/tests2/128_run_atexit.c | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tccgen.c b/tccgen.c index 3273c3be..da5c81b1 100644 --- a/tccgen.c +++ b/tccgen.c @@ -56,8 +56,9 @@ ST_DATA int nocode_wanted; /* no code generation wanted */ #define unevalmask 0xffff /* unevaluated subexpression */ #define NODATA_WANTED (nocode_wanted > 0) /* no static data output wanted either */ #define DATA_ONLY_WANTED 0x80000000 /* ON outside of functions and for static initializers */ -#define CODE_OFF() if(!nocode_wanted)(nocode_wanted |= 0x20000000) -#define CODE_ON() (nocode_wanted &= ~0x20000000) +#define CODE_OFF_BIT 0x20000000 +#define CODE_OFF() if(!nocode_wanted)(nocode_wanted |= CODE_OFF_BIT) +#define CODE_ON() (nocode_wanted &= ~CODE_OFF_BIT) ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */ ST_DATA CType func_vt; /* current function return type (used by return instruction) */ @@ -765,7 +766,13 @@ static void vcheck_cmp(void) again, so that the VT_CMP/VT_JMP value will be in vtop when code is unsuppressed again. */ - if (vtop->r == VT_CMP && !nocode_wanted) + /* However if it's just automatic suppression via CODE_OFF/ON() + then it seems that we better let things work undisturbed. + How can it work at all under nocode_wanted? Well, gv() will + actually clear it at the gsym() in load()/VT_JMP in the + generator backends */ + + if (vtop->r == VT_CMP && 0 == (nocode_wanted & ~CODE_OFF_BIT)) gv(RC_INT); } @@ -6263,7 +6270,7 @@ static int condition_3way(void) static void expr_landor(int op) { - int t = 0, cc = 1, f = 0, i = op == TOK_LAND, c, prev_ncw = nocode_wanted; + int t = 0, cc = 1, f = 0, i = op == TOK_LAND, c; for(;;) { c = f ? i : condition_3way(); if (c < 0) @@ -6286,7 +6293,6 @@ static void expr_landor(int op) nocode_wanted -= f; } else { gvtst_set(i, t); - nocode_wanted = prev_ncw; } } diff --git a/tests/tests2/128_run_atexit.c b/tests/tests2/128_run_atexit.c index f8b0f3e7..c3ff1fea 100644 --- a/tests/tests2/128_run_atexit.c +++ b/tests/tests2/128_run_atexit.c @@ -1,4 +1,5 @@ -int printf(const char *format, ...); +#include + int atexit(void (*function)(void)); int on_exit(void (*function)(int, void *), void *arg); void exit(int status); @@ -6,6 +7,7 @@ void exit(int status); void cleanup1(void) { printf ("cleanup1\n"); + fflush(stdout); } void cleanup2(void) -- 2.11.4.GIT