re PR sanitizer/80932 (UBSAN: false positive as a result of distribution: c1*(c2...
authorMarek Polacek <polacek@redhat.com>
Wed, 7 Jun 2017 11:19:40 +0000 (11:19 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 7 Jun 2017 11:19:40 +0000 (11:19 +0000)
PR sanitizer/80932
* fold-const.c (extract_muldiv_1) <case MINUS_EXPR>: Add
TYPE_OVERFLOW_WRAPS check.

* c-c++-common/ubsan/pr80932.c: New test.

From-SVN: r248961

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr80932.c [new file with mode: 0644]

index 8198e0c88d66cd993c1bf89a6a50dd5e009894f2..fa94c6fa46ac3c1f93cb37bff576360c57946c2e 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-07  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/80932
+       * fold-const.c (extract_muldiv_1) <case MINUS_EXPR>: Add
+       TYPE_OVERFLOW_WRAPS check. 
+
 2017-06-07  Bin Cheng  <bin.cheng@arm.com>
 
        * tree-vect-loop-manip.c (vect_do_peeling): Don't skip vector loop
index b0d03c9aaa3a70f12d702acc6672490a28ba3e03..f3975c7391f6f570beafe5f4bc2ed3db4ce67369 100644 (file)
@@ -6178,6 +6178,7 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type,
       t1 = extract_muldiv (op0, c, code, wide_type, &sub_strict_overflow_p);
       t2 = extract_muldiv (op1, c, code, wide_type, &sub_strict_overflow_p);
       if (t1 != 0 && t2 != 0
+         && TYPE_OVERFLOW_WRAPS (ctype)
          && (code == MULT_EXPR
              /* If not multiplication, we can only do this if both operands
                 are divisible by c.  */
index 38b22ee3dc001dce4ecd5fc96ad9f7a571881abd..990e10ac327993629dd00a04b788723586daf6bd 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-07  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/80932
+       * c-c++-common/ubsan/pr80932.c: New test.
+
 2017-06-07  Bin Cheng  <bin.cheng@arm.com>
 
        * gcc.target/i386/l_fma_double_1.c: Adjust test strings.
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr80932.c b/gcc/testsuite/c-c++-common/ubsan/pr80932.c
new file mode 100644 (file)
index 0000000..a833712
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR sanitizer/80932 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=undefined -fsanitize-undefined-trap-on-error" } */
+
+int x = 1;
+
+long int
+foo (void)
+{
+  return ((long) (13801962912760474560ULL * x) - (long) (15334142073106273231ULL * x)) * -6;
+}
+
+int
+main ()
+{
+  foo ();
+}