[LLVMbugs] [Bug 19846] New: Non-trivial infinite while loops being optimized away

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri May 23 16:29:00 PDT 2014


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

            Bug ID: 19846
           Summary: Non-trivial infinite while loops being optimized away
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: chris.a.ferguson at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following code fails to compile with Clang 3.2, is optimized away entirely
with Clang 3.3 using -O3, and is optimized away entirely with Clang 3.4 using
-O2 and -O3.

#include <cstdint>

int main()
{
    uint32_t i = 0;
    uint32_t count = 1;

    while (1)
    {
        if( i < 5 )
            count+=1;

        if (i == 0xFFFFFFFF)
            break;
        i++;
    }

    return count; // should return 6
}

The assembly output from Clang 3.3 with -O3 looks like:

main:                                   # @main
    movl    $1, %eax
    ret

Here is an online example: http://goo.gl/PAqMny

This is a simplified test case, the original looked like this:
http://goo.gl/RTdHN3

I brought this up on stackoverflow first:
http://stackoverflow.com/questions/23838661/why-is-clang-optimizing-this-code-out

-- 
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/20140523/d1db2277/attachment.html>


More information about the llvm-bugs mailing list