aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-02-17 09:51:38 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-02-17 09:51:38 +0000
commit5bf69d74abbf3b0971b9dae37b804ff685e7298c (patch)
tree6eb599938beefc3cd66ca5dcf874dab6c0fe890f /gcc
parent6a011df26ef12e31343fcb2ce4f47fb74be34f71 (diff)
downloadgcc-5bf69d74abbf3b0971b9dae37b804ff685e7298c.zip
gcc-5bf69d74abbf3b0971b9dae37b804ff685e7298c.tar.gz
gcc-5bf69d74abbf3b0971b9dae37b804ff685e7298c.tar.bz2
re PR middle-end/79536 (ICE in fold_binary_loc, at fold-const.c:9060)
PR middle-end/79536 * fold-const.c (fold_negate_expr_1): Renamed from fold_negate_expr. (fold_negate_expr): New wrapper. * gcc.dg/torture/pr79536.c: New test. From-SVN: r245526
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c34
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/torture/pr79536.c10
4 files changed, 45 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index dd08b7d..b7d0d8e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-02-17 Marek Polacek <polacek@redhat.com>
+
+ PR middle-end/79536
+ * fold-const.c (fold_negate_expr_1): Renamed from fold_negate_expr.
+ (fold_negate_expr): New wrapper.
+
2017-02-16 Sandra Loosemore <sandra@codesourcery.com>
* doc/invoke.texi (C++ Dialect Options) [-Wno-non-template-friend]:
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index a8bb8af..ad4770b 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -139,6 +139,7 @@ static tree fold_relational_const (enum tree_code, tree, tree, tree);
static tree fold_convert_const (enum tree_code, tree, tree);
static tree fold_view_convert_expr (tree, tree);
static bool vec_cst_ctor_to_array (tree, tree *);
+static tree fold_negate_expr (location_t, tree);
/* Return EXPR_LOCATION of T if it is not UNKNOWN_LOCATION.
@@ -522,7 +523,7 @@ negate_expr_p (tree t)
returned. */
static tree
-fold_negate_expr (location_t loc, tree t)
+fold_negate_expr_1 (location_t loc, tree t)
{
tree type = TREE_TYPE (t);
tree tem;
@@ -533,7 +534,7 @@ fold_negate_expr (location_t loc, tree t)
case BIT_NOT_EXPR:
if (INTEGRAL_TYPE_P (type))
return fold_build2_loc (loc, PLUS_EXPR, type, TREE_OPERAND (t, 0),
- build_one_cst (type));
+ build_one_cst (type));
break;
case INTEGER_CST:
@@ -581,14 +582,14 @@ fold_negate_expr (location_t loc, tree t)
case COMPLEX_EXPR:
if (negate_expr_p (t))
return fold_build2_loc (loc, COMPLEX_EXPR, type,
- fold_negate_expr (loc, TREE_OPERAND (t, 0)),
- fold_negate_expr (loc, TREE_OPERAND (t, 1)));
+ fold_negate_expr (loc, TREE_OPERAND (t, 0)),
+ fold_negate_expr (loc, TREE_OPERAND (t, 1)));
break;
case CONJ_EXPR:
if (negate_expr_p (t))
return fold_build1_loc (loc, CONJ_EXPR, type,
- fold_negate_expr (loc, TREE_OPERAND (t, 0)));
+ fold_negate_expr (loc, TREE_OPERAND (t, 0)));
break;
case NEGATE_EXPR:
@@ -605,7 +606,7 @@ fold_negate_expr (location_t loc, tree t)
{
tem = negate_expr (TREE_OPERAND (t, 1));
return fold_build2_loc (loc, MINUS_EXPR, type,
- tem, TREE_OPERAND (t, 0));
+ tem, TREE_OPERAND (t, 0));
}
/* -(A + B) -> (-A) - B. */
@@ -613,7 +614,7 @@ fold_negate_expr (location_t loc, tree t)
{
tem = negate_expr (TREE_OPERAND (t, 0));
return fold_build2_loc (loc, MINUS_EXPR, type,
- tem, TREE_OPERAND (t, 1));
+ tem, TREE_OPERAND (t, 1));
}
}
break;
@@ -623,7 +624,7 @@ fold_negate_expr (location_t loc, tree t)
if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
&& !HONOR_SIGNED_ZEROS (element_mode (type)))
return fold_build2_loc (loc, MINUS_EXPR, type,
- TREE_OPERAND (t, 1), TREE_OPERAND (t, 0));
+ TREE_OPERAND (t, 1), TREE_OPERAND (t, 0));
break;
case MULT_EXPR:
@@ -638,11 +639,11 @@ fold_negate_expr (location_t loc, tree t)
tem = TREE_OPERAND (t, 1);
if (negate_expr_p (tem))
return fold_build2_loc (loc, TREE_CODE (t), type,
- TREE_OPERAND (t, 0), negate_expr (tem));
+ TREE_OPERAND (t, 0), negate_expr (tem));
tem = TREE_OPERAND (t, 0);
if (negate_expr_p (tem))
return fold_build2_loc (loc, TREE_CODE (t), type,
- negate_expr (tem), TREE_OPERAND (t, 1));
+ negate_expr (tem), TREE_OPERAND (t, 1));
}
break;
@@ -715,6 +716,19 @@ fold_negate_expr (location_t loc, tree t)
return NULL_TREE;
}
+/* A wrapper for fold_negate_expr_1. */
+
+static tree
+fold_negate_expr (location_t loc, tree t)
+{
+ tree type = TREE_TYPE (t);
+ STRIP_SIGN_NOPS (t);
+ tree tem = fold_negate_expr_1 (loc, t);
+ if (tem == NULL_TREE)
+ return NULL_TREE;
+ return fold_convert_loc (loc, type, tem);
+}
+
/* Like fold_negate_expr, but return a NEGATE_EXPR tree, if T can not be
negated in a simpler way. Also allow for T to be NULL_TREE, in which case
return NULL_TREE. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index f7b64e3..abd9308 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-02-17 Marek Polacek <polacek@redhat.com>
+
+ PR middle-end/79536
+ * gcc.dg/torture/pr79536.c: New test.
+
2017-02-16 Alan Modra <amodra@gmail.com>
* gcc.c-torture/execute/pr79286.c: New.
diff --git a/gcc/testsuite/gcc.dg/torture/pr79536.c b/gcc/testsuite/gcc.dg/torture/pr79536.c
new file mode 100644
index 0000000..6f05ca7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr79536.c
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+
+typedef int A;
+int
+fn1 (A x, A y)
+{
+ if ((x + (x - y) * 1i) != -(-x + (y - x) * 1i))
+ return 1;
+ return 0;
+}