GCC and division by 0 under sanitizers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Everyone,

I'm having trouble with floating point arithmetic and division by 0.
Undefined behavior sanitizer flags a division by 0 is a runtime error.
However, IEEE 754 says it is infinity if the operation does not trap.
(Assuming I am looking at the right version of the standard).

So to test IEEE floating point for division by 0:

    void test_floats(void)
    {
        ASSERT(INFINITY == 1.0f / 0.0f);
        ...
    }

It seems like a reasonable test to me. However, we don't really want
UBsan findings during testing either.

I was looking at pragmas to disable UBsan division-by-zero in the
source file, but I don't see one. Confer,
https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html and
https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html.

Given users will CFLAGS="-fsanitize=undefined", what is the way to
handle this in a way that avoids asking the user to do something?

Asking the user to RTFM and use something like
-fsanitize=all,no-divide-by-zero or
-fsanitize-recover=float-divide-by-zero is not going to work. If RTFM
was going to work, it would have happened in the last 50 years or so.
So I want to engineer around the user.

Jeff



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux