Jeffrey Walton via llvm-dev
2020-Mar-29 23:18 UTC
[llvm-dev] How to disable UBsan divide-by-zero in source files?
Hi Everyone, I'm catching a finding for divide by zero when using floats. I think this is a false positive since IEEE 754 states either a trap or infinity: $ cat test.c #include <float.h> #include <math.h> int main(void) { return INFINITY == 1.0f / 0.0f ? 0 : 1; } $ clang -fsanitize=undefined test.c -o test.exe $ ./test.exe test.c:5:27: runtime error: division by zero I'm looking for a way to disable UBsan divide-by-zero in the source code. I don't see something like: #pragma clang diagnostic ignored "-fsanitize=divide-by-zero" Trying to use a pragma results in (https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas): $ clang -fsanitize=undefined test.c -o test.exe test.c:4:34: warning: pragma diagnostic expected option name (e.g. "-Wundef") [-Wunknown-pragmas] #pragma clang diagnostic ignored "-fsanitize=divide-by-zero" How do disable divide-by-zero at the source level? The use case is, users who run self tests will CFLAGS="-fsanitize=undefined". They should not need to investigate findings, and add additional flags like no-divide-by-zero. Things should just work for them. Thanks in advance.
Eli Friedman via llvm-dev
2020-Mar-30 17:01 UTC
[llvm-dev] How to disable UBsan divide-by-zero in source files?
https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#issue-suppression . Also, the float-divide-by-zero diagnostic is no longer part of -fsanitize=undefined, as of clang 9.0. -Eli -----Original Message----- From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Jeffrey Walton via llvm-dev Sent: Sunday, March 29, 2020 4:18 PM To: llvm-dev <llvm-dev at lists.llvm.org> Subject: [EXT] [llvm-dev] How to disable UBsan divide-by-zero in source files? Hi Everyone, I'm catching a finding for divide by zero when using floats. I think this is a false positive since IEEE 754 states either a trap or infinity: $ cat test.c #include <float.h> #include <math.h> int main(void) { return INFINITY == 1.0f / 0.0f ? 0 : 1; } $ clang -fsanitize=undefined test.c -o test.exe $ ./test.exe test.c:5:27: runtime error: division by zero I'm looking for a way to disable UBsan divide-by-zero in the source code. I don't see something like: #pragma clang diagnostic ignored "-fsanitize=divide-by-zero" Trying to use a pragma results in (https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas): $ clang -fsanitize=undefined test.c -o test.exe test.c:4:34: warning: pragma diagnostic expected option name (e.g. "-Wundef") [-Wunknown-pragmas] #pragma clang diagnostic ignored "-fsanitize=divide-by-zero" How do disable divide-by-zero at the source level? The use case is, users who run self tests will CFLAGS="-fsanitize=undefined". They should not need to investigate findings, and add additional flags like no-divide-by-zero. Things should just work for them. Thanks in advance. _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev