Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Undefined Behavior sanitizer finding for 1.0f / 0.0f #44322

Open Quuxplusone opened 4 years ago

Quuxplusone commented 4 years ago
Bugzilla Link PR45352
Status NEW
Importance P normal
Reported by Jeffrey Walton (noloader@gmail.com)
Reported on 2020-03-29 15:40:09 -0700
Last modified on 2020-04-10 03:58:00 -0700
Version 8.0
Hardware PC Linux
CC bruno@clisp.org, dblaikie@gmail.com, dcoughlin@apple.com, llvm-bugs@lists.llvm.org, noloader@gmail.com, noqnoqneo@gmail.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
The following is producing an Undefined Behavior sanitizer finding:

    ASSERT(INFINITY == 1.0f / 0.0f);

After a quick read of IEEE 754, it looks like that is conforming behavior for
floats. According the IEEE 754, conforming behavior is infinity if a trap is
not raised.

    $ 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

GCC does not produce a finding for floats.
Quuxplusone commented 4 years ago

Moving to UBSan component.

Quuxplusone commented 4 years ago
(In reply to Artem Dergachev from comment #1)
> Moving to UBSan component.

Thanks Artem.

I found old reports under the clang/ubsan pair. I was wondering where ubsan
moved to.
Quuxplusone commented 4 years ago

The documentation https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html describes a sensible behaviour, namely that -fsanitize=float-divide-by-zero is NOT included in -fsanitize=undefined (because of IEEE 754).