diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2014-05-29 23:05:52 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2014-05-29 23:05:52 +0000 |
commit | 3012a1b4cd6a7d4cc295f9c70ebc643ece5deac0 (patch) | |
tree | 44dadec0e5e0efb2db9351a8b886d7ab4f0cb200 /llvm/lib/Transforms | |
parent | 11b49c3818c3b827c027023d7765b0349325575e (diff) | |
download | bcm5719-llvm-3012a1b4cd6a7d4cc295f9c70ebc643ece5deac0.tar.gz bcm5719-llvm-3012a1b4cd6a7d4cc295f9c70ebc643ece5deac0.zip |
Fix one bug in the latest incarnation of r209843 -- combining GEPs
across PHI nodes. The code was computing the Idxs from the 'GEP'
variable's indices when what it wanted was Op1's indices. This caused an
ASan heap-overflow for me that pin pointed the issue when Op1 had more
indices than GEP did. =] I'll let Louis add a specific test case for
this if he wants.
llvm-svn: 209857
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index c72d099d9f0..38f92ddf665 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -1233,10 +1233,21 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { if (!Op2 || Op1->getNumOperands() != Op2->getNumOperands()) return nullptr; + // Keep track of the type as we walk the GEP. + Type *CurTy = Op1->getOperand(0)->getType()->getScalarType(); + for (unsigned J = 0, F = Op1->getNumOperands(); J != F; ++J) { if (Op1->getOperand(J)->getType() != Op2->getOperand(J)->getType()) return nullptr; + if (J > 1) { + if (CompositeType *CT = dyn_cast<CompositeType>(CurTy)) { + CurTy = CT->getTypeAtIndex(Op1->getOperand(J)); + } else { + CurTy = nullptr; + } + } + if (Op1->getOperand(J) != Op2->getOperand(J)) { if (DI == -1) { // We have not seen any differences yet in the GEPs feeding the @@ -1245,14 +1256,8 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) { // The first two arguments can vary for any GEP, the rest have to be // static for struct slots - if (J > 1) { - SmallVector<Value*, 8> Idxs(GEP.idx_begin(), GEP.idx_begin()+J-1); - Type *Ty = - GetElementPtrInst::getIndexedType(Op1->getOperand(0)->getType(), - Idxs); - if (Ty->isStructTy()) - return nullptr; - } + if (J > 1 && CurTy->isStructTy()) + return nullptr; DI = J; } else { |