https://github.com/kadircet updated https://github.com/llvm/llvm-project/pull/72246
From 84f320a1c746eddea3171bd984613464a5872cbb Mon Sep 17 00:00:00 2001 From: Kadir Cetinkaya <kadir...@google.com> Date: Tue, 14 Nov 2023 13:08:52 +0100 Subject: [PATCH] [include-cleaner] Make sure exports of stdlib also works for physical files This was creating discrepancy in cases where we might have a physical file entry (e.g. because we followed a source location from a stdlib file) and tried to find its exporters. --- .../include-cleaner/lib/Record.cpp | 18 ++++-------------- .../include-cleaner/unittests/RecordTest.cpp | 2 ++ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp index 7a8e10a9c675496..6e00ff93a7fe2fa 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -240,20 +240,10 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler { // Make sure current include is covered by the export pragma. if ((Top.Block && HashLine > Top.SeenAtLine) || Top.SeenAtLine == HashLine) { - if (IncludedHeader) { - switch (IncludedHeader->kind()) { - case Header::Physical: - Out->IWYUExportBy[IncludedHeader->physical().getUniqueID()] - .push_back(Top.Path); - break; - case Header::Standard: - Out->StdIWYUExportBy[IncludedHeader->standard()].push_back(Top.Path); - break; - case Header::Verbatim: - assert(false && "unexpected Verbatim header"); - break; - } - } + if (IncludedFile) + Out->IWYUExportBy[IncludedFile->getUniqueID()].push_back(Top.Path); + if (IncludedHeader && IncludedHeader->kind() == Header::Standard) + Out->StdIWYUExportBy[IncludedHeader->standard()].push_back(Top.Path); // main-file #include with export pragma should never be removed. if (Top.SeenAtFile == SM.getMainFileID() && IncludedFile) Out->ShouldKeep.insert(IncludedFile->getUniqueID()); diff --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp index 36850731d514539..dfefa66887b0f24 100644 --- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp @@ -452,6 +452,8 @@ TEST_F(PragmaIncludeTest, IWYUExportForStandardHeaders) { auto &FM = Processed.fileManager(); EXPECT_THAT(PI.getExporters(*tooling::stdlib::Header::named("<string>"), FM), testing::UnorderedElementsAre(FileNamed("export.h"))); + EXPECT_THAT(PI.getExporters(llvm::cantFail(FM.getFileRef("string")), FM), + testing::UnorderedElementsAre(FileNamed("export.h"))); } TEST_F(PragmaIncludeTest, IWYUExportBlock) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits