public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/110936] New: if constexpr: member function pointers cannot be checked with ubsan
@ 2023-08-07 15:52 jeanmichael.celerier at gmail dot com
2023-09-01 1:54 ` [Bug c++/110936] " johelegp at gmail dot com
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: jeanmichael.celerier at gmail dot com @ 2023-08-07 15:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110936
Bug ID: 110936
Summary: if constexpr: member function pointers cannot be
checked with ubsan
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: jeanmichael.celerier at gmail dot com
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
Target Milestone: ---
Repro:
struct foo {
void bar() { }
};
void process(auto f) {
if constexpr(&decltype(f)::bar);
}
int main() {
process(foo{});
}
Works fine in normal compilation mode as expected, however with
-fsanitize=undefined it does not work: https://gcc.godbolt.org/z/9qvz89na8
<source>:6:3: error: '(foo::bar != 0)' is not a constant expression
if constexpr(&decltype(f)::bar);
I tested as far back as g++ 7.1 and it did not work either back then, and prior
versions did not have if constexpr.
It would be less of a problem if there was any way to do #if
defined(__SANITIZE_UNDEFINED__) or something similar but while asan has it,
ubsan does not seem to have any macro to enable detection of it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110936] if constexpr: member function pointers cannot be checked with ubsan
2023-08-07 15:52 [Bug sanitizer/110936] New: if constexpr: member function pointers cannot be checked with ubsan jeanmichael.celerier at gmail dot com
@ 2023-09-01 1:54 ` johelegp at gmail dot com
2023-09-01 2:21 ` johelegp at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: johelegp at gmail dot com @ 2023-09-01 1:54 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110936
--- Comment #1 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
This should block BUG101603.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110936] if constexpr: member function pointers cannot be checked with ubsan
2023-08-07 15:52 [Bug sanitizer/110936] New: if constexpr: member function pointers cannot be checked with ubsan jeanmichael.celerier at gmail dot com
2023-09-01 1:54 ` [Bug c++/110936] " johelegp at gmail dot com
@ 2023-09-01 2:21 ` johelegp at gmail dot com
2023-11-09 1:42 ` nathanieloshead at gmail dot com
2023-11-09 1:44 ` johelegp at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: johelegp at gmail dot com @ 2023-09-01 2:21 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110936
--- Comment #2 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
FWIW, it seems that you can use
<https://quuxplusone.github.io/blog/2022/01/04/test-constexpr-friendliness/>
to test the validity during constant evaluation.
It seems that an invalid constant expression implies a `false` result.
So I guard the check with a validity check:
<https://compiler-explorer.com/z/had59d6nv>.
```C++
#include <type_traits>
template<auto F> concept is_constant = requires { typename
std::integral_constant<int, (F(), 0)>; };
template<auto l, auto r>
constexpr bool implements() {
using R = decltype(r);
if constexpr (requires { static_cast<R>(l); })
#if !defined(__GNUC__) || defined(__clang__)
return static_cast<R>(l) != r;
#else // Workaround <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962>.
return !is_constant<[]() { return static_cast<R>(l) != r; }> ||
static_cast<R>(l) != r;
#endif
return false;
}
struct B { void f(); };
struct D0 : B { };
struct D1 : B { void f(); };
struct D2 : B { void f() const; };
// struct D3 : B { int f(); void f() const; };
static_assert(!implements<&D0::f, &B::f>());
static_assert(implements<&D1::f, &B::f>());
static_assert(!implements<&D2::f, &B::f>());
// static_assert(!implements<&D3::f, &B::f>());
```
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110936] if constexpr: member function pointers cannot be checked with ubsan
2023-08-07 15:52 [Bug sanitizer/110936] New: if constexpr: member function pointers cannot be checked with ubsan jeanmichael.celerier at gmail dot com
2023-09-01 1:54 ` [Bug c++/110936] " johelegp at gmail dot com
2023-09-01 2:21 ` johelegp at gmail dot com
@ 2023-11-09 1:42 ` nathanieloshead at gmail dot com
2023-11-09 1:44 ` johelegp at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: nathanieloshead at gmail dot com @ 2023-11-09 1:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110936
Nathaniel Shead <nathanieloshead at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |nathanieloshead at gmail dot com
--- Comment #3 from Nathaniel Shead <nathanieloshead at gmail dot com> ---
More generally this appears to be caused by '-fno-delete-null-pointer-checks'
causing constant folding not to occur. Minimised example:
struct foo { void bar() { } };
constexpr bool b = &foo::bar;
https://gcc.godbolt.org/z/x7csTzjfa
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/110936] if constexpr: member function pointers cannot be checked with ubsan
2023-08-07 15:52 [Bug sanitizer/110936] New: if constexpr: member function pointers cannot be checked with ubsan jeanmichael.celerier at gmail dot com
` (2 preceding siblings ...)
2023-11-09 1:42 ` nathanieloshead at gmail dot com
@ 2023-11-09 1:44 ` johelegp at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: johelegp at gmail dot com @ 2023-11-09 1:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110936
--- Comment #4 from Johel Ernesto Guerrero Peña <johelegp at gmail dot com> ---
They talk about `-fno-delete-null-pointer-checks` in BUG71962.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-11-09 1:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 15:52 [Bug sanitizer/110936] New: if constexpr: member function pointers cannot be checked with ubsan jeanmichael.celerier at gmail dot com
2023-09-01 1:54 ` [Bug c++/110936] " johelegp at gmail dot com
2023-09-01 2:21 ` johelegp at gmail dot com
2023-11-09 1:42 ` nathanieloshead at gmail dot com
2023-11-09 1:44 ` johelegp 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).