summaryrefslogtreecommitdiff
path: root/lib/Tooling/Core/Replacement.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2016-08-03 15:12:00 +0000
committerManuel Klimek <klimek@google.com>2016-08-03 15:12:00 +0000
commit7604798c68651927fb923ec1c0f6cda70122fc07 (patch)
tree3f75b5795b5622f935abd181e35c25a24f531d85 /lib/Tooling/Core/Replacement.cpp
parent7c12ee2f0bb2c9a06b9f59c288db1f441e55972d (diff)
downloadclang-7604798c68651927fb923ec1c0f6cda70122fc07.tar.gz
Fix bug in conflict check for Replacements::add().
We would not detect conflicts when inserting insertions at the same offset as previously contained replacements. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@277603 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Tooling/Core/Replacement.cpp')
-rw-r--r--lib/Tooling/Core/Replacement.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/Tooling/Core/Replacement.cpp b/lib/Tooling/Core/Replacement.cpp
index b990ed2083..d498f43352 100644
--- a/lib/Tooling/Core/Replacement.cpp
+++ b/lib/Tooling/Core/Replacement.cpp
@@ -159,15 +159,16 @@ llvm::Error Replacements::add(const Replacement &R) {
// replacement cannot overlap.
Replacement AtEnd(R.getFilePath(), R.getOffset() + R.getLength(), 0, "");
- // Find the first entry that starts after the end of R.
- // We cannot use upper_bound for that, as there might be an element equal to
- // AtEnd in Replaces, and AtEnd does not overlap.
- // Instead, we use lower_bound and special-case finding AtEnd below.
+ // Find the first entry that starts after or at the end of R. Note that
+ // entries that start at the end can still be conflicting if R is an
+ // insertion.
auto I = Replaces.lower_bound(AtEnd);
- // If *I == R (which can only happen if R == AtEnd) the first entry that
- // starts after R is (I+1).
- if (I != Replaces.end() && *I == R)
+ // If it starts at the same offset as R (can only happen if R is an
+ // insertion), we have a conflict. In that case, increase I to fall through
+ // to the conflict check.
+ if (I != Replaces.end() && R.getOffset() == I->getOffset())
++I;
+
// I is the smallest iterator whose entry cannot overlap.
// If that is begin(), there are no overlaps.
if (I == Replaces.begin()) {