Laurenz Altenmüller via llvm-dev
2021-Mar-03 20:28 UTC
[llvm-dev] Suppress specific sanitizer check, but still fail program on all others
Hello,
I have a question regarding the sanitizers. 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?
Cheers
Laurenz
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20210303/5d2304db/attachment-0001.html>
Vitaly Buka via llvm-dev
2021-Mar-04 20:46 UTC
[llvm-dev] Suppress specific sanitizer check, but still fail program on all others
UBSAN_OPTIONS=halt_on_error=1 Also you can consider to use: https://clang.llvm.org/docs/SanitizerSpecialCaseList.html On Thu, 4 Mar 2021 at 10:06, Laurenz Altenmüller via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello, > > I have a question regarding the sanitizers. 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 <(214)%20748-3647> + 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 <(214)%20748-3648> 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? > > Cheers > Laurenz > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210304/b09cdeab/attachment.html>