<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Non-trivial infinite while loops being optimized away"
   href="http://llvm.org/bugs/show_bug.cgi?id=19846">19846</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Non-trivial infinite while loops being optimized away
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>chris.a.ferguson@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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: <a href="http://goo.gl/PAqMny">http://goo.gl/PAqMny</a>

This is a simplified test case, the original looked like this:
<a href="http://goo.gl/RTdHN3">http://goo.gl/RTdHN3</a>

I brought this up on stackoverflow first:
<a href="http://stackoverflow.com/questions/23838661/why-is-clang-optimizing-this-code-out">http://stackoverflow.com/questions/23838661/why-is-clang-optimizing-this-code-out</a></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>