我想抑制第三方库中的一个错误,但在任何其他失败的检查中仍然让程序退出 1。在我看来,无论文件的内容如何,-fno-sanitize-recover
都会退出程序。另一方面,指定的错误被正确抑制,另一个错误仍然打印,但程序正常退出,这是我不想要的suppressions
。-fsanitize-recover
$ 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
我怎样才能达到预期的行为?Ubsan 抑制和 -fno-sanitize-recover 真的相互排斥吗?