OSDN Git Service

PR middle-end/19100
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 5 Jan 2005 17:27:26 +0000 (17:27 +0000)
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 5 Jan 2005 17:27:26 +0000 (17:27 +0000)
* c-common.c: Include real.h.
(c_common_truthvalue_conversion): Avoid destructively modifying expr.
Correctly handle TREE_CONSTANT_OVERFLOW for INTEGER_CST.
Correctly handle TREE_CONSTANT_OVERFLOW and NaNs for REAL_CST.
* Makefile.in (c-common.o): Update dependencies.

* gcc.dg/conv-3.c: New test case.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@92957 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/conv-3.c [new file with mode: 0644]

index 418665c..7589a23 100644 (file)
@@ -1,3 +1,12 @@
+2005-01-05  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/19100
+       * c-common.c: Include real.h.
+       (c_common_truthvalue_conversion): Avoid destructively modifying expr.
+       Correctly handle TREE_CONSTANT_OVERFLOW for INTEGER_CST.
+       Correctly handle TREE_CONSTANT_OVERFLOW and NaNs for REAL_CST.
+       * Makefile.in (c-common.o): Update dependencies.
+
 2005-01-05  Joseph S. Myers  <joseph@codesourcery.com>
 
        * c-parse.in (asm_string): Add trailing semicolon.
index b4c6349..bb81a6f 100644 (file)
@@ -46,6 +46,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include "hashtab.h"
 #include "tree-mudflap.h"
 #include "opts.h"
+#include "real.h"
 
 cpp_reader *parse_in;          /* Declared in c-pragma.h.  */
 
@@ -2326,17 +2327,24 @@ c_common_truthvalue_conversion (tree expr)
     case TRUTH_OR_EXPR:
     case TRUTH_XOR_EXPR:
     case TRUTH_NOT_EXPR:
-      TREE_TYPE (expr) = truthvalue_type_node;
+      if (TREE_TYPE (expr) != truthvalue_type_node)
+       return build2 (TREE_CODE (expr), truthvalue_type_node,
+                      TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1));
       return expr;
 
     case ERROR_MARK:
       return expr;
 
     case INTEGER_CST:
-      return integer_zerop (expr) ? truthvalue_false_node : truthvalue_true_node;
+      /* Avoid integer_zerop to ignore TREE_CONSTANT_OVERFLOW.  */
+      return (TREE_INT_CST_LOW (expr) != 0 || TREE_INT_CST_HIGH (expr) != 0)
+            ? truthvalue_true_node
+            : truthvalue_false_node;
 
     case REAL_CST:
-      return real_zerop (expr) ? truthvalue_false_node : truthvalue_true_node;
+      return real_compare (NE_EXPR, &TREE_REAL_CST (expr), &dconst0)
+            ? truthvalue_true_node
+            : truthvalue_false_node;
 
     case ADDR_EXPR:
       {
index dfc3aa5..e2ef31b 100644 (file)
@@ -1,3 +1,8 @@
+2005-01-05  Roger Sayle  <roger@eyesopen.com>
+
+       PR middle-end/19100
+       * gcc.dg/conv-3.c: New test case.
+
 2005-01-05  Joseph S. Myers  <joseph@codesourcery.com>
 
        * gcc.dg/asm-wide-1.c: New test.
diff --git a/gcc/testsuite/gcc.dg/conv-3.c b/gcc/testsuite/gcc.dg/conv-3.c
new file mode 100644 (file)
index 0000000..3b4f430
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR middle-end/19100 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+void abort (void);
+
+int test (int v)
+{
+  return ((signed char) (v ? 0x100 : 0)) ? 17 : 18;
+}
+
+int main()
+{
+  if (test (2) != 18)
+    abort ();
+  return 0;
+}
+