From 52e6797044fc8e5281d862339f4c27988017557d Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 21 Jan 2019 20:53:04 +0100 Subject: [PATCH] re PR sanitizer/88901 (ICE when using -fsanitize=pointer-compare) 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 | 7 +++++++ gcc/cp/typeck.c | 4 +++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/asan/pr88901.C | 13 +++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/asan/pr88901.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4292930daf3..e5ce94c75e8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2019-01-21 Jakub Jelinek + + 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 PR c++/88875 - error with explicit list constructor. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 47e407d1faa..ec722a36035 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a483214c55..ba5285fc710 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-01-21 Jakub Jelinek + + PR sanitizer/88901 + * g++.dg/asan/pr88901.C: New test. + 2019-01-21 Tamar Christina * 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 index 00000000000..fa5d949fe3a --- /dev/null +++ b/gcc/testsuite/g++.dg/asan/pr88901.C @@ -0,0 +1,13 @@ +// PR sanitizer/88901 +// { dg-do compile } +// { dg-options "-fsanitize=address -fsanitize=pointer-compare" } + +template +struct A { + void foo() { + auto d = [](char *x, char *y) { + for (char *p = x; p + sizeof(T) <= y; p += sizeof(T)) + reinterpret_cast(p)->~T(); + }; + } +}; -- 2.30.2