From cad873959410ddacfcd1a61d59755adf870dd592 Mon Sep 17 00:00:00 2001 From: herman ten brugge Date: Sat, 11 Mar 2023 07:51:00 +0100 Subject: [PATCH] Fix nocode_wanted in expr_landor The generated code by yarpgen failed. I traced the problem to expr_landor. The problem was that nocode_wanted was removing too much code. See also testcase 33. --- tccgen.c | 3 ++- tests/tests2/33_ternary_op.c | 26 ++++++++++++++++++++++++++ tests/tests2/33_ternary_op.expect | 1 + 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tccgen.c b/tccgen.c index 765e7425..3273c3be 100644 --- a/tccgen.c +++ b/tccgen.c @@ -6263,7 +6263,7 @@ static int condition_3way(void) static void expr_landor(int op) { - int t = 0, cc = 1, f = 0, i = op == TOK_LAND, c; + int t = 0, cc = 1, f = 0, i = op == TOK_LAND, c, prev_ncw = nocode_wanted; for(;;) { c = f ? i : condition_3way(); if (c < 0) @@ -6286,6 +6286,7 @@ static void expr_landor(int op) nocode_wanted -= f; } else { gvtst_set(i, t); + nocode_wanted = prev_ncw; } } diff --git a/tests/tests2/33_ternary_op.c b/tests/tests2/33_ternary_op.c index ee025383..8305438c 100644 --- a/tests/tests2/33_ternary_op.c +++ b/tests/tests2/33_ternary_op.c @@ -50,6 +50,31 @@ void constantcond(void) printf("okay\n"); } +unsigned short tf_4_var_2 = 29886; +const unsigned short tf_4_var_34 = 54077; +const unsigned short tf_4_var_86 = 1129; +long int tf_4_var_98 = -4448775496354969734L; + +unsigned short tf_4_array_8 [9] = + {52593, 34626, 28127, 8124, 11473, 14634, 8370, 31153, 31060}; +unsigned short tf_4_array_2 [6] = + {7493, 64504, 22566, 54931, 44752, 18026}; +unsigned short tf_4_array_3 [9] = + {22671, 46595, 24007, 22460, 12020, 19732, 46148, 3906, 26139}; +unsigned short tf_4_array_7 [9] = + {24530, 26236, 61122, 9019, 26099, 31028, 1078, 27042, 36756}; +unsigned short tf_4_array_4 [9] = + {32711, 2853, 55531, 52731, 6621, 38797, 23543, 64627, 55640}; + +long int tf_4_var_132 = -6396431410421938408L; + +static void tst_yarpgen(void) +{ + /* generated by yarpgen */ + tf_4_var_132 = (long int) (((unsigned long long int) (((((((int) (tf_4_var_86)) && ((int) (tf_4_array_8 [0]))) ? (((int) (tf_4_var_2)) || ((int) (8))) : (((int) (tf_4_array_2 [0])) || (-4096)))) || ((((int) (tf_4_array_3 [6])) || ((int) (tf_4_var_34))) && (((int) (tf_4_array_3 [7])) || ((int) (tf_4_var_98))))) % ((+((int) ((unsigned short) (-6)))) && ((((int) (tf_4_array_7 [5])) & ((int) (tf_4_array_7 [1]))) | (((int) (tf_4_array_4 [0])) & ((int) (tf_4_array_4 [0]))))))) <= (((unsigned long long int) ((int) ((unsigned short) (((7192886880476152731ULL) * (7192886880476152731ULL)) * ((unsigned long long int) (((-9223372036854775807L - 1L)) * ((long int) ((int) (0))))))))) * (((unsigned long long int) (((-6) * ((int) (3))) * (-((int) (4))))) * (((8ULL) * (4ULL)) * ((unsigned long long int) (((long int) (-6)) * (-3L))))))); + printf("%ld\n", tf_4_var_132); +} + int main() { int Count; @@ -86,6 +111,7 @@ int main() constantcond(); + tst_yarpgen(); return 0; } diff --git a/tests/tests2/33_ternary_op.expect b/tests/tests2/33_ternary_op.expect index 158d02ff..c21f5fbb 100644 --- a/tests/tests2/33_ternary_op.expect +++ b/tests/tests2/33_ternary_op.expect @@ -11,3 +11,4 @@ 27 152 okay +1