[LLVMbugs] [Bug 16642] New: Optimization eliminates an overflow check.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 17 05:35:14 PDT 2013


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

            Bug ID: 16642
           Summary: Optimization eliminates an overflow check.
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: julsomp at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following simple function
long long f(long long x, long long y) {
  long long r;
  long long err = 0;
  r = x * y;
  err = y != 0 && r / y != x;
  return err ? 0 : r;
}
clang -c -O1 -S bla.c
compiles to just
f:                                      # @f
    .cfi_startproc
# BB#0:
    imulq    %rsi, %rdi
    movq    %rdi, %rax
    ret
.Ltmp0:
    .size    f, .Ltmp0-f
    .cfi_endproc

which eliminates the attempted overflow checking, and therefore returns results
other than expected when x * y overflows.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130717/bf27db2b/attachment.html>


More information about the llvm-bugs mailing list