On Thu, 31 Mar 2022, Jonathan Wakely wrote:
On Thu, 31 Mar 2022 at 17:03, Marc Glisse via Libstdc++
<libstd...@gcc.gnu.org> wrote:
On Thu, 31 Mar 2022, Matthias Kretz via Gcc-patches wrote:
I like it. But I'd like it even more if we could have
#elif defined _UBSAN
__ubsan_invoke_ub("reached std::unreachable()");
But to my knowledge UBSAN has no hooks for the library like this (yet).
-fsanitize=undefined already replaces __builtin_unreachable with its own
thing, so I was indeed going to ask if the assertion / trap provide a
better debugging experience compared to plain __builtin_unreachable, with
the possibility to get a stack trace (UBSAN_OPTIONS=print_stacktrace=1),
etc? Detecting if (the right subset of) ubsan is enabled sounds like a
good idea.
Does UBsan define a macro that we can use to detect it?
https://github.com/google/sanitizers/issues/765 seems to say no (it could
be outdated though), but they were asking for use cases to motivate adding
one. Apparently there is a macro for clang, although I don't think it is
fine-grained.
Adding one to cppbuiltin.cc testing SANITIZE_UNREACHABLE looks easy, maybe
we can do just this one, we don't need to go overboard and define macros
for all possible suboptions of ubsan right now.
I don't think any of that prevents from pushing your patch as is for
gcc-12.
--
Marc Glisse