llvm-cbe icon indicating copy to clipboard operation
llvm-cbe copied to clipboard

__builtin_unreachable()

Open spth opened this issue 9 years ago • 0 comments

The cbe sometimes emits:

__builtin_unreachable();

Which is a GCC extension also supported by clang. For MSVC there is

#ifdef _MSC_VER
#define __builtin_unreachable() __assume(0)
#endif

However, __builtin_unreachable() is not standard C, so the emitted code compiles with GCC, clang and MSVC, but not other C compilers.

I see three possible solutions:

  1. Do not emit any __builtin_unreachable(). This might take some optimization opportunities from GCC, clang and MSVC, but it shouldn't hurt much. Anyway, __builtin_unreachable() is something rare.
  2. Make __builtin_unreachable() an empty define unless the compiler is GCC, clang or MSVC.
  3. Replace __builtin_unreachable() by an empty, _Noreturn static inline function. This should give the c compiler the full information on unreachability. But it uses _Noreturn, requiring C11.

We could even use 3) if C11is available (like we already do with _Noreturn) and otherwise fall back to 2). But I don't know if this rather exotic functionality is worth it. 1) would be best for simplicity.

Philipp

spth avatar Oct 25 '16 14:10 spth