[LLVMbugs] [Bug 11854] New: floating point division by 0.0 vs -ftrapv vs IEEE floating point semantics

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jan 25 10:00:00 PST 2012


             Bug #: 11854
           Summary: floating point division by 0.0 vs -ftrapv vs IEEE
                    floating point semantics
           Product: new-bugs
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sean at rogue-research.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

In C and C++ floating point division by 0 is undefined behaviour[1][2].

clang's -ftrapv flag catches it:

int main (int argc, char *argv[])
    (void)argc; (void)argv;

    double a = 10.0;
    double b = 0.0;
    double c = a / b;

    return c;

$ clang -ftrapv test.c 
$ ./a.out 
Illegal instruction: 4

On the one hand, I like this, because I want to write portable code.  OTOH,
practically speaking, most environments use IEEE floating point semantics,
where division by 0 gives NaN or Inf.

Therefore, I'd like to suggest splitting -ftrapv into 2 flags.  One very
strict, as currently; and one that doesn't complain about things that are well
defined in IEEE-754.


C++98 5.6 Multiplicative operators [expr.mul]p4 says , "If the second operand
of / or % is zero the behavior is undefined".  It's the same in C++11 N3242. 
Floating point division is not distinguished from integral division...

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list