mirror of
https://github.com/cc65/cc65.git
synced 2024-12-23 04:30:10 +00:00
Fixed the handling of "while (0) {}".
It's a corner case; but, conditional macroes might create it -- better safe than sorry.
This commit is contained in:
parent
e43dbe1c24
commit
1aab287189
@ -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);
|
||||
|
116
test/val/while.c
116
test/val/while.c
@ -1,53 +1,107 @@
|
||||
/*
|
||||
!!DESCRIPTION!!
|
||||
!!DESCRIPTION!! while-condition tests
|
||||
!!ORIGIN!! SDCC regression tests
|
||||
!!LICENCE!! GPL, read COPYING.GPL
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
|
||||
unsigned char success = 0;
|
||||
unsigned char failures = 0;
|
||||
unsigned char dummy = 0;
|
||||
static unsigned char failures = 0x00;
|
||||
static unsigned char achar0 = 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 ()
|
||||
{
|
||||
dummy++;
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
while1 (void)
|
||||
{
|
||||
unsigned char i = 10;
|
||||
|
||||
do
|
||||
{
|
||||
achar0++;
|
||||
}
|
||||
while (--i);
|
||||
do {
|
||||
++achar0;
|
||||
} while (--i);
|
||||
|
||||
if (achar0 != 10)
|
||||
failures++;
|
||||
if (achar0 != 10) {
|
||||
failures |= 0x01;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
while2 (void)
|
||||
{
|
||||
unsigned char i = 10;
|
||||
|
||||
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 (1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user