From 010c4d9c147b2bf50580f322fbe94fbde1206971 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Wed, 5 Jan 2005 17:27:26 +0000 Subject: [PATCH] re PR middle-end/19100 (Wrong code for ?-operator with casted ?-operator predicat) 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. * gcc.dg/conv-3.c: New test case. From-SVN: r92957 --- gcc/ChangeLog | 9 +++++++++ gcc/c-common.c | 14 +++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/conv-3.c | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/conv-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 418665c245b..7589a23c83c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2005-01-05 Roger Sayle + + 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 * c-parse.in (asm_string): Add trailing semicolon. diff --git a/gcc/c-common.c b/gcc/c-common.c index b4c6349cbd8..bb81a6f281b 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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: { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dfc3aa58c2d..e2ef31bb0bb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-01-05 Roger Sayle + + PR middle-end/19100 + * gcc.dg/conv-3.c: New test case. + 2005-01-05 Joseph S. Myers * 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 index 00000000000..3b4f4309d9d --- /dev/null +++ b/gcc/testsuite/gcc.dg/conv-3.c @@ -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; +} + -- 2.30.2