From 90ec750dbf67872ce3076fceaf3b8df570c75c45 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Mon, 21 Mar 2005 03:30:08 +0000 Subject: [PATCH] re PR middle-end/20539 (ICE in simplify_subreg, at simplify-rtx.c:3674) PR middle-end/20539 * fold-const.c (fold_binary): Fix type mismatch between TRUTH_{AND,OR,XOR}_EXPR nodes an their operands' types. (fold_binary) : Avoid calling invert_truthvalue for non-truth-valued expressions. * c-common.c (c_common_truthvalue_conversion): Handle ERROR_MARK and FUNCTION_DECL in the main switch. : When changing the result type of these tree nodes, we also need to convert their operands to match. : Likewise. * gcc.c-torture/compile/pr13066-1.c: New test case. * gcc.c-torture/compile/pr20539-1.c: Likewise. * g++.dg/opt/pr13066-1.C: Likewise. From-SVN: r96777 --- gcc/ChangeLog | 15 +++++++++ gcc/c-common.c | 32 +++++++++++-------- gcc/fold-const.c | 14 ++++++-- gcc/testsuite/ChangeLog | 7 ++++ gcc/testsuite/g++.dg/opt/pr13066-1.C | 22 +++++++++++++ .../gcc.c-torture/compile/pr13066-1.c | 10 ++++++ .../gcc.c-torture/compile/pr20539-1.c | 10 ++++++ 7 files changed, 93 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/opt/pr13066-1.C create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr13066-1.c create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr20539-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 34e1a5ddbb2..cf4a6c92cbd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2005-03-20 Roger Sayle + + PR middle-end/20539 + * fold-const.c (fold_binary): Fix type mismatch between + TRUTH_{AND,OR,XOR}_EXPR nodes an their operands' types. + (fold_binary) : Avoid calling invert_truthvalue + for non-truth-valued expressions. + + * c-common.c (c_common_truthvalue_conversion): Handle ERROR_MARK + and FUNCTION_DECL in the main switch. + : When changing the result type of these tree nodes, + we also need to convert their operands to match. + : Likewise. + 2005-03-21 Joseph S. Myers * c-common.c (lvalue_or_else): Replace by lvalue_error; only give diff --git a/gcc/c-common.c b/gcc/c-common.c index 9c6a9d141af..a18520d9e0d 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -2327,33 +2327,33 @@ pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop) tree c_common_truthvalue_conversion (tree expr) { - if (TREE_CODE (expr) == ERROR_MARK) - return expr; - - if (TREE_CODE (expr) == FUNCTION_DECL) - expr = build_unary_op (ADDR_EXPR, expr, 0); - switch (TREE_CODE (expr)) { case EQ_EXPR: case NE_EXPR: case UNEQ_EXPR: case LTGT_EXPR: case LE_EXPR: case GE_EXPR: case LT_EXPR: case GT_EXPR: case UNLE_EXPR: case UNGE_EXPR: case UNLT_EXPR: case UNGT_EXPR: case ORDERED_EXPR: case UNORDERED_EXPR: + if (TREE_TYPE (expr) == truthvalue_type_node) + return expr; + return build2 (TREE_CODE (expr), truthvalue_type_node, + TREE_OPERAND (expr, 0), TREE_OPERAND (expr, 1)); + case TRUTH_ANDIF_EXPR: case TRUTH_ORIF_EXPR: case TRUTH_AND_EXPR: case TRUTH_OR_EXPR: case TRUTH_XOR_EXPR: - 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; + if (TREE_TYPE (expr) == truthvalue_type_node) + return expr; + return build2 (TREE_CODE (expr), truthvalue_type_node, + lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0)), + lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 1))); case TRUTH_NOT_EXPR: - if (TREE_TYPE (expr) != truthvalue_type_node) - return build1 (TREE_CODE (expr), truthvalue_type_node, - TREE_OPERAND (expr, 0)); - return expr; + if (TREE_TYPE (expr) == truthvalue_type_node) + return expr; + return build1 (TREE_CODE (expr), truthvalue_type_node, + lang_hooks.truthvalue_conversion (TREE_OPERAND (expr, 0))); case ERROR_MARK: return expr; @@ -2369,6 +2369,10 @@ c_common_truthvalue_conversion (tree expr) ? truthvalue_true_node : truthvalue_false_node; + case FUNCTION_DECL: + expr = build_unary_op (ADDR_EXPR, expr, 0); + /* Fall through. */ + case ADDR_EXPR: { if (TREE_CODE (TREE_OPERAND (expr, 0)) == FUNCTION_DECL diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bc17c1d3e9c..848b167e9b7 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7159,13 +7159,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) tem = fold (build2 (code == BIT_AND_EXPR ? TRUTH_AND_EXPR : code == BIT_IOR_EXPR ? TRUTH_OR_EXPR : TRUTH_XOR_EXPR, - type, fold_convert (boolean_type_node, arg0), + boolean_type_node, + fold_convert (boolean_type_node, arg0), fold_convert (boolean_type_node, arg1))); if (code == EQ_EXPR) tem = invert_truthvalue (tem); - return tem; + return fold_convert (type, tem); } if (TREE_CODE_CLASS (code) == tcc_comparison @@ -8717,7 +8718,14 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) return non_lvalue (fold_convert (type, arg0)); /* If the second arg is constant true, this is a logical inversion. */ if (integer_onep (arg1)) - return non_lvalue (fold_convert (type, invert_truthvalue (arg0))); + { + /* Only call invert_truthvalue if operand is a truth value. */ + if (TREE_CODE (TREE_TYPE (arg0)) != BOOLEAN_TYPE) + tem = fold (build1 (TRUTH_NOT_EXPR, TREE_TYPE (arg0), arg0)); + else + tem = invert_truthvalue (arg0); + return non_lvalue (fold_convert (type, tem)); + } /* Identical arguments cancel to zero. */ if (operand_equal_p (arg0, arg1, 0)) return omit_one_operand (type, integer_zero_node, arg0); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 7921dd4ff16..3f850f5d3e9 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2005-03-20 Roger Sayle + + PR middle-end/20539 + * gcc.c-torture/compile/pr13066-1.c: New test case. + * gcc.c-torture/compile/pr20539-1.c: Likewise. + * g++.dg/opt/pr13066-1.C: Likewise. + 2005-03-20 Joseph S. Myers * gcc.dg/bitfld-14.c, gcc.dg/enum3.c: New tests. diff --git a/gcc/testsuite/g++.dg/opt/pr13066-1.C b/gcc/testsuite/g++.dg/opt/pr13066-1.C new file mode 100644 index 00000000000..67f85345676 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr13066-1.C @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +class nsIURI; + +struct nsCOMPtr +{ + operator nsIURI*() const + { + return mRawPtr; + } + + nsIURI *mRawPtr; +}; + +void func() +{ + nsCOMPtr u1; + if (!u1 == !u1) + return; +} + diff --git a/gcc/testsuite/gcc.c-torture/compile/pr13066-1.c b/gcc/testsuite/gcc.c-torture/compile/pr13066-1.c new file mode 100644 index 00000000000..c2930f95df6 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr13066-1.c @@ -0,0 +1,10 @@ +void *g, *c; +int a, b; + +int f() +{ + if ((0 == a) != (b || g == c)) + return 1; + return 0; +} + diff --git a/gcc/testsuite/gcc.c-torture/compile/pr20539-1.c b/gcc/testsuite/gcc.c-torture/compile/pr20539-1.c new file mode 100644 index 00000000000..f67f06b8816 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr20539-1.c @@ -0,0 +1,10 @@ +char l7_en; +long long l6_data_Z_0th; +int t; +void f() +{ + if (((char )(l6_data_Z_0th>>1 & 1U)) & ((l6_data_Z_0th & 1U) + | !(((char )(l6_data_Z_0th>>35 & 15U))==14U))) + t = 0ULL; +} +