[clang] [clang][modules] Use file name as requested (PR #68957)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 13 15:58:34 PDT 2023


================
@@ -1384,10 +1384,10 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context,
       SmallVector<FileEntryRef, 1> ModMaps(AdditionalModMaps->begin(),
                                            AdditionalModMaps->end());
       llvm::sort(ModMaps, [](FileEntryRef A, FileEntryRef B) {
-        return A.getName() < B.getName();
+        return A.getNameAsRequested() < B.getNameAsRequested();
       });
       for (FileEntryRef F : ModMaps)
-        AddPath(F.getName(), Record);
+        AddPath(F.getNameAsRequested(), Record);
----------------
jansvoboda11 wrote:

Yeah, this is a bit suspicious. This test started failing downstream after de85739ded2 and this change appeared to be required to fix things.

Turns out `llvm::SmallPtrSet<FileEntryRef, 1>` determines equality of elements based on the equality of their `void *` representation, not based on `FileEntryRef::operator==()`. This means that when we find the module map through a VFS, but serialize the on-disk path, we aren't able to correctly match them together in `ASTReader`.

I don't want to go messing with the `SmallPtrSet` implementation, so I'll probably just revert [D154905](https://reviews.llvm.org/D154905) (making the types unusable in `SmallPtrSet`) and switch from `llvm::SmallPtrSet<FileEntryRef, 1>` to  `llvm::DenseMap<FileEntryRef>`.

https://github.com/llvm/llvm-project/pull/68957


More information about the cfe-commits mailing list