From 7ad2cf8d68249a3da0322863297ff48327c4fed0 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Tue, 14 Nov 2017 15:38:40 +0100 Subject: [PATCH] Code suppression fixes See adjusted testcase, a lone break; in a do while loop was incorrectly disabling the exit test. --- tccgen.c | 2 ++ tests/tests2/87_dead_code.c | 33 ++++++++++++++++++++++++++++++++ tests/tests2/87_dead_code.expect | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/tccgen.c b/tccgen.c index 2c365be7..5265e494 100644 --- a/tccgen.c +++ b/tccgen.c @@ -6088,6 +6088,8 @@ static void block(int *bsym, int *csym, int is_expr) skip(TOK_WHILE); skip('('); gsym(b); + if (b) + nocode_wanted = saved_nocode_wanted; gexpr(); c = gvtst(0, 0); gsym_addr(c, d); diff --git a/tests/tests2/87_dead_code.c b/tests/tests2/87_dead_code.c index 98d4566c..0d5a64ce 100644 --- a/tests/tests2/87_dead_code.c +++ b/tests/tests2/87_dead_code.c @@ -26,6 +26,36 @@ static void kb_wait_1(void) timeout--; } while (timeout); } + +static int global; + +static void foo(int i) +{ + global+=i; + printf ("g=%d\n", global); +} + +static int check(void) +{ + printf ("check %d\n", global); + return 1; +} + +static void dowhile(void) +{ + do { + foo(1); + if (global == 1) { + continue; + } else if (global == 2) { + continue; + } + /* The following break shouldn't disable the check() call, + as it's reachable by the continues above. */ + break; + } while (check()); +} + int main (void) { int i = 1; @@ -118,5 +148,8 @@ enterloop3: printf ("error4\n"); } } + + dowhile(); + return 0; } diff --git a/tests/tests2/87_dead_code.expect b/tests/tests2/87_dead_code.expect index 0b3ec1d9..a8c93bd0 100644 --- a/tests/tests2/87_dead_code.expect +++ b/tests/tests2/87_dead_code.expect @@ -16,3 +16,8 @@ once3 twice3 caseok caseok2 +g=1 +check 1 +g=2 +check 2 +g=3