4 ms·
> with gcc to keep a lid on the effects of undefined behavior (and often more or even stricter options, such as -fwrapv). Speaking of which, a killer feature I
by josephg 9y ago
> with gcc to keep a lid on the effects of undefined behavior (and often more or even stricter options, such as -fwrapv).
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.
- rbehrends 9y agoThis 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.
- deleted 9y ago[deleted]
- jchb 9y agoIt exists. Clang has UBSan which can detect many undefined behaviour (https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks 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.
- iainmerrick 9y agoIt 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 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.