[clang-tools-extra] r250523 - Replacements in different files do not overlap.
Angel Garcia Gomez via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 16 09:15:27 PDT 2015
Author: angelgarcia
Date: Fri Oct 16 11:15:27 2015
New Revision: 250523
URL: http://llvm.org/viewvc/llvm-project?rev=250523&view=rev
Log:
Replacements in different files do not overlap.
Summary: Prevent clang-tidy from discarding fixes that are in different files but happen to have the same file offset.
Reviewers: klimek, bkramer
Subscribers: bkramer, alexfh, cfe-commits
Differential Revision: http://reviews.llvm.org/D13810
Added:
clang-tools-extra/trunk/test/clang-tidy/Inputs/overlapping/
clang-tools-extra/trunk/test/clang-tidy/Inputs/overlapping/o.h
clang-tools-extra/trunk/test/clang-tidy/overlapping.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=250523&r1=250522&r2=250523&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Fri Oct 16 11:15:27 2015
@@ -469,34 +469,40 @@ void ClangTidyDiagnosticConsumer::remove
}
// Build events from error intervals.
- std::vector<Event> Events;
+ std::map<std::string, std::vector<Event>> FileEvents;
for (unsigned I = 0; I < Errors.size(); ++I) {
for (const auto &Replace : Errors[I].Fix) {
unsigned Begin = Replace.getOffset();
unsigned End = Begin + Replace.getLength();
+ const std::string &FilePath = Replace.getFilePath();
// FIXME: Handle empty intervals, such as those from insertions.
if (Begin == End)
continue;
- Events.push_back(Event(Begin, End, Event::ET_Begin, I, Sizes[I]));
- Events.push_back(Event(Begin, End, Event::ET_End, I, Sizes[I]));
+ FileEvents[FilePath].push_back(
+ Event(Begin, End, Event::ET_Begin, I, Sizes[I]));
+ FileEvents[FilePath].push_back(
+ Event(Begin, End, Event::ET_End, I, Sizes[I]));
}
}
- std::sort(Events.begin(), Events.end());
- // Sweep.
std::vector<bool> Apply(Errors.size(), true);
- int OpenIntervals = 0;
- for (const auto &Event : Events) {
- if (Event.Type == Event::ET_End)
- --OpenIntervals;
- // This has to be checked after removing the interval from the count if it
- // is an end event, or before adding it if it is a begin event.
- if (OpenIntervals != 0)
- Apply[Event.ErrorId] = false;
- if (Event.Type == Event::ET_Begin)
- ++OpenIntervals;
+ for (auto &FileAndEvents : FileEvents) {
+ std::vector<Event> &Events = FileAndEvents.second;
+ // Sweep.
+ std::sort(Events.begin(), Events.end());
+ int OpenIntervals = 0;
+ for (const auto &Event : Events) {
+ if (Event.Type == Event::ET_End)
+ --OpenIntervals;
+ // This has to be checked after removing the interval from the count if it
+ // is an end event, or before adding it if it is a begin event.
+ if (OpenIntervals != 0)
+ Apply[Event.ErrorId] = false;
+ if (Event.Type == Event::ET_Begin)
+ ++OpenIntervals;
+ }
+ assert(OpenIntervals == 0 && "Amount of begin/end points doesn't match");
}
- assert(OpenIntervals == 0 && "Amount of begin/end points doesn't match");
for (unsigned I = 0; I < Errors.size(); ++I) {
if (!Apply[I]) {
Added: clang-tools-extra/trunk/test/clang-tidy/Inputs/overlapping/o.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/Inputs/overlapping/o.h?rev=250523&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/Inputs/overlapping/o.h (added)
+++ clang-tools-extra/trunk/test/clang-tidy/Inputs/overlapping/o.h Fri Oct 16 11:15:27 2015
@@ -0,0 +1,9 @@
+// run: clang-tidy -checks=-*,llvm-include-order -header-filter=.* %s \
+// run: -- -isystem %S/Inputs/Headers -I %S/Inputs/overlapping | \
+// run: not grep "note: this fix will not be applied because it overlaps with another fix"
+
+#include "b.h"
+#include "a.h"
+
+// The comments above are there to match the offset of the #include with the
+// offset of the #includes in the .cpp file.
Added: clang-tools-extra/trunk/test/clang-tidy/overlapping.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/overlapping.cpp?rev=250523&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/overlapping.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/overlapping.cpp Fri Oct 16 11:15:27 2015
@@ -0,0 +1,10 @@
+// RUN: clang-tidy -checks=-*,llvm-include-order -header-filter=.* %s \
+// RUN: -- -isystem %S/Inputs/Headers -I %S/Inputs/overlapping | \
+// RUN: not grep "note: this fix will not be applied because it overlaps with another fix"
+
+#include <s.h>
+#include "o.h"
+
+// Test that clang-tidy takes into account in which file we are doing the
+// replacements to determine if they overlap or not. In the file "o.h" there is
+// a similar error at the same file offset, but they do not overlap.
More information about the cfe-commits
mailing list