Regression file for testing the nested for-loop bug in the PIC port that Steve Tell...
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 30 Mar 2003 14:47:23 +0000 (14:47 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 30 Mar 2003 14:47:23 +0000 (14:47 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2431 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/regression/nestfor.c [new file with mode: 0644]

diff --git a/src/regression/nestfor.c b/src/regression/nestfor.c
new file mode 100644 (file)
index 0000000..8b22cae
--- /dev/null
@@ -0,0 +1,146 @@
+#define __16F873
+#include "p16f873.h"
+//#include "p16c84.h"
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+
+unsigned char call3(void);
+
+void dput(unsigned char val)
+{
+       PORTB = val;
+       PORTA = 0x01;
+       PORTA = 0x00;
+}
+
+void done()
+{
+
+  dummy++;
+
+}
+
+/* both loops use the loop variable inside the inner loop */
+void for1(void)
+{
+       unsigned char i, j;
+
+       uchar0 = 0;
+       uchar1 = 0;
+       for(i = 0; i < 3; i++) {
+               uchar0++;
+               for(j = 0; j < 4; j++) {
+                       uchar1++;
+                       dput(i);
+                       dput(j);
+               }
+       }
+       if(uchar0 != 3)
+               failures++;
+       if(uchar1 != 12)
+               failures++;
+}
+
+/* only the outer loop's variable is used inside, inner can be optimized into a repeat-loop */
+void for2(void)
+{
+       unsigned char i, j;
+
+       uchar0 = 0;
+       uchar1 = 0;
+       for(i = 0; i < 3; i++) {
+               uchar0++;
+               for(j = 0; j < 4; j++) {
+                       uchar1++;
+                       dput(i);
+               }
+       }
+       if(uchar0 != 3)
+               failures++;
+       if(uchar1 != 12)
+               failures++;
+}
+
+/* only the inner loop's variable is used inside */
+void for3(void)
+{
+       unsigned char i, j;
+
+       uchar0 = 0;
+       uchar1 = 0;
+       for(i = 0; i < 3; i++) {
+               uchar0++;
+               for(j = 0; j < 4; j++) {
+                       uchar1++;
+                       dput(j);
+               }
+       }
+       if(uchar0 != 3)
+               failures++;
+       if(uchar1 != 12)
+               failures++;
+
+}
+
+/* neither loop variable used inside the loops */
+void for4(void)
+{
+       unsigned char i, j;
+
+       uchar0 = 0;
+       uchar1 = 0;
+       for(i = 0; i < 3; i++) {
+               uchar0++;
+               for(j = 0; j < 4; j++) {
+                       uchar1++;
+                       dput(uchar0);
+                       dput(uchar1);
+               }
+       }
+       if(uchar0 != 3)
+               failures++;
+       if(uchar1 != 12)
+               failures++;
+
+}
+
+/* like for1 but different condition in inner loop */
+void for5(void)
+{
+       unsigned char i, j;
+
+       uchar0 = 0;
+       uchar1 = 0;
+       for(i = 0; i < 3; i++) {
+               uchar0++;
+               for(j = 10; j >= 5; j--) {
+                       uchar1++;
+                       dput(i);
+                       dput(j);
+               }
+       }
+       if(uchar0 != 3)
+               failures++;
+       if(uchar1 != 18)
+               failures++;
+}
+
+void main(void)
+{
+  for1();
+  for2();
+  for3();
+  for4();
+  for5();
+
+  success = failures;
+  done();
+}