ymandel created this revision.
ymandel added a reviewer: alexfh.
Herald added a subscriber: xazax.hun.
ymandel requested review of this revision.
Herald added a project: clang.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96542

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


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -104,7 +104,8 @@
       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;
     }
 }


Index: clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
+++ clang-tools-extra/clang-tidy/utils/TransformerClangTidyCheck.cpp
@@ -104,7 +104,8 @@
       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;
     }
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to