<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 --- - Clang optimized out two break statement from a while loop"
   href="http://llvm.org/bugs/show_bug.cgi?id=16757">16757</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang optimized out two break statement from a while loop
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.3
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>mrcool0905@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>Created <span class=""><a href="attachment.cgi?id=10960" name="attach_10960" title="example code">attachment 10960</a> <a href="attachment.cgi?id=10960&action=edit" title="example code">[details]</a></span>
example code

I have a following example function. The problem I am seeing now is that
without a return statement, clang will optimize out the break statements and
we'll never break from the while(1) and return. I've attached the example code.

 bool advance() {
 17         if ( mCurrent == 0 )
 18             return false;
 19         while( 1 )
 20         {
 21             mIndex ++;
 22             if( mIndex > 2 )
 23             {
 24                 mCurrent = mCurrent->next;
 25                 mIndex = 0;
 26             }
 27             if( mCurrent == 0 )
 28                 break;
 29             if( functionReturningBool( mCurrent, mIndex ) )
 30                 break;
 31         }
 32         // warning missing return
 33         
 34     }

Here is the disassembly:
00000000 <Iterator::advance()>:
   0:   e92d 4890       stmdb   sp!, {r4, r7, fp, lr}
   4:   4604            mov     r4, r0
   6:   af01            add     r7, sp, #4
   8:   6820            ldr     r0, [r4, #0]
   a:   2800            cmp     r0, #0
   c:   bf04            itt     eq
   e:   2000            moveq   r0, #0
  10:   e8bd 8890       ldmiaeq.w       sp!, {r4, r7, fp, pc}
  14:   6862            ldr     r2, [r4, #4]
  16:   1c51            adds    r1, r2, #1
  18:   2a02            cmp     r2, #2
  1a:   6061            str     r1, [r4, #4]
  1c:   6820            ldr     r0, [r4, #0]
  1e:   bfa2            ittt    ge
  20:   6800            ldrge   r0, [r0, #0]
  22:   2100            movge   r1, #0
  24:   e884 0003       stmiage.w       r4, {r0, r1}
  28:   f7ff fffe       bl      0 <functionReturningBool(List*, int)>
  2c:   e7f2            b.n     14 <Iterator::advance()+0x14>
  2e:   bf00            nop</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>