3 ms·
> Do you want to have signed integer overflow not be undefined behavior? Sorry, you can't do that in C. Do you want to support SIMD vector types? Oops, no suppo
by pizlonator 3y ago
> Do you want to have signed integer overflow not be undefined behavior? Sorry, you can't do that in C. Do you want to support SIMD vector types? Oops, no support in C. Underaligned memory accesses? Packed structures? Support for handling unwind structures? Coroutines?
You can get those things with most C compilers via compiler flags or other extensions.
You can handle unwinding by targeting C++ instead of C, or doing the unwinding in a totally custom way. The last JVM I wrote had a C backend that did unwinding. It worked with any C compiler. You wouldn’t want to use llvm’s unwinding for the unwinding of most higher level languages anyway.
Coroutines can be lowered to C. Most coroutines in higher level languages work best when lowered to C-like functions that save/restore state as needed. Heck, JSC’s coroutines just lower to JSC’s internal notion of a regular function.
> there are still a few LLVM instructions and intrinsics that just don't exist in C (chief among them is invoke, which is used to implement C++ exception handling).
Right so if you’re implementing C++ then you probably want to compile to llvm not C. But if you have exception semantics that are sufficiently not like C++ then you’re better off handling them at a higher level and lowering to something that doesn’t rely on invoke. You can do that in C.
More details: C++ exceptions and llvm invoke are optimized very aggressively for the case that no exceptions are thrown. If you compile Java, where some programs use exceptions for control flow, you’ll want an implementation that is less aggressively optimized for not throwing. And then if you do that then C is fine.