3 ms·
> In LLVM this might just be a weird side-effect we don't care about, but actually having an integer overflow is a big deal in C that introduces UB. Given the i
by jcranmer 6y ago
> In LLVM this might just be a weird side-effect we don't care about, but actually having an integer overflow is a big deal in C that introduces UB. Given the introduction, LLVM (incorrectly) introduces (C) UB at times.
This doesn't matter. LLVM IR is not C, and it is not convertible to C, as it implements a superset of C semantics, which includes some cases where behavior that is undefined in C is well-defined in LLVM IR. Once C is lowered to LLVM IR, it doesn't matter what C says is or isn't undefined behavior, because there is no longer any C code being considered.
- dvt 6y ago> This doesn't matter. Maybe I expressed myself a bit too literally, but I wouldn't say that how LLVM handles UB "doesn't matter." Look at how Clang compiles undefined behavior vs GCC (for example)[1]. A bit tautological, but different ways of handling UB can lead to different ways UB behaves. > LLVM IR is not C, and it is not convertible to C... This isn't strictly true. There used to be an "official" C(pp) backend, which has been recently resurrected[2]. You can definitely go from LLVM to C -- probably won't be very readable, though. [1] https://blog.llvm.org/posts/2011-05-21-what-every-c-programmer-should-know_21/ https://blog.llvm.org/posts/2011-05-21-what-every-c-programm... [2] https://github.com/JuliaComputing/llvm-cbe https://github.com/JuliaComputing/llvm-cbe
- lambdatronics 6y ago> different ways of handling UB can lead to different ways UB behaves. Ha! If something depends on how 'undefined behavior' behaves, then it's not really undefined, is it? :D