diff options
author | kadir çetinkaya <kadircet@google.com> | 2023-11-17 10:11:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-17 10:11:21 +0100 |
commit | fd2d5add437b2b324492b1bc29374699fe7b614b (patch) | |
tree | f98b476c947cc33e47487050811b1e963da36ea4 | |
parent | de176d8c5496d6cf20e82aface98e102c593dbe2 (diff) | |
download | llvm-fd2d5add437b2b324492b1bc29374699fe7b614b.zip llvm-fd2d5add437b2b324492b1bc29374699fe7b614b.tar.gz llvm-fd2d5add437b2b324492b1bc29374699fe7b614b.tar.bz2 |
[include-cleaner] Make sure exports of stdlib also works for physical files (#72246)
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.
-rw-r--r-- | clang-tools-extra/include-cleaner/lib/Record.cpp | 18 | ||||
-rw-r--r-- | clang-tools-extra/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 7a8e10a..6e00ff9 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -240,20 +240,10 @@ public: // 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 3685073..dfefa66 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) { |