re PR sanitizer/87837 (-O2 -fsanitize=signed-integer-overflow misses overflows on...
authorJakub Jelinek <jakub@redhat.com>
Mon, 5 Nov 2018 10:27:13 +0000 (11:27 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 5 Nov 2018 10:27:13 +0000 (11:27 +0100)
PR sanitizer/87837
* match.pd (X + Y < X): Don't optimize if TYPE_OVERFLOW_SANITIZED.

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

From-SVN: r265793

gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/pr87837.c [new file with mode: 0644]

index f1a9d11..099b540 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/87837
+       * match.pd (X + Y < X): Don't optimize if TYPE_OVERFLOW_SANITIZED.
+
 2018-11-05  Xuepeng Guo  <xuepeng.guo@intel.com>
 
        PR target/87853
index d07ceb7..d47249a 100644 (file)
@@ -1572,6 +1572,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
   (op:c (plus:c@2 @0 @1) @1)
   (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
        && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))
+       && !TYPE_OVERFLOW_SANITIZED (TREE_TYPE (@0))
        && (CONSTANT_CLASS_P (@0) || single_use (@2)))
    (op @0 { build_zero_cst (TREE_TYPE (@0)); }))))
 /* For equality, this is also true with wrapping overflow.  */
index a02831c..0bb7b76 100644 (file)
@@ -1,3 +1,8 @@
+2018-11-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/87837
+       * c-c++-common/ubsan/pr87837.c: New test.
+
 2018-11-05  Martin Liska  <mliska@suse.cz>
 
        PR c/87811
diff --git a/gcc/testsuite/c-c++-common/ubsan/pr87837.c b/gcc/testsuite/c-c++-common/ubsan/pr87837.c
new file mode 100644 (file)
index 0000000..5ee991c
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR sanitizer/87837 */
+/* { dg-do run } */
+/* { dg-options "-fsanitize=signed-integer-overflow -Wno-unused-variable" } */
+
+int
+foo (int n)
+{
+  return n + __INT_MAX__ < n;
+}
+
+int
+main ()
+{
+  volatile int a = foo (1);
+  return 0;
+}
+
+/* { dg-output "signed integer overflow: 1 \\+ 2147483647 cannot be represented in type 'int'" } */