From: Greg King Date: Fri, 7 Apr 2017 13:26:58 +0000 (-0400) Subject: Fixed the handling of "while (0) {}". X-Git-Tag: V2.17~149^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F418%2Fhead;p=cc65 Fixed the handling of "while (0) {}". It's a corner case; but, conditional macroes might create it -- better safe than sorry. --- diff --git a/src/cc65/stmt.c b/src/cc65/stmt.c index 84b516dc3..c6167fa78 100644 --- a/src/cc65/stmt.c +++ b/src/cc65/stmt.c @@ -273,9 +273,6 @@ static void WhileStatement (void) /* Remember the current position */ GetCodePos (&CondCodeStart); - /* Emit the code position label */ - g_defcodelabel (CondLabel); - /* Test the loop condition */ TestInParens (LoopLabel, 1); @@ -288,6 +285,9 @@ static void WhileStatement (void) /* Loop body */ Statement (&PendingToken); + /* Emit the while condition label */ + g_defcodelabel (CondLabel); + /* Move the test code here */ GetCodePos (&Here); MoveCode (&CondCodeStart, &CondCodeEnd, &Here); diff --git a/test/val/while.c b/test/val/while.c index cf2147052..b86b1fba5 100644 --- a/test/val/while.c +++ b/test/val/while.c @@ -1,53 +1,107 @@ /* - !!DESCRIPTION!! + !!DESCRIPTION!! while-condition tests !!ORIGIN!! SDCC regression tests !!LICENCE!! GPL, read COPYING.GPL */ #include -#include - -unsigned char success = 0; -unsigned char failures = 0; -unsigned char dummy = 0; - -#ifdef SUPPORT_BIT_TYPES -bit bit0 = 0; -#endif -unsigned int aint0 = 0; -unsigned int aint1 = 0; -unsigned char achar0 = 0; -unsigned char achar1 = 0; - -void -done () + +static unsigned char failures = 0x00; +static unsigned char achar0 = 0; + +static void +while1 (void) { - dummy++; + unsigned char i = 10; + + do { + ++achar0; + } while (--i); + + if (achar0 != 10) { + failures |= 0x01; + } } -void -while1 (void) +static void +while2 (void) { unsigned char i = 10; - do - { - achar0++; + achar0 = 0; + while (--i) { + ++achar0; + } + + if (achar0 != 10 - 1) { + failures |= 0x02; + } +} + +static void +while3 (void) +{ + achar0 = 0; + do { + if (++achar0 == (unsigned char)0) { + return; } - while (--i); + } while (1); - if (achar0 != 10) - failures++; + failures |= 0x04; +} + +static void +while4 (void) +{ + achar0 = 0; + while (1) { + if (++achar0 == (unsigned char)0) { + return; + } + } + + failures |= 0x08; +} + +static void +while5 (void) +{ + achar0 = 0; + do { + ++achar0; + } while (0); + + if (achar0 != 1) { + failures |= 0x10; + } +} + +static void +while6 (void) +{ + achar0 = 0; + while (0) { + ++achar0; + } + + if (achar0 != 1 - 1) { + failures |= 0x20; + } } int main (void) { while1 (); + while2 (); + while3 (); + while4 (); + while5 (); + while6 (); - success = failures; - done (); - printf("failures: %d\n",failures); - + if (failures) { + printf("failures: 0x%02X\n", failures); + } return failures; }