[gcc r11-3368] c++: Ignore __sanitizer_ptr_{sub, cmp} builtin calls during constant expression evaluation [PR97145]
Jakub Jelinek
jakub@gcc.gnu.org
Tue Sep 22 19:08:12 GMT 2020
https://gcc.gnu.org/g:bc13106e0414b86af8f6878e7681e6a959921b9e
commit r11-3368-gbc13106e0414b86af8f6878e7681e6a959921b9e
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Sep 22 21:06:32 2020 +0200
c++: Ignore __sanitizer_ptr_{sub,cmp} builtin calls during constant expression evaluation [PR97145]
These two builtin calls are added already during parsing before pointer
subtractions or comparisons, normally they perform runtime verification
of whether the pointers point to the same object or different objects,
but during constant expressione valuation we don't really need those
builtins for anything.
2020-09-22 Jakub Jelinek <jakub@redhat.com>
PR c++/97145
* constexpr.c (cxx_eval_builtin_function_call): Return void_node for
calls to __sanitize_ptr_{sub,cmp} builtins.
* g++.dg/asan/pr97145.C: New test.
Diff:
---
gcc/cp/constexpr.c | 6 ++++++
gcc/testsuite/g++.dg/asan/pr97145.C | 7 +++++++
2 files changed, 13 insertions(+)
diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 72fbdab06c5..dacce58fcff 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1355,6 +1355,12 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
case BUILT_IN_STRSTR:
strops = 2;
strret = 1;
+ break;
+ case BUILT_IN_ASAN_POINTER_COMPARE:
+ case BUILT_IN_ASAN_POINTER_SUBTRACT:
+ /* These builtins shall be ignored during constant expression
+ evaluation. */
+ return void_node;
default:
break;
}
diff --git a/gcc/testsuite/g++.dg/asan/pr97145.C b/gcc/testsuite/g++.dg/asan/pr97145.C
new file mode 100644
index 00000000000..993c8a5dfa7
--- /dev/null
+++ b/gcc/testsuite/g++.dg/asan/pr97145.C
@@ -0,0 +1,7 @@
+// PR c++/97145
+// { dg-do compile { target c++11 } }
+// { dg-options "-fsanitize=address,pointer-subtract,pointer-compare" }
+
+constexpr char *a = nullptr;
+constexpr auto b = a - a;
+constexpr auto c = a < a;
More information about the Gcc-cvs
mailing list