[LLVMbugs] [Bug 2408] New: CBE generates code that violates C signed integer overflow rules

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Jun 3 05:53:19 PDT 2008


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

           Summary: CBE generates code that violates C signed integer
                    overflow rules
           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: sharparrow1 at yahoo.com
                CC: llvmbugs at cs.uiuc.edu


Testcase:
define i32 @a(i32 %a) {
entry:
        %shr = ashr i32 %a, 0           ; <i32> [#uses=1]
        %shr2 = ashr i32 2, 0           ; <i32> [#uses=1]
        %mul = mul i32 %shr, %shr2              ; <i32> [#uses=1]
        %shr4 = ashr i32 2, 0           ; <i32> [#uses=1]
        %div = sdiv i32 %mul, %shr4             ; <i32> [#uses=1]
        ret i32 %div
}

Result of "llc -march=c | ~/bin/gcc-4.3 -x c - -o - -S -O3 -fno-strict-aliasing
-fomit-frame-pointer":
a:
        movl    4(%esp), %eax
        ret

The semantics of this are not the same as those of the original code; for
example, take a(INT_MIN).

A bit contrived, but I'm reasonably sure this could affect real code.

To avoid this, the C backend should make sure to always do
addition/subtraction/multiplication in unsigned types.

Alternatively, we could suggest that -fwrapv should always be used with
CBE-generated code, but that seems unnecessary.  (If we go with this option,
anything that invokes gcc with CBE-generated code needs to be fixed.)


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