aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-05-19 15:30:54 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-05-19 15:30:54 +0000
commit33f8c0a14da482bc7884e5f663615a3d7fd08cff (patch)
tree0c42b764c20d321089046e2fa134c11df25dbbdd /gcc
parentff50231797977a56a0d256db645f1e004c6acf00 (diff)
downloadgcc-33f8c0a14da482bc7884e5f663615a3d7fd08cff.zip
gcc-33f8c0a14da482bc7884e5f663615a3d7fd08cff.tar.gz
gcc-33f8c0a14da482bc7884e5f663615a3d7fd08cff.tar.bz2
re PR sanitizer/80800 (UBSAN: yet another false positive)
PR sanitizer/80800 * fold-const.c (extract_muldiv_1) <case TRUNC_DIV_EXPR>: Add TYPE_OVERFLOW_WRAPS checks. * c-c++-common/ubsan/pr80800.c: New test. * c-c++-common/Wduplicated-branches-1.c: Adjust an expression. From-SVN: r248291
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c2
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/c-c++-common/Wduplicated-branches-1.c2
-rw-r--r--gcc/testsuite/c-c++-common/ubsan/pr80800.c25
5 files changed, 40 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c40af47..00aa02c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-19 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/80800
+ * fold-const.c (extract_muldiv_1) <case TRUNC_DIV_EXPR>: Add
+ TYPE_OVERFLOW_WRAPS checks.
+
2017-05-19 Thomas Schwinge <thomas@codesourcery.com>
* tree-core.h (enum omp_clause_default_kind): Add
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 19aa722..736552c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -6281,11 +6281,13 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
new operation. Likewise for the RHS from a MULT_EXPR. Otherwise,
do something only if the second operand is a constant. */
if (same_p
+ && TYPE_OVERFLOW_WRAPS (ctype)
&& (t1 = extract_muldiv (op0, c, code, wide_type,
strict_overflow_p)) != 0)
return fold_build2 (tcode, ctype, fold_convert (ctype, t1),
fold_convert (ctype, op1));
else if (tcode == MULT_EXPR && code == MULT_EXPR
+ && TYPE_OVERFLOW_WRAPS (ctype)
&& (t1 = extract_muldiv (op1, c, code, wide_type,
strict_overflow_p)) != 0)
return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e8e2df5..dafa034 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2017-05-19 Marek Polacek <polacek@redhat.com>
+
+ PR sanitizer/80800
+ * c-c++-common/ubsan/pr80800.c: New test.
+ * c-c++-common/Wduplicated-branches-1.c: Adjust an expression.
+
2017-05-19 Thomas Schwinge <thomas@codesourcery.com>
* c-c++-common/goacc/default-1.c: Update.
diff --git a/gcc/testsuite/c-c++-common/Wduplicated-branches-1.c b/gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
index c0b93fc..7c5062d 100644
--- a/gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
+++ b/gcc/testsuite/c-c++-common/Wduplicated-branches-1.c
@@ -89,7 +89,7 @@ f (int i, int *p)
if (i == 8) /* { dg-warning "this condition has identical branches" } */
return i * 8 * i * 8;
else
- return 8 * i * 8 * i;
+ return i * 8 * i * 8;
if (i == 9) /* { dg-warning "this condition has identical branches" } */
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr80800.c b/gcc/testsuite/c-c++-common/ubsan/pr80800.c
new file mode 100644
index 0000000..992c136
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/pr80800.c
@@ -0,0 +1,25 @@
+/* PR sanitizer/80800 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+int n = 20000;
+int z = 0;
+
+int
+fn1 (void)
+{
+ return (n * 10000 * z) * 50;
+}
+
+int
+fn2 (void)
+{
+ return (10000 * n * z) * 50;
+}
+
+int
+main ()
+{
+ fn1 ();
+ fn2 ();
+}