/* Remember the current position */
GetCodePos (&CondCodeStart);
- /* Emit the code position label */
- g_defcodelabel (CondLabel);
-
/* Test the loop condition */
TestInParens (LoopLabel, 1);
/* Loop body */
Statement (&PendingToken);
+ /* Emit the while condition label */
+ g_defcodelabel (CondLabel);
+
/* Move the test code here */
GetCodePos (&Here);
MoveCode (&CondCodeStart, &CondCodeEnd, &Here);
/*
- !!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;
-
-#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;
}