diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -272,7 +272,7 @@ /// Return a range covering \p RangeOrContainer with the first N elements /// excluded. -template auto drop_begin(T &&RangeOrContainer, size_t N) { +template auto drop_begin(T &&RangeOrContainer, size_t N = 1) { return make_range(std::next(adl_begin(RangeOrContainer), N), adl_end(RangeOrContainer)); } diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -349,7 +349,7 @@ bool Changed = false; if (InheritAllAttrs || InheritSomeAttrs) { - for (const MDOperand &Existing : drop_begin(OrigLoopID->operands(), 1)) { + for (const MDOperand &Existing : drop_begin(OrigLoopID->operands())) { MDNode *Op = cast(Existing.get()); auto InheritThisAttribute = [InheritSomeAttrs, @@ -386,7 +386,7 @@ continue; HasAnyFollowup = true; - for (const MDOperand &Option : drop_begin(FollowupNode->operands(), 1)) { + for (const MDOperand &Option : drop_begin(FollowupNode->operands())) { MDs.push_back(Option.get()); Changed = true; } diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp --- a/llvm/unittests/ADT/STLExtrasTest.cpp +++ b/llvm/unittests/ADT/STLExtrasTest.cpp @@ -400,6 +400,17 @@ } } +TEST(STLExtrasTest, DropBeginDefaultTest) { + SmallVector vec{0, 1, 2, 3, 4}; + + int i = 1; + for (auto &v : drop_begin(vec)) { + EXPECT_EQ(v, i); + i += 1; + } + EXPECT_EQ(i, 5); +} + TEST(STLExtrasTest, EarlyIncrementTest) { std::list L = {1, 2, 3, 4};