diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1282,7 +1282,11 @@ if (auto *AdditionalModMaps = Map.getAdditionalModuleMapFiles(WritingModule)) { Record.push_back(AdditionalModMaps->size()); - for (const FileEntry *F : *AdditionalModMaps) + SmallVector ModMaps(AdditionalModMaps->begin(), AdditionalModMaps->end()); + llvm::sort(ModMaps, [](const FileEntry *A, const FileEntry *B) { + return A->getName() < B->getName(); + }); + for (const FileEntry *F : ModMaps) AddPath(F->getName(), Record); } else { Record.push_back(0);