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

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 9 14:06:01 PST 2022


ldionne added a comment.

In D119152#3306276 <https://reviews.llvm.org/D119152#3306276>, @philnik wrote:

> How do you expect the libc++-specific test to look? The compiler won't ignore that there is a `__builtin_unreachable` in the way and just remove all the code after that. We don't control the behavior in this case. We don't even have to do anything in `unreachable()`. It can just be empty and marked with `[[noreturn]]` and it would work pretty much the same.  https://godbolt.org/z/GvbnG76nW

Sorry, `.fail.cpp` wasn't accurate. In `<test>.pass.cpp`:

  // 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, and it will call `std::abort()` otherwise. In both cases, the executable will return with non-zero. And since the test is `XFAIL`ed, it will expect that non-zero and be reported as an expected failure.

If we implemented `std::unreachable()` as an empty body, it would result in "unexpected pass".



================
Comment at: libcxx/test/std/utilities/utility/utility.unreachable/unreachable.compile.pass.cpp:8
+//===----------------------------------------------------------------------===//
+
+#include <utility>
----------------
This needs some standard requirements.

I suggest running just the test you're adding locally under various standard modes (`build/bin/llvm-lit -sv libcxx/test/<path-to-test> --param std=c++XX`) to shake out basic failures and get faster turn around time.


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