1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-20 14:29:30 +00:00

Merge pull request #418 from greg-king5/while-nothing

Fix the handling of the C construct "while (0) { }".
This commit is contained in:
Oliver Schmidt 2017-04-07 16:07:38 +02:00 committed by GitHub
commit 9b243ff68c
2 changed files with 88 additions and 34 deletions

View File

@ -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);

View File

@ -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;
}