aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/FrontendAction.cpp
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2020-04-21 15:30:54 -0700
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2020-04-21 15:45:54 -0700
commitd892eec710caae84099f38fdb89d32ca15a23c1a (patch)
tree27d8a596bbe74893ed5649d0dcb40ddf896ba20e /clang/lib/Frontend/FrontendAction.cpp
parent01d2a01e79d3d83f18cf3e54c2bf55bba523b77a (diff)
downloadllvm-d892eec710caae84099f38fdb89d32ca15a23c1a.zip
llvm-d892eec710caae84099f38fdb89d32ca15a23c1a.tar.gz
llvm-d892eec710caae84099f38fdb89d32ca15a23c1a.tar.bz2
Reapply: Make header inclusion order from umbrella dirs deterministic
Sort the headers by name before adding the includes in collectModuleHeaderIncludes. This makes the include order for building umbrellas deterministic across different filesystems and also guarantees that the ASTWriter always dump top headers in the same order. There's currently no good way to test for this behavior. This was first introduced in r289478 and reverted few times because of ASANifed test failures on open source bots (both from LLVM and Swift). Finally reproduced the problem in a Linux machine and use std::sort as a fix, since we are not dealing with POD-like types. rdar://problem/28116411
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r--clang/lib/Frontend/FrontendAction.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 6168057..dc361b2 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -364,6 +364,7 @@ static std::error_code collectModuleHeaderIncludes(
llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);
llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
+ SmallVector<std::pair<std::string, const FileEntry *>, 8> Headers;
for (llvm::vfs::recursive_directory_iterator Dir(FS, DirNative, EC), End;
Dir != End && !EC; Dir.increment(EC)) {
// Check whether this entry has an extension typically associated with
@@ -394,13 +395,25 @@ static std::error_code collectModuleHeaderIncludes(
++It)
llvm::sys::path::append(RelativeHeader, *It);
- // Include this header as part of the umbrella directory.
- Module->addTopHeader(*Header);
- addHeaderInclude(RelativeHeader, Includes, LangOpts, Module->IsExternC);
+ std::string RelName = RelativeHeader.c_str();
+ Headers.push_back(std::make_pair(RelName, *Header));
}
if (EC)
return EC;
+
+ // Sort header paths and make the header inclusion order deterministic
+ // across different OSs and filesystems.
+ llvm::sort(Headers.begin(), Headers.end(), [](
+ const std::pair<std::string, const FileEntry *> &LHS,
+ const std::pair<std::string, const FileEntry *> &RHS) {
+ return LHS.first < RHS.first;
+ });
+ for (auto &H : Headers) {
+ // Include this header as part of the umbrella directory.
+ Module->addTopHeader(H.second);
+ addHeaderInclude(H.first, Includes, LangOpts, Module->IsExternC);
+ }
}
// Recurse into submodules.