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

            Bug ID: 15727
           Summary: Value::isUsedInBasicBlock is buggy.
           Product: libraries
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: release blocker
          Priority: P
         Component: Core LLVM classes
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

I happened to use Value::isUsedInBasicBlock(const BasicBlock *BB) const.

I noticed that the function always returns false when the basic block size is
larger than 3. So I checked the source of Value.c and found there is a bug
there.

113   unsigned MaxBlockSize = 3;                                                
114   for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E;
++I) {    
115     if (std::find(I->op_begin(), I->op_end(), this) != I->op_end())         
116       return true;                                                          
117     if (MaxBlockSize-- == 0) // If the block is larger fall back to
use_iterator    
118       break;                                                                
119   }                                                                         
120                                                                             
121   if (MaxBlockSize != 0) // We scanned the entire block and found no use.   
122     return false;  

If block size is larger than 3, in line 117, the loop is breaked out, and
MaxBlockSize = -1. In line 121, MaxBlockSize != 0 is true, and false is
returned. This explains why the function always returns false when the block
size is larger than 3.

The potential bug fix is

117   if (--MaxBlockSize == 0) // If ...

Thanks!

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to