diff --git a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp index b3188ec56fdfc9..5655d548ee344b 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/IRForTarget.cpp @@ -1582,14 +1582,7 @@ bool IRForTarget::UnfoldConstant(Constant *old_constant, ptr = value_maker.GetValue(function); std::vector index_vector; - - unsigned operand_index; - unsigned num_operands = constant_expr->getNumOperands(); - - for (operand_index = 1; operand_index < num_operands; - ++operand_index) { - Value *operand = constant_expr->getOperand(operand_index); - + for (Value *operand : gep->indices()) { if (operand == old_constant) operand = value_maker.GetValue(function); diff --git a/llvm/include/llvm/IR/Operator.h b/llvm/include/llvm/IR/Operator.h index 46c1dfc3e7350e..d0bce742cc96d3 100644 --- a/llvm/include/llvm/IR/Operator.h +++ b/llvm/include/llvm/IR/Operator.h @@ -488,6 +488,14 @@ class GEPOperator inline op_iterator idx_end() { return op_end(); } inline const_op_iterator idx_end() const { return op_end(); } + inline iterator_range indices() { + return make_range(idx_begin(), idx_end()); + } + + inline iterator_range indices() const { + return make_range(idx_begin(), idx_end()); + } + Value *getPointerOperand() { return getOperand(0); } @@ -544,7 +552,7 @@ class GEPOperator } unsigned countNonConstantIndices() const { - return count_if(make_range(idx_begin(), idx_end()), [](const Use& use) { + return count_if(indices(), [](const Use& use) { return !isa(*use); }); } diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp index 843c04855bf744..221b116d4371e2 100644 --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -5732,8 +5732,8 @@ const SCEV *ScalarEvolution::createNodeForGEP(GEPOperator *GEP) { return getUnknown(GEP); SmallVector IndexExprs; - for (auto Index = GEP->idx_begin(); Index != GEP->idx_end(); ++Index) - IndexExprs.push_back(getSCEV(*Index)); + for (Value *Index : GEP->indices()) + IndexExprs.push_back(getSCEV(Index)); return getGEPExpr(GEP, IndexExprs); }