[all-commits] [llvm/llvm-project] 92e8af: [Clang] Expose RequiresNullTerminator in FileManager.

Michael Spencer via All-commits all-commits at lists.llvm.org
Wed Apr 15 14:18:20 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 92e8af0ecbe7eb36bc03a211afa9151c81b7b531
      https://github.com/llvm/llvm-project/commit/92e8af0ecbe7eb36bc03a211afa9151c81b7b531
  Author: Michael Spencer <bigcheesegs at gmail.com>
  Date:   2020-04-15 (Wed, 15 Apr 2020)

  Changed paths:
    M clang/include/clang/Basic/FileManager.h
    M clang/lib/Basic/FileManager.cpp
    M llvm/lib/Support/MemoryBuffer.cpp
    M llvm/unittests/Support/MemoryBufferTest.cpp

  Log Message:
  -----------
  [Clang] Expose RequiresNullTerminator in FileManager.

This is needed to fix the reason
0a2be46cfdb698fe (Modules: Invalidate out-of-date PCMs as they're
discovered) and 5b44a4b07fc1d ([modules] Do not cache invalid state for
modules that we attempted to load.) were reverted.

These patches changed Clang to use `isVolatile` when loading modules.
This had the side effect of not using mmap when loading modules, and
thus greatly increased memory usage.

The reason it wasn't using mmap is because `MemoryBuffer` plays some
games with file size when you request null termination, and it has to
disable these when `isVolatile` is set as the size may change by the
time it's mmapped. Clang by default passes
`RequiresNullTerminator = true`, and `shouldUseMmap` ignored if
`RequiresNullTerminator` was even requested.

This patch adds `RequiresNullTerminator` to the `FileManager` interface
so Clang can use it when loading modules, and changes `shouldUseMmap` to
only take volatility into account if `RequiresNullTerminator` is true.
This is fine as both `mmap` and a `read` loop are vulnerable to
modifying the file while reading, but are immune to the rename Clang
does when replacing a module file.

Differential Revision: https://reviews.llvm.org/D77772




More information about the All-commits mailing list