Unverified Commit fd2d5add authored by kadir çetinkaya's avatar kadir çetinkaya Committed by GitHub
Browse files

[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.
parent de176d8c
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -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:
      if (IncludedFile)
        Out->IWYUExportBy[IncludedFile->getUniqueID()].push_back(Top.Path);
      if (IncludedHeader && IncludedHeader->kind() == Header::Standard)
        Out->StdIWYUExportBy[IncludedHeader->standard()].push_back(Top.Path);
          break;
        case Header::Verbatim:
          assert(false && "unexpected Verbatim header");
          break;
        }
      }
      // main-file #include with export pragma should never be removed.
      if (Top.SeenAtFile == SM.getMainFileID() && IncludedFile)
        Out->ShouldKeep.insert(IncludedFile->getUniqueID());
+2 −0
Original line number Diff line number Diff line
@@ -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) {