* src/SDCCast.c (backPatchLabels): fixed bug #1408066: made it inifinitely recurseabl...
authorbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 17 Jan 2006 23:48:35 +0000 (23:48 +0000)
committerbernhardheld <bernhardheld@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 17 Jan 2006 23:48:35 +0000 (23:48 +0000)
* support/regression/tests/bug-1408066.c: added

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4020 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCast.c
support/regression/tests/bug-1408066.c [new file with mode: 0644]

index 8325d42c1fbb822740b2a92e92ed52e3e5382ceb..b4c2f67534846957abb29d3e3ff531d59d1aea00 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-01-18 Bernhard Held <bernhard AT bernhardheld.de>
+
+       * src/SDCCast.c (backPatchLabels): fixed bug #1408066: made it
+       inifinitely recurseable, added static   
+       * support/regression/tests/bug-1408066.c: added
+
 2006-01-17 Bernhard Held <bernhard AT bernhardheld.de>
 
        * src/SDCCicode.h,
index 3a91217c983507e25be4c2f2bc618865b4dd002b..285bf5e9b8d5d76f15fbe8474eacdd16cc60820d 100644 (file)
@@ -59,7 +59,7 @@ ast *optimizeGetHbit (ast *, RESULT_TYPE);
 ast *optimizeGetAbit (ast *, RESULT_TYPE);
 ast *optimizeGetByte (ast *, RESULT_TYPE);
 ast *optimizeGetWord (ast *, RESULT_TYPE);
-ast *backPatchLabels (ast *, symbol *, symbol *);
+static ast *backPatchLabels (ast *, symbol *, symbol *);
 void PA(ast *t);
 int inInitMode = 0;
 memmap *GcurMemmap=NULL;  /* points to the memmap that's currently active */
@@ -4519,11 +4519,12 @@ sizeofOp (sym_link * type)
 #define IS_IFX(ex) (ex->type == EX_OP && ex->opval.op == IFX )
 #define IS_LT(ex)  (ex->type == EX_OP && ex->opval.op == '<' )
 #define IS_GT(ex)  (ex->type == EX_OP && ex->opval.op == '>')
+#define IS_NULLOP(ex) (ex->type == EX_OP && ex->opval.op == NULLOP)
 
 /*-----------------------------------------------------------------*/
 /* backPatchLabels - change and or not operators to flow control    */
 /*-----------------------------------------------------------------*/
-ast *
+static ast *
 backPatchLabels (ast * tree, symbol * trueLabel, symbol * falseLabel)
 {
 
@@ -4588,25 +4589,18 @@ backPatchLabels (ast * tree, symbol * trueLabel, symbol * falseLabel)
   /* change not */
   if (IS_NOT (tree))
     {
-      int wasnot = IS_NOT (tree->left);
+      /* call with exchanged labels */
       tree->left = backPatchLabels (tree->left, falseLabel, trueLabel);
 
-      /* if the left is already a IFX */
+      /* if left isn't already a IFX */
       if (!IS_IFX (tree->left))
-        tree->left = newNode (IFX, tree->left, NULL);
-
-      if (wasnot)
-        {
-          tree->left->trueLabel = trueLabel;
-          tree->left->falseLabel = falseLabel;
-        }
-      else
         {
+          tree->left = newNode (IFX, tree->left, NULL);
           tree->left->trueLabel = falseLabel;
           tree->left->falseLabel = trueLabel;
         }
       return tree->left;
-    }
+     }
 
   if (IS_IFX (tree))
     {
diff --git a/support/regression/tests/bug-1408066.c b/support/regression/tests/bug-1408066.c
new file mode 100644 (file)
index 0000000..0052324
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+   bug-136564.c0
+
+   loop induction
+*/
+
+#include <testfwk.h>
+
+
+void
+testBackPatchLabel(void)
+{
+  volatile unsigned char c0 = 0, c1 = 1;
+  unsigned char r;
+
+  if (     (c0 == 0)) r = 1; else r = 0; ASSERT(r == 1);
+  if (    !(c0 == 0)) r = 1; else r = 0; ASSERT(r == 0);
+  if (   !!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 1);
+  if (  !!!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 0);
+  if ( !!!!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 1);
+  if (!!!!!(c0 == 0)) r = 1; else r = 0; ASSERT(r == 0);
+
+  if (     ((c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 1);
+  if (    !((c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 0);
+  if (   !!((c0 == 0) && (c1 == 1))) r = 1; else r = 0; ASSERT(r == 1);
+
+  if (     (  (c0 == 0) &&   (c1 == 1))) r = 1; else r = 0; ASSERT(r == 1);
+  if (    !( !(c0 == 1) &&  !(c1 == 0))) r = 1; else r = 0; ASSERT(r == 0);
+  if (   !!(!!(c0 == 0) && !!(c1 == 1))) r = 1; else r = 0; ASSERT(r == 1);
+}