[clang-tools-extra] 33f35a4 - [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include insertions.

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 12 08:24:42 PST 2021


Author: Yitzhak Mandelbaum
Date: 2021-02-12T16:23:53Z
New Revision: 33f35a4b793bb53b830f8893110af57672e1dc79

URL: https://github.com/llvm/llvm-project/commit/33f35a4b793bb53b830f8893110af57672e1dc79
DIFF: https://github.com/llvm/llvm-project/commit/33f35a4b793bb53b830f8893110af57672e1dc79.diff

LOG: [clang-tidy] Fix `TransformerClangTidyCheck`'s handling of include insertions.

Currently, all include insertions are directed to the main file. However,
Transformer rules can specify alternative destinations for include
insertions. This patch fixes the code to associate the include with the correct
file.

This patch was tested manually. The clang tidy unit test framework does not
support testing changes to header files. Given that this is a bug fix for a live
bug, the patch relies on manual testing rather than blocking on upgrading the
unit test framework.

Differential Revision: https://reviews.llvm.org/D96542

Added: 
    

Modified: 
    clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
index e93f3fbf21d7..9f64c562600b 100644
--- a/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -104,7 +104,8 @@ void TransformerClangTidyCheck::check(
       Diag << FixItHint::CreateReplacement(T.Range, T.Replacement);
       break;
     case transformer::EditKind::AddInclude:
-      Diag << Inserter.createMainFileIncludeInsertion(T.Replacement);
+      Diag << Inserter.createIncludeInsertion(
+          Result.SourceManager->getFileID(T.Range.getBegin()), T.Replacement);
       break;
     }
 }


        


More information about the cfe-commits mailing list