I have an UndefinedBehaviorSanitizer build (-fsanitize=undefined
), and I am trying to suppress a warning for UB in an external library that is out of my control. The clang/gcc docs mention __attribute__((no_sanitize("undefined")))
, but to my surprise it seems that this attribute does not suppress warnings from subroutines.
//__attribute__((no_sanitize("shift"))) // this correctly suppresses the warning
int bar() {
return 1 << 64;
}
__attribute__((no_sanitize("shift"))) // this does not
int foo() {
return bar();
}
int main() {
foo();
return 0;
}
Since this attribute doesn't seem to work, how can I suppress this warning? I could remove the entire target from my UBSan build, but that seems incredibly heavy-handed.
Clang has pragmas to apply attributes in bulk:
Wrapping the header in those disables the check in your example: