[flang] Replace manual mmap with llvm::MemoryBuffer
authorDavid Truby <david.truby@arm.com>
Thu, 27 Feb 2020 13:42:56 +0000 (13:42 +0000)
committerDavid Truby <david.truby@arm.com>
Tue, 24 Mar 2020 13:35:01 +0000 (13:35 +0000)
commit13ea73e42db3685091b1028991cf9f68d07fd7ac
treeacc4dcaa936b32df4e3a29b5a6f0f9aa3a22001d
parent901198441ffa6dea0953bcef4bc5c238708b384a
[flang] Replace manual mmap with llvm::MemoryBuffer

The previous code had handling for cases when too many file descriptors may be
opened; this is not necessary with MemoryBuffer as the file descriptors are
closed after the mapping occurs. MemoryBuffer also internally handles the case
where a file is small and therefore an mmap is bad for performance; such files
are simply copied to memory after being opened.

Many places elsewhere in the code assume that the buffer is not empty, and the
old file opening code handles this by replacing an empty file with a buffer
containing a single newline. That behavior is now kept in the new MemoryBuffer
based code.

Original-commit: flang-compiler/f18@d34df8435127d847867e2c0bb157def9f20f4202
Reviewed-on: https://github.com/flang-compiler/f18/pull/1032
flang/include/flang/Parser/source.h
flang/lib/Parser/prescan.cpp
flang/lib/Parser/provenance.cpp
flang/lib/Parser/source.cpp
flang/lib/Semantics/mod-file.cpp
flang/test/Semantics/empty.f90 [new file with mode: 0644]