[Support] Allow FileOutputBuffer::create to create an empty file
authorFangrui Song <maskray@google.com>
Mon, 4 May 2020 16:45:41 +0000 (09:45 -0700)
committerFangrui Song <maskray@google.com>
Tue, 5 May 2020 15:11:58 +0000 (08:11 -0700)
commit9d53db2aa098ca5136c352c38710ea48bf078e7a
treec4385325c7e8cb2914f553a112d0f29ec7ec6941
parent47f5066553240b1559eed06706688ed8cce56fe7
[Support] Allow FileOutputBuffer::create to create an empty file

Size==0 triggers `assert(Size != 0)` in mapped_file_region::init.
I plan to use an empty file in D79339 (llvm-objcopy --dump-section).

According to POSIX, "If len is zero, mmap() shall fail and no mapping
shall be established." Just specialize case Size=0 to use
createInMemoryBuffer.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D79338
llvm/lib/Support/FileOutputBuffer.cpp
llvm/unittests/Support/FileOutputBufferTest.cpp