[clang][GSoC 2025] Usability Improvements for trapping Undefined Behavior Sanitizer

If you have in your top-level build flags (Makefile or w/e):

COPTS+=-fsanitize=undefined

And then you have a particular build target you wish to not build with the sanitizer:

foo.o: COPTS+=-fno-sanitize=all

And now you want to build the binary in trap mode. So maybe you add to the toplevel

ifdef SANITIZE_TRAP
COPTS+=-fsanitize-trap=undefined
endif

It would be annoying to have to know you need to also go disable -fsanitize-trap for each target that opted-out of sanitization.

And, why inconsistently, only for -fsanitize-trap, and not any other sanitizer-option which is applicable only if a particular sanitizer is actually enabled? Note that there’s other options that even take sanitizer names the same way, -fsanitize-merge-handlers=<sanitizer-kind>, -fsanitize-recover=<sanitizer-kind>, -fsanitize-skip-hot-cutoff=<sanitizer-kind>=<weight>.

Yet, if it was consistently an error to specify options for a disabled sanitizer, it would be even more annoying…

2 Likes