[llvm] r209065 - Fix for sanitizer crash introduced in r209049

Louis Gerbarg lgg at apple.com
Fri May 16 23:51:36 PDT 2014


Author: louis
Date: Sat May 17 01:51:36 2014
New Revision: 209065

URL: http://llvm.org/viewvc/llvm-project?rev=209065&view=rev
Log:
Fix for sanitizer crash introduced in r209049

This patch fixes 3 issues introduced by r209049 that only showed up in on
the sanitizer buildbots. One was a typo in a compare. The other is a check to
confirm that the single differing value in the two incoming GEPs is the same
type. The final issue was the the IRBuilder under some circumstances would
build PHIs in the middle of the block.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=209065&r1=209064&r2=209065&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Sat May 17 01:51:36 2014
@@ -1230,10 +1230,13 @@ Instruction *InstCombiner::visitGetEleme
 
     for (auto I = PN->op_begin()+1, E = PN->op_end(); I !=E; ++I) {
       GetElementPtrInst *Op2 = dyn_cast<GetElementPtrInst>(*I);
-      if (!Op2 || Op1->getNumOperands() != Op1->getNumOperands())
+      if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands())
         return nullptr;
 
       for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) {
+        if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType())
+          return nullptr;
+
         if (Op1->getOperand(J) != Op2->getOperand(J)) {
           if (DI == -1) {
             // We have not seen any differences yet in the GEPs feeding the
@@ -1263,8 +1266,12 @@ Instruction *InstCombiner::visitGetEleme
       // All the GEPs feeding the PHI differ at a single offset. Clone a GEP
       // into the current block so it can be merged, and create a new PHI to
       // set that index.
+      Instruction *InsertPt = Builder->GetInsertPoint();
+      Builder->SetInsertPoint(PN);
       PHINode *NewPN = Builder->CreatePHI(Op1->getOperand(DI)->getType(),
                                           PN->getNumOperands());
+      Builder->SetInsertPoint(InsertPt);
+
       for (auto &I : PN->operands())
         NewPN->addIncoming(dyn_cast<GEPOperator>(I)->getOperand(DI),
                            PN->getIncomingBlock(I));





More information about the llvm-commits mailing list