tree-chkp.c (chkp_compute_bounds_for_assignment): Handle POINTER_DIFF_EXPR.
authorJakub Jelinek <jakub@redhat.com>
Sat, 2 Dec 2017 07:58:05 +0000 (08:58 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 2 Dec 2017 07:58:05 +0000 (08:58 +0100)
* tree-chkp.c (chkp_compute_bounds_for_assignment): Handle
POINTER_DIFF_EXPR.

* gcc.target/i386/mpx/pointer-diff-1.c: New test.

From-SVN: r255355

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/i386/mpx/pointer-diff-1.c [new file with mode: 0644]
gcc/tree-chkp.c

index f1ce291..40ef3d0 100644 (file)
@@ -1,5 +1,8 @@
 2017-12-02  Jakub Jelinek  <jakub@redhat.com>
 
+       * tree-chkp.c (chkp_compute_bounds_for_assignment): Handle
+       POINTER_DIFF_EXPR.
+
        PR c++/81212
        * tree-cfg.c (pass_warn_function_return::execute): Handle
        __builtin_ubsan_handle_missing_return like __builtin_unreachable
index eedf1a8..c66f314 100644 (file)
@@ -1,5 +1,7 @@
 2017-12-02  Jakub Jelinek  <jakub@redhat.com>
 
+       * gcc.target/i386/mpx/pointer-diff-1.c: New test.
+
        PR c++/81212
        * g++.dg/ubsan/pr81212.C: New test.
        * g++.dg/ubsan/return-1.C: Add -Wno-return-type to dg-options.
diff --git a/gcc/testsuite/gcc.target/i386/mpx/pointer-diff-1.c b/gcc/testsuite/gcc.target/i386/mpx/pointer-diff-1.c
new file mode 100644 (file)
index 0000000..6579919
--- /dev/null
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -mmpx -fcheck-pointer-bounds" } */
+
+char *
+foo (char *p, char *q)
+{
+  return (char *) (p - q);     /* { dg-bogus "pointer bounds were lost due to unexpected expression" } */
+}
index 6d24355..8296786 100644 (file)
@@ -2762,6 +2762,7 @@ chkp_compute_bounds_for_assignment (tree node, gimple *assign)
     case FLOAT_EXPR:
     case REALPART_EXPR:
     case IMAGPART_EXPR:
+    case POINTER_DIFF_EXPR:
       /* No valid bounds may be produced by these exprs.  */
       bounds = chkp_get_invalid_op_bounds ();
       break;