[LLVMbugs] [Bug 3354] New: apparent bad interaction between math and short-circuit

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Jan 19 12:19:28 PST 2009


http://llvm.org/bugs/show_bug.cgi?id=3354

           Summary: apparent bad interaction between math and short-circuit
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: regehr at cs.utah.edu
                CC: llvmbugs at cs.uiuc.edu


The attached program displays this behavior on x86 Linux:

[regehr at babel tmp30]$ llvm-gcc -O small.c -o small
small.c: In function ‘main’:
small.c:19: warning: division by zero
small.c:19: warning: division by zero
[regehr at babel tmp30]$ ./small
x=1
Floating point exception

The thing is, the divide-by-zero behaviors are all protected by
short-circuiting operations, and should never fire.  I claim that LLVM's -O0
behavior is what must occur at all optimization levels:

[regehr at babel tmp30]$ llvm-gcc -O0 small.c -o small
small.c: In function ‘main’:
small.c:19: warning: division by zero
small.c:19: warning: division by zero
[regehr at babel tmp30]$ ./small
x=1
x=0

The macro in the attached code is simply a macroized version of the 2nd safe
multiplication fragment here:

https://www.securecoding.cert.org/confluence/display/cplusplus/INT32-CPP.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow


-- 
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