[libcxx-commits] [PATCH] D119152: [libc++] Implement P0627R6 (Function to mark unreachable code)

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 9 14:18:52 PST 2022


Quuxplusone added a comment.

In D119152#3309138 <https://reviews.llvm.org/D119152#3309138>, @ldionne wrote:

> In D119152#3306276 <https://reviews.llvm.org/D119152#3306276>, @philnik wrote:
>
>> How do you expect the libc++-specific test to look? [...] https://godbolt.org/z/GvbnG76nW
>
>
>
>   // XFAIL: *
>   
>   int main(int, char**) {
>     std::unreachable();
>   
>     return 0;
>   }
>
> When you run this, it will do `zsh: illegal hardware instruction  ./a.out` if `__builtin_unreachable()` is used [...]

I don't think that's guaranteed. `__builtin_unreachable()` just means "assume false"; it doesn't necessarily translate into a `ud2` AFAIK, especially if we're talking about something that will work on both GCC and Clang.
Even on Clang at `-O0`, it seems to just flow off the unreachable end of `main` into whatever code follows that in memory: https://godbolt.org/z/fz6hh76P5

However, I think we //could// do a `verify.cpp` test: namely,

  [[noreturn]] void f() { std::unreachable(); }

should //not// trigger Clang's diagnostic `warning: function declared 'noreturn' should not return [-Winvalid-noreturn]`. If it does, that's a bug.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119152/new/

https://reviews.llvm.org/D119152



More information about the libcxx-commits mailing list