I'm creating a statically compiled programming language, and I'm using LLVM as its backend. I want my language to trap/crash whenever integer overflow occurs.
I'm aware of things like llvm.sadd.with.overflow, but I don't think that's an optimal/efficient solution. That function returns a struct of two values, instead of just giving me direct access to the OF register flag. Ideally, after each arithmetic operation I would just have a "JO" assembly instruction to trap whenever integer overflow occurs. This is exactly what clang's UndefinedBehaviorSanitizer does. However, I'm compiling to LLVM IR, not C or C++.
How can I use the UndefinedBehaviorSanitizer (or accomplish something equivalent) to handle integer overflow, directly within LLVM IR?