[PATCH] D23264: Fixes calculateRangesAfterReplacements crash when Replacements is empty.

Eric Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 8 06:45:38 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL278004: Fixes calculateRangesAfterReplacements crash when Replacements is empty. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D23264?vs=67155&id=67156#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23264

Files:
  cfe/trunk/lib/Tooling/Core/Replacement.cpp
  cfe/trunk/unittests/Tooling/RefactoringTest.cpp

Index: cfe/trunk/lib/Tooling/Core/Replacement.cpp
===================================================================
--- cfe/trunk/lib/Tooling/Core/Replacement.cpp
+++ cfe/trunk/lib/Tooling/Core/Replacement.cpp
@@ -361,6 +361,8 @@
   //   - Merge with \p Replaces.
   //   - The new ranges will be the affected ranges of the merged replacements.
   auto MergedRanges = combineAndSortRanges(Ranges);
+  if (Replaces.empty())
+    return MergedRanges;
   tooling::Replacements FakeReplaces;
   for (const auto &R : MergedRanges) {
     auto Err = FakeReplaces.add(Replacement(Replaces.begin()->getFilePath(),
Index: cfe/trunk/unittests/Tooling/RefactoringTest.cpp
===================================================================
--- cfe/trunk/unittests/Tooling/RefactoringTest.cpp
+++ cfe/trunk/unittests/Tooling/RefactoringTest.cpp
@@ -506,6 +506,13 @@
   EXPECT_TRUE(Ranges[1].getLength() == 22);
 }
 
+TEST(Range, RangesAfterEmptyReplacements) {
+  std::vector<Range> Ranges = {Range(5, 6), Range(10, 5)};
+  Replacements Replaces;
+  std::vector<Range> Expected = {Range(5, 10)};
+  EXPECT_EQ(Expected, calculateRangesAfterReplacements(Replaces, Ranges));
+}
+
 TEST(Range, RangesAfterReplacements) {
   std::vector<Range> Ranges = {Range(5, 2), Range(10, 5)};
   Replacements Replaces = toReplacements({Replacement("foo", 0, 2, "1234")});


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23264.67156.patch
Type: text/x-patch
Size: 1346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160808/105924fe/attachment.bin>


More information about the cfe-commits mailing list