public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
@ 2020-09-21 11:55 chfast at gmail dot com
2020-09-21 12:09 ` [Bug c++/97145] " rguenth at gcc dot gnu.org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: chfast at gmail dot com @ 2020-09-21 11:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
Bug ID: 97145
Summary: Sanitizer pointer-subtract breaks constexpr functions
subtracting pointers
Product: gcc
Version: 10.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: chfast at gmail dot com
Target Milestone: ---
Having a constexpr function that subtracts two pointers does not work in
constexpr context when building with -fsanitize=address,pointer-subtract.
GCC version: starts with 8.1 where pointer-subtract was introduced, up to
trunk.
Minimal code:
constexpr char* a = nullptr;
constexpr auto d = a - a;
<source>:3:22: error: '__builtin___sanitizer_ptr_sub(0, 0)' is not a constant
expression
3 | constexpr auto d = a - a;
| ~~^~~
https://godbolt.org/z/qWxT9v
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/97145] Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
@ 2020-09-21 12:09 ` rguenth at gcc dot gnu.org
2020-09-21 12:12 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-09-21 12:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |rejects-valid
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Maybe we shouldn't sanitize constexpr stuff?
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/97145] Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
2020-09-21 12:09 ` [Bug c++/97145] " rguenth at gcc dot gnu.org
@ 2020-09-21 12:12 ` jakub at gcc dot gnu.org
2020-09-21 15:47 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-21 12:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
No, we just need to ignore the sanitization builtins during constant
evaluation.
We already do for some of them.
We can ignore sanitization only in consteval functions, constexpr just means
that the compiler attempts to evaluate it at compile time if called in constant
expression contexts or with constant arguments, but it is still emitted out of
line and can be called at runtime.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/97145] Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
2020-09-21 12:09 ` [Bug c++/97145] " rguenth at gcc dot gnu.org
2020-09-21 12:12 ` jakub at gcc dot gnu.org
@ 2020-09-21 15:47 ` jakub at gcc dot gnu.org
2020-09-22 19:08 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-21 15:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2020-09-21
Ever confirmed|0 |1
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49251
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49251&action=edit
gcc11-pr97145.patch
Untested fix.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/97145] Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
` (2 preceding siblings ...)
2020-09-21 15:47 ` jakub at gcc dot gnu.org
@ 2020-09-22 19:08 ` cvs-commit at gcc dot gnu.org
2020-10-05 8:24 ` cvs-commit at gcc dot gnu.org
2021-02-23 17:34 ` chfast at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-22 19:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
--- Comment #4 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/97145] Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
` (3 preceding siblings ...)
2020-09-22 19:08 ` cvs-commit at gcc dot gnu.org
@ 2020-10-05 8:24 ` cvs-commit at gcc dot gnu.org
2021-02-23 17:34 ` chfast at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-10-05 8:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:3f56563cf84f97ef271ef0f949a571c13cdd06e2
commit r10-8850-g3f56563cf84f97ef271ef0f949a571c13cdd06e2
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.
(cherry picked from commit bc13106e0414b86af8f6878e7681e6a959921b9e)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/97145] Sanitizer pointer-subtract breaks constexpr functions subtracting pointers
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
` (4 preceding siblings ...)
2020-10-05 8:24 ` cvs-commit at gcc dot gnu.org
@ 2021-02-23 17:34 ` chfast at gmail dot com
5 siblings, 0 replies; 7+ messages in thread
From: chfast at gmail dot com @ 2021-02-23 17:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97145
Paweł Bylica <chfast at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution|--- |FIXED
--- Comment #6 from Paweł Bylica <chfast at gmail dot com> ---
This looks to be fixed in trunk. Thanks.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-02-23 17:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 11:55 [Bug c++/97145] New: Sanitizer pointer-subtract breaks constexpr functions subtracting pointers chfast at gmail dot com
2020-09-21 12:09 ` [Bug c++/97145] " rguenth at gcc dot gnu.org
2020-09-21 12:12 ` jakub at gcc dot gnu.org
2020-09-21 15:47 ` jakub at gcc dot gnu.org
2020-09-22 19:08 ` cvs-commit at gcc dot gnu.org
2020-10-05 8:24 ` cvs-commit at gcc dot gnu.org
2021-02-23 17:34 ` chfast at gmail dot com
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).