* 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
+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,
/* 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))
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);
--- /dev/null
+/*
+ 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));
+}