[LLVMbugs] [Bug 16757] New: Clang optimized out two break statement from a while loop

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jul 30 15:42:57 PDT 2013


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

            Bug ID: 16757
           Summary: Clang optimized out two break statement from a while
                    loop
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: mrcool0905 at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 10960
  --> http://llvm.org/bugs/attachment.cgi?id=10960&action=edit
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

-- 
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/20130730/7f18b455/attachment.html>


More information about the llvm-bugs mailing list