aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr81097.c12
4 files changed, 25 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4293a05..8210d27 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2017-06-20 Richard Biener <rguenther@suse.de>
+
+ PR middle-end/81097
+ * fold-const.c (split_tree): Fold to type before negating.
+
2017-06-20 David Malcolm <dmalcolm@redhat.com>
* diagnostic-show-locus.c
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8559b1d..379a30e 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -853,9 +853,9 @@ split_tree (location_t loc, tree in, tree type, enum tree_code code,
&& code == PLUS_EXPR)
{
/* -X - 1 is folded to ~X, undo that here. Do _not_ do this
- when IN is constant. */
- *minus_litp = build_one_cst (TREE_TYPE (in));
- var = negate_expr (TREE_OPERAND (in, 0));
+ when IN is constant. Convert to TYPE before negating. */
+ *minus_litp = build_one_cst (type);
+ var = negate_expr (fold_convert_loc (loc, type, TREE_OPERAND (in, 0)));
}
else
var = in;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 9077fe1..28c97de 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2017-06-20 Richard Biener <rguenther@suse.de>
+ PR middle-end/81097
+ * c-c++-common/ubsan/pr81097.c: New testcase.
+
+2017-06-20 Richard Biener <rguenther@suse.de>
+
* gcc.dg/vect/pr65947-9.c: Adjust.
2017-06-20 Prakhar Bahuguna <prakhar.bahuguna@arm.com>
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr81097.c b/gcc/testsuite/c-c++-common/ubsan/pr81097.c
new file mode 100644
index 0000000..cd323ea
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr81097.c
@@ -0,0 +1,12 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+unsigned int a = 3309568;
+unsigned int b = -1204857327;
+short c = -10871;
+short x;
+int main()
+{
+ x = ((short)(~a) | ~c) + ((short)(~b) | ~c);
+ return 0;
+}