[clang] Use IsVolatile=true and RequiresNullTerminator=false for PCMs
authorMichael Spencer <bigcheesegs@gmail.com>
Wed, 10 Jun 2020 20:37:03 +0000 (14:37 -0600)
committerMichael Spencer <bigcheesegs@gmail.com>
Wed, 10 Jun 2020 20:37:30 +0000 (14:37 -0600)
This change got missed while upstreaming
https://reviews.llvm.org/D77772. This is the part of that change that
actually passes the correct arguments when opening a PCM.

The test didn't catch this because it starts at the
`MemoryBuffer::getOpenFile` level. It's not really possible to test
`ModuleManager::addModule` itself to verify how the file was opened.

clang/lib/Serialization/ModuleManager.cpp

index 2656220..a42ed2f 100644 (file)
@@ -185,7 +185,14 @@ ModuleManager::addModule(StringRef FileName, ModuleKind Type,
       Buf = llvm::MemoryBuffer::getSTDIN();
     } else {
       // Get a buffer of the file and close the file descriptor when done.
-      Buf = FileMgr.getBufferForFile(NewModule->File, /*isVolatile=*/false);
+      // The file is volatile because in a parallel build we expect multiple
+      // compiler processes to use the same module file rebuilding it if needed.
+      //
+      // RequiresNullTerminator is false because module files don't need it, and
+      // this allows the file to still be mmapped.
+      Buf = FileMgr.getBufferForFile(NewModule->File,
+                                     /*IsVolatile=*/true,
+                                     /*RequiresNullTerminator=*/false);
     }
 
     if (!Buf) {