llvm-cbe
llvm-cbe copied to clipboard
__builtin_unreachable()
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:
- 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.
- Make __builtin_unreachable() an empty define unless the compiler is GCC, clang or MSVC.
- 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