re PR sanitizer/88901 (ICE when using -fsanitize=pointer-compare)
authorJakub Jelinek <jakub@redhat.com>
Mon, 21 Jan 2019 19:53:04 +0000 (20:53 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 21 Jan 2019 19:53:04 +0000 (20:53 +0100)
PR sanitizer/88901
* typeck.c (cp_build_binary_op): Don't instrument
SANITIZE_POINTER_COMPARE if processing_template_decl.
(pointer_diff): Similarly for SANITIZE_POINTER_SUBTRACT.

* g++.dg/asan/pr88901.C: New test.

From-SVN: r268122

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/asan/pr88901.C [new file with mode: 0644]

index 4292930..e5ce94c 100644 (file)
@@ -1,3 +1,10 @@
+2019-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/88901
+       * typeck.c (cp_build_binary_op): Don't instrument
+       SANITIZE_POINTER_COMPARE if processing_template_decl.
+       (pointer_diff): Similarly for SANITIZE_POINTER_SUBTRACT.
+
 2019-01-18  Jason Merrill  <jason@redhat.com>
 
        PR c++/88875 - error with explicit list constructor.
index 47e407d..ec722a3 100644 (file)
@@ -5233,6 +5233,7 @@ cp_build_binary_op (const op_location_t &location,
        }
 
       if ((code0 == POINTER_TYPE || code1 == POINTER_TYPE)
+         && !processing_template_decl
          && sanitize_flags_p (SANITIZE_POINTER_COMPARE))
        {
          op0 = save_expr (op0);
@@ -5650,7 +5651,8 @@ pointer_diff (location_t loc, tree op0, tree op1, tree ptrtype,
   else
     inttype = restype;
 
-  if (sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
+  if (!processing_template_decl
+      && sanitize_flags_p (SANITIZE_POINTER_SUBTRACT))
     {
       op0 = save_expr (op0);
       op1 = save_expr (op1);
index 6a48321..ba5285f 100644 (file)
@@ -1,3 +1,8 @@
+2019-01-21  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/88901
+       * g++.dg/asan/pr88901.C: New test.
+
 2019-01-21  Tamar Christina  <tamar.christina@arm.com>
 
        * g++.dg/vect/simd-clone-7.cc: Fix assembler scan.
diff --git a/gcc/testsuite/g++.dg/asan/pr88901.C b/gcc/testsuite/g++.dg/asan/pr88901.C
new file mode 100644 (file)
index 0000000..fa5d949
--- /dev/null
@@ -0,0 +1,13 @@
+// PR sanitizer/88901
+// { dg-do compile }
+// { dg-options "-fsanitize=address -fsanitize=pointer-compare" }
+
+template <typename T>
+struct A {
+  void foo() {
+    auto d = [](char *x, char *y) {
+      for (char *p = x; p + sizeof(T) <= y; p += sizeof(T))
+        reinterpret_cast<T *>(p)->~T();
+    };
+  }
+};