* [PATCH] c++: Ignore __sanitizer_ptr_{sub,cmp} builtin calls during constant expression evaluation [PR97145]
@ 2020-09-22 7:48 Jakub Jelinek
2020-09-22 13:44 ` Jason Merrill
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-09-22 7:48 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
Hi!
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.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
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.
--- gcc/cp/constexpr.c.jj 2020-09-07 16:58:53.342195330 +0200
+++ gcc/cp/constexpr.c 2020-09-21 23:50:39.909211245 +0200
@@ -1355,6 +1355,12 @@ cxx_eval_builtin_function_call (const co
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;
}
--- gcc/testsuite/g++.dg/asan/pr97145.C.jj 2020-09-21 17:37:50.408562876 +0200
+++ gcc/testsuite/g++.dg/asan/pr97145.C 2020-09-21 17:38:26.961031023 +0200
@@ -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;
Jakub
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] c++: Ignore __sanitizer_ptr_{sub,cmp} builtin calls during constant expression evaluation [PR97145]
2020-09-22 7:48 [PATCH] c++: Ignore __sanitizer_ptr_{sub,cmp} builtin calls during constant expression evaluation [PR97145] Jakub Jelinek
@ 2020-09-22 13:44 ` Jason Merrill
0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2020-09-22 13:44 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches
On 9/22/20 3:48 AM, Jakub Jelinek wrote:
> Hi!
>
> 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.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
OK.
> 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.
>
> --- gcc/cp/constexpr.c.jj 2020-09-07 16:58:53.342195330 +0200
> +++ gcc/cp/constexpr.c 2020-09-21 23:50:39.909211245 +0200
> @@ -1355,6 +1355,12 @@ cxx_eval_builtin_function_call (const co
> 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;
> }
> --- gcc/testsuite/g++.dg/asan/pr97145.C.jj 2020-09-21 17:37:50.408562876 +0200
> +++ gcc/testsuite/g++.dg/asan/pr97145.C 2020-09-21 17:38:26.961031023 +0200
> @@ -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;
>
> Jakub
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-09-22 13:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-22 7:48 [PATCH] c++: Ignore __sanitizer_ptr_{sub,cmp} builtin calls during constant expression evaluation [PR97145] Jakub Jelinek
2020-09-22 13:44 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).