r289478 - [Modules] Make header inclusion order from umbrella dirs deterministic

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 12 14:41:21 PST 2016


Author: bruno
Date: Mon Dec 12 16:41:20 2016
New Revision: 289478

URL: http://llvm.org/viewvc/llvm-project?rev=289478&view=rev
Log:
[Modules] 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.

rdar://problem/28116411

Modified:
    cfe/trunk/lib/Frontend/FrontendActions.cpp

Modified: cfe/trunk/lib/Frontend/FrontendActions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendActions.cpp?rev=289478&r1=289477&r2=289478&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/FrontendActions.cpp (original)
+++ cfe/trunk/lib/Frontend/FrontendActions.cpp Mon Dec 12 16:41:20 2016
@@ -233,6 +233,7 @@ collectModuleHeaderIncludes(const LangOp
     llvm::sys::path::native(UmbrellaDir.Entry->getName(), DirNative);
 
     vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem();
+    SmallVector<std::pair<std::string, const FileEntry *>, 8> Headers;
     for (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 
@@ -263,13 +264,20 @@ collectModuleHeaderIncludes(const LangOp
            ++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);
+      Headers.push_back(std::make_pair(RelativeHeader.str(), Header));
     }
 
     if (EC)
       return EC;
+
+    // Sort header paths and make the header inclusion order deterministic
+    // across different OSs and filesystems.
+    llvm::array_pod_sort(Headers.begin(), Headers.end());
+    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.




More information about the cfe-commits mailing list