Suppress specific sanitizer check, but still fail program on all others

2

I would like to suppress one error in a third-party library, but still have the program exit 1 on any other failed check. It seems to me that -fno-sanitize-recover will exit the program regardless of the suppressions file's contents. With -fsanitize-recover on the other hand, the specified error is correctly suppressed and the other one still printed, but the program exits normally, which I don't want.

$ cat main.cpp
int main() {
  int k = 0x7fffffff;
  k++;      // signed-integer-overflow
  k <<= k;  // invalid-shift-exponent
  return 0;
}

$ clang++ -fsanitize=undefined -fno-sanitize-recover main.cpp -o main

$ cat supp.txt
signed-integer-overflow:main.cpp

$ UBSAN_OPTIONS=report_error_type=1,suppressions=supp.txt ./main
main.cpp:3:4: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: signed-integer-overflow main.cpp:3:4 in

$ echo $?
1

$ clang++ -fsanitize=undefined -fsanitize-recover main.cpp -o main

$ UBSAN_OPTIONS=report_error_type=1,suppressions=supp.txt ./main
main.cpp:4:5: runtime error: shift exponent -2147483648 is negative
SUMMARY: UndefinedBehaviorSanitizer: invalid-shift-exponent main.cpp:4:5 in

$ echo $?
0

How can I achieve the desired behavior? Are Ubsan suppressions and -fno-sanitize-recover really mutually exclusive?

c++
clang
sanitizer
ubsan
asked on Stack Overflow Mar 3, 2021 by Laurenz

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0