[llvm-dev] How to disable UBsan divide-by-zero in source files?
Jeffrey Walton via llvm-dev
llvm-dev at lists.llvm.org
Sun Mar 29 16:18:16 PDT 2020
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.
More information about the llvm-dev
mailing list