4 ms·
TIL about clang's -fsanitize=undefined, and immediately discovered and corrected a handful of subtle bugs lurking in one of my projects. Thanks, Zig, and thanks
by RodgerTheGreat 5y ago
TIL about clang's -fsanitize=undefined, and immediately discovered and corrected a handful of subtle bugs lurking in one of my projects. Thanks, Zig, and thanks, Clang.
- slimsag 5y agoCrazy how often this catches undefined behavior. Compiling GLFW with Zig we've found like ~4 separate UB issues, one I described here[0] Wish it could default to on with clang, but probably it'd break too many things. Really wonder how many severe issues we'd find just from turning this on by default everywhere, though. [0] https://devlog.hexops.com/2021/perfecting-glfw-for-zig-and-finding-undefined-behavior https://devlog.hexops.com/2021/perfecting-glfw-for-zig-and-f...
- bregma 5y agoUBSAN adds a lot of runtime overhead. Turning it on my default would mean most software built with clang (or GCC, which has also had it for years) would suddenly be dog slow, like MSVCC in debug mode. Few developers have any idea how to use their toolchain correctly, so the defaults need to be chosen wisely.
- a_e_k 5y agoI recently started testing a project with -fsanitize=integer as well. It'll report a few potential issues that -fsanitize=undefined won't, like left shifting a 1-bit off the end.
- brandmeyer 5y agoGCC supports many of the same sanitizers as well, since they were originally developed for GCC. We use GNU's ubsan and asan in our automated test suite.