[PATCH] D23257: Fix clang-tidy crash when a single fix is applied on multiple files.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 8 07:04:03 PDT 2016


alexfh requested changes to this revision.
This revision now requires changes to proceed.

================
Comment at: clang-tidy/ClangTidy.cpp:129
@@ -128,22 +128,3 @@
                   << Message.Message << Name;
-      for (const tooling::Replacement &Fix : Error.Fix) {
-        // Retrieve the source range for applicable fixes. Macro definitions
-        // on the command line have locations in a virtual buffer and don't
-        // have valid file paths and are therefore not applicable.
-        SourceRange Range;
-        SourceLocation FixLoc;
-        if (Fix.isApplicable()) {
-          SmallString<128> FixAbsoluteFilePath = Fix.getFilePath();
-          Files.makeAbsolutePath(FixAbsoluteFilePath);
-          FixLoc = getLocation(FixAbsoluteFilePath, Fix.getOffset());
-          SourceLocation FixEndLoc = FixLoc.getLocWithOffset(Fix.getLength());
-          Range = SourceRange(FixLoc, FixEndLoc);
-          Diag << FixItHint::CreateReplacement(Range, Fix.getReplacementText());
-        }
-
-        ++TotalFixes;
-        if (ApplyFixes) {
-          bool Success = Fix.isApplicable() && Fix.apply(Rewrite);
-          if (Success)
-            ++AppliedFixes;
-          FixLocations.push_back(std::make_pair(FixLoc, Success));
+      for (const auto &FileAndFixes : Error.Fix) {
+        for (const auto &Fix : FileAndFixes.second) {
----------------
s/Fixes/Replacements/

================
Comment at: clang-tidy/ClangTidyDiagnosticConsumer.cpp:80
@@ -79,3 +79,3 @@
 
-      auto Err =
-          Error.Fix.add(tooling::Replacement(SM, Range, FixIt.CodeToInsert));
+      tooling::Replacement replace(SM, Range, FixIt.CodeToInsert);
+      auto Err = Error.Fix[replace.getFilePath()].add(replace);
----------------
nit: 1. `replace` is a verb; 2. variable names should start with a capital.

`Replacement` would be better.

================
Comment at: test/clang-tidy/modernize-pass-by-value-multi-fixes.cpp:1
@@ +1,2 @@
+// RUN: cp %S/Inputs/modernize-pass-by-value/header-with-fix.h %T/pass-by-value-header-with-fix.h
+// RUN: sed -e 's#//.*$##' %s > %t.cpp
----------------
I think, `cat x > y` is preferred over `cp x y` in lit tests as a more platform-agnostic way of copying files.


https://reviews.llvm.org/D23257





More information about the cfe-commits mailing list