diff options
| author | Manuel Klimek <klimek@google.com> | 2016-08-03 15:12:00 +0000 |
|---|---|---|
| committer | Manuel Klimek <klimek@google.com> | 2016-08-03 15:12:00 +0000 |
| commit | 16c6d0ac373e2d9d0c39a39ac865dfc7e33786c2 (patch) | |
| tree | 04775233a35385960d1dfe912336d5589a2c0d28 /clang/lib/Tooling | |
| parent | 82b1468a4dacc9d3e59cddb587b10acde871296a (diff) | |
| download | bcm5719-llvm-16c6d0ac373e2d9d0c39a39ac865dfc7e33786c2.tar.gz bcm5719-llvm-16c6d0ac373e2d9d0c39a39ac865dfc7e33786c2.zip | |
Fix bug in conflict check for Replacements::add().
We would not detect conflicts when inserting insertions at the same
offset as previously contained replacements.
llvm-svn: 277603
Diffstat (limited to 'clang/lib/Tooling')
| -rw-r--r-- | clang/lib/Tooling/Core/Replacement.cpp | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/clang/lib/Tooling/Core/Replacement.cpp b/clang/lib/Tooling/Core/Replacement.cpp index b990ed2083a..d498f433521 100644 --- a/clang/lib/Tooling/Core/Replacement.cpp +++ b/clang/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()) { |

