diff --git a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h --- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h +++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Record.h @@ -90,12 +90,15 @@ IWYUPublic; /// A reverse map from the underlying header to its exporter headers. - // - // There's no way to get a FileEntry from a UniqueID, especially when it - // hasn't been opened before. So store the full path and convert it to a - // FileEntry by opening the file again through a FileManager. + /// + /// There's no way to get a FileEntry from a UniqueID, especially when it + /// hasn't been opened before. So store the path and convert it to a + /// FileEntry by opening the file again through a FileManager. + /// + /// We don't use RealPathName, as opening the file through a different name + /// changes its preferred name. Clearly this is fragile! llvm::DenseMap> + llvm::SmallVector> IWYUExportBy; /// Contains all non self-contained files detected during the parsing. diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -204,7 +204,7 @@ Top.SeenAtLine == HashLine) { if (IncludedHeader) Out->IWYUExportBy[IncludedHeader->getUniqueID()].push_back( - Top.FullPath); + Top.Path); // main-file #include with export pragma should never be removed. if (Top.SeenAtFile == SM.getMainFileID()) Out->ShouldKeep.insert(HashLine); @@ -251,14 +251,13 @@ SM.getFileOffset(Range.getBegin())); // Record export pragma. if (Pragma->startswith("export")) { - ExportStack.push_back( - {CommentLine, CommentFID, - save(SM.getFileEntryForID(CommentFID)->tryGetRealPathName()), - false}); + ExportStack.push_back({CommentLine, CommentFID, + save(SM.getFileEntryForID(CommentFID)->getName()), + false}); } else if (Pragma->startswith("begin_exports")) { - ExportStack.push_back( - {CommentLine, CommentFID, - save(SM.getFileEntryForID(CommentFID)->tryGetRealPathName()), true}); + ExportStack.push_back({CommentLine, CommentFID, + save(SM.getFileEntryForID(CommentFID)->getName()), + true}); } else if (Pragma->startswith("end_exports")) { // FIXME: be robust on unmatching cases. We should only pop the stack if // the begin_exports and end_exports is in the same file. @@ -297,8 +296,8 @@ int SeenAtLine = 0; // 1-based line number. // The file where we saw the pragma. FileID SeenAtFile; - // FullPath of the file SeenAtFile. - StringRef FullPath; + // Name (per FileEntry::getName()) of the file SeenAtFile. + StringRef Path; // true if it is a block begin/end_exports pragma; false if it is a // single-line export pragma. bool Block = false;