From ca435dc2e36c685a225933283841ab3a827c3316 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 26 Sep 2016 20:31:24 +0200 Subject: opt: Make break and goto not fallthrough As we can optimize dead code a bit already it's fitting to disable code emission after break and goto. --- tests/tcctest.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'tests/tcctest.c') diff --git a/tests/tcctest.c b/tests/tcctest.c index 8031af4..a0ddc84 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -1184,6 +1184,57 @@ void optimize_out(void) printf("oo:%d\n", defined_function()); else printf("oo:%d\n", undefined_function()); + while (1) { + printf("oow:%d\n", defined_function()); + break; + printf("oow:%d\n", undefined_function()); + } + j = 1; + /* Following is a switch without {} block intentionally. */ + switch (j) + case 1: break; + printf ("oos:%d\n", defined_function()); + /* The following break shouldn't lead to disabled code after + the while. */ + while (1) + break; + printf ("ool1:%d\n", defined_function()); + /* Same for the other types of loops. */ + do + break; + while (1); + printf ("ool2:%d\n", defined_function()); + for (;;) + break; + printf ("ool3:%d\n", defined_function()); + /* Normal {} blocks without controlling statements + shouldn't reactivate code emission */ + while (1) { + { + break; + } + printf ("ool4:%d\n", undefined_function()); + } + j = 1; + while (j) { + if (j == 0) + break; /* this break shouldn't disable code outside the if. */ + printf("ool5:%d\n", defined_function()); + j--; + } + + j = 1; + while (j) { + if (1) + j--; + else + breakhere: break; + printf("ool6:%d\n", defined_function()); + goto breakhere; + } + if (1) + return; + printf ("oor:%d\n", undefined_function()); } int defined_function(void) -- cgit v1.3.1