* src/SDCCast.c (isConformingBody): fixed bug 1505811, thanks Robert Larice
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 10 Mar 2008 21:34:22 +0000 (21:34 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 10 Mar 2008 21:34:22 +0000 (21:34 +0000)
* support/regression/tests/bug1505811.c: new, added

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

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

index 65079f559a12b8edd0a51f4007d6e38578a144d6..ca49bdca71abab71cf96e5a0d400cd764a0355c9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2008-03-10 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/SDCCast.c (isConformingBody): fixed bug 1505811, thanks Robert Larice
+       * support/regression/tests/bug1505811.c: new, added
+
 2008-03-09 Raphael Neider <rneider AT web.de>
 
        * device/include/pic16/pic18f2620.h,
index 94a1c5a24e80b7a06776e58d3b7fa8a5bf978e0c..869752b3955dfb9a774bd5952a2ded9cc0d322f7 100644 (file)
@@ -1799,8 +1799,8 @@ astHasDeref (ast * tree)
 }
 
 /*-----------------------------------------------------------------*/
-/* isConformingBody - the loop body has to conform to a set of rules */
-/* for the loop to be considered reversible read on for rules      */
+/* isConformingBody - the loop body has to conform to a set of     */
+/* rules for the loop to be considered reversible read on for rules*/
 /*-----------------------------------------------------------------*/
 bool
 isConformingBody (ast * pbody, symbol * sym, ast * body)
@@ -1809,14 +1809,13 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
   /* we are going to do a pre-order traversal of the
      tree && check for the following conditions. (essentially
      a set of very shallow tests )
-     a) the sym passed does not participate in
-     any arithmetic operation
+     a) the sym passed does not participate in any arithmetic operation
      b) There are no function calls
      c) all jumps are within the body
      d) address of loop control variable not taken
-     e) if an assignment has a pointer on the
-     left hand side make sure right does not have
-     loop control variable */
+     e) if an assignment has a pointer on the left hand side make sure
+        right does not have loop control variable
+  */
 
   /* if we reach the end or a leaf then true */
   if (!pbody || IS_AST_LINK (pbody) || IS_AST_VALUE (pbody))
@@ -1871,9 +1870,9 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
 
       /* if right is NULL then unary operation  */
 /*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*----------------------------*/
       /*  address of                */
-/*----------------------------*/
+      /*----------------------------*/
       if (!pbody->right)
         {
           if (IS_AST_SYM_VALUE (pbody->left) &&
@@ -1973,7 +1972,8 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
       if (astHasVolatile (pbody->left))
         return FALSE;
 
-      if (astHasDeref(pbody->right)) return FALSE;
+      if (astHasDeref(pbody->right))
+        return FALSE;
 
       return isConformingBody (pbody->left, sym, body) &&
         isConformingBody (pbody->right, sym, body);
@@ -1990,27 +1990,31 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
       assert ("Parser should not have generated this\n");
 
 /*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*----------------------------*/
       /*      comma operator        */
-/*----------------------------*/
+      /*----------------------------*/
     case ',':
       return isConformingBody (pbody->left, sym, body) &&
         isConformingBody (pbody->right, sym, body);
 
 /*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*----------------------------*/
       /*       function call        */
-/*----------------------------*/
+      /*----------------------------*/
     case CALL:
-        /* if local & not passed as paramater then ok */
-        if (sym->level && !astHasSymbol(pbody->right,sym))
+        /* if local & not passed as parameter &
+           not used to find the function then ok */
+        if (sym->level && !astHasSymbol (pbody->right, sym) &&
+            !astHasSymbol (pbody->left, sym))
+          {
             return TRUE;
+          }
       return FALSE;
 
 /*------------------------------------------------------------------*/
-/*----------------------------*/
+      /*----------------------------*/
       /*     return statement       */
-/*----------------------------*/
+      /*----------------------------*/
     case RETURN:
       return FALSE;
 
@@ -2029,9 +2033,6 @@ isConformingBody (ast * pbody, symbol * sym, ast * body)
 
   return isConformingBody (pbody->left, sym, body) &&
     isConformingBody (pbody->right, sym, body);
-
-
-
 }
 
 /*-----------------------------------------------------------------*/
diff --git a/support/regression/tests/bug1505811.c b/support/regression/tests/bug1505811.c
new file mode 100644 (file)
index 0000000..ddb4e0a
--- /dev/null
@@ -0,0 +1,34 @@
+/* bug 1505811
+ *   demonstrates an incorrect "loopreverse"
+ *   note func0, is a kind of safeguard, the incorrect code
+ *     will access indices 0 and 1 instead of 1 and 2,
+ *     and with incorrect order
+ */
+
+#include <testfwk.h>
+
+char glbl;
+
+void func0() { glbl = 0; }
+void func1() { glbl = 1; }
+void func2() { glbl = 2; }
+
+typedef void (*fptr)();
+
+fptr ep_init[3] = { func0, func1, func2 };
+
+void buggy()
+{
+  unsigned char i;
+  for(i = 1; i <= 2; i++)
+  {
+    ep_init[i]();
+  }
+}
+
+void
+testBug(void)
+{
+  buggy();
+  ASSERT(glbl == 2);
+}