diff options
author | Shubham Sandeep Rastogi <srastogi22@apple.com> | 2024-02-05 15:30:35 -0800 |
---|---|---|
committer | Shubham Sandeep Rastogi <srastogi22@apple.com> | 2024-02-05 15:33:21 -0800 |
commit | 6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48 (patch) | |
tree | 472afc99e6540b0675b4b56b172cd7aefc6fc291 /llvm/lib | |
parent | a7bc9cb6ffa91ff0ebabc45c0c7263c7c2c3a4de (diff) | |
download | llvm-6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48.zip llvm-6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48.tar.gz llvm-6ce03ff3fef8fb6fa9afe8eb22c6d98bced26d48.tar.bz2 |
Revert "[IR] Use range-based for loops (NFC)"
This reverts commit e8512786fedbfa6ddba70ceddc29d7122173ba5e.
This revert is done because llvm::drop_begin over an empty ArrayRef
doesn't return an empty range, and therefore can lead to an invalid
address returned instead.
See discussion in https://github.com/llvm/llvm-project/pull/80737 for
more context.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/AsmWriter.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Function.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/IR/ProfDataUtils.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 7 |
6 files changed, 16 insertions, 14 deletions
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp index 35a9876..7b56c47 100644 --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1309,8 +1309,8 @@ void SlotTracker::CreateMetadataSlot(const MDNode *N) { ++mdnNext; // Recursively add any MDNodes referenced by operands. - for (const MDOperand &MDO : N->operands()) - if (const MDNode *Op = dyn_cast_or_null<MDNode>(MDO)) + for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) + if (const MDNode *Op = dyn_cast_or_null<MDNode>(N->getOperand(i))) CreateMetadataSlot(Op); } diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 19d80eb9..b90bbe7 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -5209,8 +5209,8 @@ static Metadata *upgradeLoopArgument(Metadata *MD) { SmallVector<Metadata *, 8> Ops; Ops.reserve(T->getNumOperands()); Ops.push_back(upgradeLoopTag(T->getContext(), OldTag->getString())); - for (const MDOperand &MDO : llvm::drop_begin(T->operands())) - Ops.push_back(MDO); + for (unsigned I = 1, E = T->getNumOperands(); I != E; ++I) + Ops.push_back(T->getOperand(I)); return MDTuple::get(T->getContext(), Ops); } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 2cf8829..d8c1b0d 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -400,8 +400,8 @@ static MDNode *updateLoopMetadataDebugLocationsImpl( // Save space for the self-referential LoopID. SmallVector<Metadata *, 4> MDs = {nullptr}; - for (const MDOperand &MDO : llvm::drop_begin(OrigLoopID->operands())) { - Metadata *MD = MDO; + for (unsigned i = 1; i < OrigLoopID->getNumOperands(); ++i) { + Metadata *MD = OrigLoopID->getOperand(i); if (!MD) MDs.push_back(nullptr); else if (Metadata *NewMD = Updater(MD)) diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index d3e2ae0..22e2455 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -1976,9 +1976,10 @@ DenseSet<GlobalValue::GUID> Function::getImportGUIDs() const { if (MDNode *MD = getMetadata(LLVMContext::MD_prof)) if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) if (MDS->getString().equals("function_entry_count")) - for (const MDOperand &MDO : llvm::drop_begin(MD->operands(), 2)) - R.insert( - mdconst::extract<ConstantInt>(MDO)->getValue().getZExtValue()); + for (unsigned i = 2; i < MD->getNumOperands(); i++) + R.insert(mdconst::extract<ConstantInt>(MD->getOperand(i)) + ->getValue() + .getZExtValue()); return R; } diff --git a/llvm/lib/IR/ProfDataUtils.cpp b/llvm/lib/IR/ProfDataUtils.cpp index dcb057c..b1a10d0 100644 --- a/llvm/lib/IR/ProfDataUtils.cpp +++ b/llvm/lib/IR/ProfDataUtils.cpp @@ -162,8 +162,8 @@ bool extractProfTotalWeight(const MDNode *ProfileData, uint64_t &TotalVal) { return false; if (ProfDataName->getString().equals("branch_weights")) { - for (const MDOperand &MDO : llvm::drop_begin(ProfileData->operands())) { - auto *V = mdconst::dyn_extract<ConstantInt>(MDO); + for (unsigned Idx = 1; Idx < ProfileData->getNumOperands(); Idx++) { + auto *V = mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(Idx)); assert(V && "Malformed branch_weight in MD_prof node"); TotalVal += V->getValue().getZExtValue(); } diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index 8d992c2..b04d39c 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -2913,8 +2913,8 @@ void Verifier::visitFunction(const Function &F) { VisitDebugLoc(I, I.getDebugLoc().getAsMDNode()); // The llvm.loop annotations also contain two DILocations. if (auto MD = I.getMetadata(LLVMContext::MD_loop)) - for (const MDOperand &MDO : llvm::drop_begin(MD->operands())) - VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MDO)); + for (unsigned i = 1; i < MD->getNumOperands(); ++i) + VisitDebugLoc(I, dyn_cast_or_null<MDNode>(MD->getOperand(i))); if (BrokenDebugInfo) return; } @@ -4713,7 +4713,8 @@ void Verifier::visitProfMetadata(Instruction &I, MDNode *MD) { Check(MD->getNumOperands() == 1 + ExpectedNumOperands, "Wrong number of operands", MD); } - for (const MDOperand &MDO : llvm::drop_begin(MD->operands())) { + for (unsigned i = 1; i < MD->getNumOperands(); ++i) { + auto &MDO = MD->getOperand(i); Check(MDO, "second operand should not be null", MD); Check(mdconst::dyn_extract<ConstantInt>(MDO), "!prof brunch_weights operand is not a const int"); |