From: bernhardheld Date: Mon, 1 Jan 2007 20:42:04 +0000 (+0000) Subject: * src/SDCCast.c (createDo): backPatchLabels() needs falseLabel in empty 'while'-loop... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=b6bf74fe60d0d76aa76e89e1b9adb870aa5b8933;p=fw%2Fsdcc * src/SDCCast.c (createDo): backPatchLabels() needs falseLabel in empty 'while'-loop to work correctly, see regression test 'while.c' * support/regression/tests/while.c: added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4550 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 1bb517aa..63a8cf9b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-01-01 Bernhard Held + + * src/SDCCast.c (createDo): backPatchLabels() needs falseLabel in + empty 'while'-loop to work correctly, see regression test 'while.c' + * support/regression/tests/while.c: added + 2007-01-01 Borut Razem * support/cpp2/libcpp/directives.c, support/cpp2/libcpp/identifiers.c, @@ -71,6 +77,7 @@ and flex are not installed, 2nd try 2006-12-30 Bernhard Held + * src/mcs51/peeph.def: renamed rule 400 to 500, moved rule 253.x to 400.x for better code in RFE 899102 diff --git a/src/SDCCast.c b/src/SDCCast.c index 99582eef..def33ed0 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -5148,11 +5148,13 @@ createDo (symbol * trueLabel, symbol * continueLabel, /* if the body does not exist then it is simple */ if (!doBody) { - condAst = backPatchLabels (condAst, continueLabel, NULL); + condAst = backPatchLabels (condAst, continueLabel, falseLabel); doTree = (IS_IFX (condAst) ? createLabel (continueLabel, condAst) : newNode (IFX, createLabel (continueLabel, condAst), NULL)); doTree->trueLabel = continueLabel; doTree->falseLabel = NULL; + + doTree = newNode (NULLOP, doTree, createLabel (falseLabel, NULL)); return doTree; } diff --git a/support/regression/tests/while.c b/support/regression/tests/while.c new file mode 100644 index 00000000..f38ae9bf --- /dev/null +++ b/support/regression/tests/while.c @@ -0,0 +1,30 @@ +/* + while.c +*/ + +#include + +char c1 = 0, c2 = 1; + +void +testEmptyWhile(void) +{ + /* loops forever if bug ist present */ + do {} while (c1 && c2); + + /* other cases: */ + do {} while ( c1 && c1); + do {} while ( c1 && !c2); + do {} while (!c1 && !c2); + do {} while ( c2 && c1); + do {} while (!c2 && c1); + do {} while (!c2 && !c1); + do {} while (!c2 && !c2); + + do {} while ( c1 || c1); + do {} while ( c1 || !c2); + do {} while (!c2 || c1); + do {} while (!c2 || !c2); + + ASSERT(1); +}