]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCCast.c (decorateType),
authorMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 16 Jun 2007 14:53:19 +0000 (14:53 +0000)
committerMaartenBrock <MaartenBrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 16 Jun 2007 14:53:19 +0000 (14:53 +0000)
* src/SDCCicode.c (geniCodeConditional): moved optimization for '?' from
  iCode to ast level to fix bug 1738367
* support/regression/tests/bug1738367.c: new, added

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

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

index 9db5c08d7b7e36015ef79b45d7b8c1cb8b493524..09a5f257e58a21ee42f0041fded4d802ea3b9be2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-06-16 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/SDCCast.c (decorateType),
+       * src/SDCCicode.c (geniCodeConditional): moved optimization for '?' from
+         iCode to ast level to fix bug 1738367
+       * support/regression/tests/bug1738367.c: new, added
+
 2007-06-15 Raphael Neider <rneider AT web.de>
 
        * src/pic16/devices.inc,
index 26888cd94001bc32b9686241bf466d0ea0cba743..0e49a71724635789fc75ae6e63b930b7f2d08297 100644 (file)
@@ -4369,6 +4369,27 @@ decorateType (ast * tree, RESULT_TYPE resultType)
       /* the type is value of the colon operator (on the right) */
       assert (IS_COLON_OP (tree->right));
 
+      if (IS_AST_LIT_VALUE (tree->right->left) && IS_AST_LIT_VALUE (tree->right->right))
+        {
+          double valTrue = AST_LIT_VALUE (tree->right->left);
+          double valFalse = AST_LIT_VALUE (tree->right->right);
+
+          if ((valTrue == 1) && (valFalse == 0) &&
+              ((resultType == RESULT_TYPE_IFX) || (resultType == RESULT_TYPE_BIT)))
+            {
+              /* assign cond to result */
+              return decorateType (tree->left, resultTypeProp);
+            }
+          else if ((valTrue == 0) && (valFalse == 1))
+            {
+              /* assign !cond to result */
+              tree->opval.op = '!';
+              tree->decorated = 0;
+              tree->right = NULL;
+              return decorateType (tree, resultTypeProp);
+            }
+        }
+
       /* if they are equal then replace the tree */
       if (!astHasVolatile (tree->right) &&
           isAstEqual (tree->right->left, tree->right->right))
index 601a20eeffec7823caf36b05f121db43dd641b82..2c0b61eab1d9943fa53dd57be9171ea27749e97b 100644 (file)
@@ -3147,33 +3147,6 @@ geniCodeConditional (ast * tree,int lvl)
   operand *result = newiTempOperand (tree->right->ftype, 0);
   operand *opTrue, *opFalse;
 
-  if (IS_AST_LIT_VALUE (astTrue) && IS_AST_LIT_VALUE (astFalse))
-    {
-      double valTrue = AST_LIT_VALUE (astTrue);
-      double valFalse = AST_LIT_VALUE (astFalse);
-
-      if (IS_BIT (operandType (result)))
-        {
-          if ((valTrue != 0) && (valFalse == 0))
-            {
-              /* assign cond to result */
-              geniCodeAssign (result, geniCodeRValue (cond, FALSE), 0, 0);
-              return result;
-            }
-          else if ((valTrue == 0) && (valFalse != 0))
-            {
-              /* assign !cond to result */
-              result = geniCodeUnary (geniCodeRValue (cond, FALSE), '!');
-              return result;
-            }
-          else
-            {
-              /* they have the same boolean value, make them equal */
-              astFalse = astTrue;
-            }
-        }
-    }
-
   ic = newiCodeCondition (geniCodeRValue (cond, FALSE), NULL, falseLabel);
   ADDTOCHAIN (ic);
 
diff --git a/support/regression/tests/bug1738367.c b/support/regression/tests/bug1738367.c
new file mode 100644 (file)
index 0000000..a96297a
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+   bug1738367.c
+*/
+
+#include <testfwk.h>
+#include <stdbool.h>
+
+bool Ternary(unsigned char status)
+{
+       return (status == 0) ? 0 : 1;
+}
+
+void
+testBug(void)
+{
+       ASSERT(!Ternary(0x00));
+       ASSERT( Ternary(0x10));
+}