[PATCH] D121750: Add a cmake flag to turn `llvm_unreachable()` into builtin_trap() when assertions are disabled

Mehdi AMINI via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 18 12:22:46 PDT 2022


mehdi_amini added inline comments.


================
Comment at: llvm/include/llvm/Support/ErrorHandling.h:143
+#elif LLVM_UNREACHABLE_OPTIMIZE
+#define llvm_unreachable(msg) LLVM_BUILTIN_TRAP
 #elif defined(LLVM_BUILTIN_UNREACHABLE)
----------------
mehdi_amini wrote:
> dexonsmith wrote:
> > Based on:
> > > 7>C:\src\upstream\llvm_clean_git\llvm\lib\Support\Compression.cpp(104): error C4716: 'llvm::zlib::uncompress': must return a value
> > 
> > it looks like `LLVM_BUILTIN_TRAP` isn't guaranteed to be something the compiler understands as `noreturn`. Maybe this logic needs to fallback to `llvm_unreachable_internal` if `LLVM_BUILTIN_TRAP` is not a function.
> The bug is that when you suggested a renaming the macro I didn't inverse the condition: the previous name was something like `SHOULD_TRAP` but with the new name the logic is reversed! I need `#elif !LLVM_UNREACHABLE_OPTIMIZE` I think.
I fixed the condition but I'm not sure how to address the windows situation. I think I'd try to add an attribute or something to make it "noreturn" there as well, but rather leave it to someone who could actually test it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D121750



More information about the llvm-commits mailing list