It exists. Clang has UBSan which can detect many undefined behaviour (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#...).
It's integrated into Apple's Xcode 9, which can pause into the debugger when encountering an issue.
I was actually using it to debug an issue just as I read your comment.
Re:The Curious Case of the Longevity of C
by iainmerrick on Tuesday October 03, 2017 @11:55AM
(#15393290)
It exists, but it doesn't do anything in the example that was discussed recently, "undefined behavior may call a never-called function": https://news.ycombinator.com/item?id=15324414
As far as I can tell, -O0 is the only way to avoid that particular mis-optimization in Clang.
Re:The Curious Case of the Longevity of C
by rbehrends on Tuesday October 03, 2017 @10:50AM
(#15392774)
This cannot be done for all undefined behavior (because that would be too expensive, if at all possible), but you can use the `-fsanitize` family of options in both gcc and clang to at least get runtime errors for quite a few important cases of undefined behavior.
Speaking of which, a killer feature I'd like to see in a C compiler is a flag for debug mode which SIGABRTs whenever it enters an undefined behaviour codepath. For example, sometimes the compiler knows that if pointers alias, or an integer overflows or something, it can do whatever it wants. I want a flag which will automatically add assertions to the generated code, so at least in debug mode it'll crash if thats ever actually the case.