summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/MemoryBufferTest.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [Support] Improve readNativeFile(Slice) interfacePavel Labath2019-08-221-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: There was a subtle, but pretty important difference between the Slice and regular versions of this function. The Slice function was zero-initializing the rest of the buffer when the read syscall returned less bytes than expected, while the regular function did not. This patch removes the inconsistency by making both functions *not* zero-initialize the buffer. The zeroing code is moved to the MemoryBuffer class, which is currently the only user of this code. This makes the API more consistent, and the code shorter. While in there, I also refactor the functions to return the number of bytes through the regular return value (via Expected<size_t>) instead of a separate by-ref argument. Reviewers: aganea, rnk Subscribers: kristina, Bigcheese, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66471 llvm-svn: 369627
* Recommit "MemoryBuffer: Add a missing error-check to getOpenFileImpl"Pavel Labath2019-08-201-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | This recommits r368977, which was reverted in r369027 due to test failures in lldb. The cause of this was different behavior of readNativeFileSlice on windows and unix. These have been addressed in r369269. The original commit message was: In case the function was called with a desired read size *and* the file was not an "mmap()" candidate, the function was falling back to a "pread()", but it was failing to check the result of that system call. This meant that the function would return "success" even though the read operation failed, and it returned a buffer full of uninitialized memory. Reviewers: rnk, dblaikie Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66224 llvm-svn: 369370
* Revert "MemoryBuffer: Add a missing error-check to getOpenFileImpl"Pavel Labath2019-08-151-51/+0
| | | | | | This reverts commit r368977 because it broke a couple of tests in lldb. llvm-svn: 369027
* MemoryBuffer: Add a missing error-check to getOpenFileImplPavel Labath2019-08-151-0/+51
| | | | | | | | | | | | | | | | | | | Summary: In case the function was called with a desired read size *and* the file was not an "mmap()" candidate, the function was falling back to a "pread()", but it was failing to check the result of that system call. This meant that the function would return "success" even though the read operation failed, and it returned a buffer full of uninitialized memory. Reviewers: rnk, dblaikie Subscribers: kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66224 llvm-svn: 368977
* [Support] Move llvm::MemoryBuffer to sys::fs::file_tReid Kleckner2019-07-101-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: On Windows, Posix integer file descriptors are a compatibility layer over native file handles provided by the C runtime. There is a hard limit on the maximum number of file descriptors that a process can open, and the limit is 8192. LLD typically doesn't run into this limit because it opens input files, maps them into memory, and then immediately closes the file descriptor. This prevents it from running out of FDs. For various reasons, I'd like to open handles to every input file and keep them open during linking. That requires migrating MemoryBuffer over to taking open native file handles instead of integer FDs. Reviewers: aganea, Bigcheese Reviewed By: aganea Subscribers: smeenai, silvas, mehdi_amini, hiraditya, steven_wu, dexonsmith, dang, llvm-commits, zturner Tags: #llvm Differential Revision: https://reviews.llvm.org/D63453 llvm-svn: 365588
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* [Support] Pacify -Wsign-compare in unit test.Benjamin Kramer2018-03-081-2/+2
| | | | llvm-svn: 327070
* [Support] Add WriteThroughMemoryBuffer.Zachary Turner2018-03-081-0/+29
| | | | | | | | | | | This is like MemoryBuffer (read-only) and WritableMemoryBuffer (writable private), but where the underlying file can be modified after writing. This is useful when you want to open a file, make some targeted edits, and then write it back out. Differential Revision: https://reviews.llvm.org/D44230 llvm-svn: 327057
* [Support] Add WritableMemoryBuffer::getNewMemBufferPavel Labath2018-01-091-2/+2
| | | | | | | | | | | | | | | | | | Summary: The idea is that it would replace (non-Writable)MemoryBuffer::getNewMemBuffer, which is quite useless unless you const_cast its contents to write to it (which all (both) callers of this function were doing). This patch also fixes one of the usages in COFFWriter. After fixing the other usage in clang, I plan to delete the old function. Reviewers: dblaikie, Bigcheese Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41540 llvm-svn: 322094
* [Support] Remove MemoryBuffer::getNewUninitMemBufferPavel Labath2017-12-211-3/+3
| | | | | | | | | | | There is nothing useful that can be done with a read-only uninitialized buffer without const_casting its contents to initialize it. A better solution is to obtain a writable buffer (WritableMemoryBuffer::getNewUninitMemBuffer), and then convert it to a read-only buffer after initialization. All callers of this function have already been updated to do this, so this function is now unused. llvm-svn: 321257
* [Support] Add WritableMemoryBuffer classPavel Labath2017-12-191-0/+34
| | | | | | | | | | | | | | | | | | | | | | | | Summary: The motivation here is LLDB, where we need to fixup relocations in mmapped files before their contents can be read correctly. The MemoryBuffer class does exactly what we need, *except* that it maps the file in read-only mode. WritableMemoryBuffer reuses the existing machinery for opening and mmapping a file. The only difference is in the argument to the mapped_file_region constructor -- we create a private copy-on-write mapping, so that we can make changes to the mapped data, but the changes aren't carried over to the underlying file. This patch is based on an initial version by Zachary Turner. Reviewers: mehdi_amini, rnk, rafael, dblaikie, zturner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40291 llvm-svn: 321071
* Re-sort #include lines for unittests. This uses a slightly modifiedChandler Carruth2017-06-061-1/+1
| | | | | | | | | | | | | | | clang-format (https://reviews.llvm.org/D33932) to keep primary headers at the top and handle new utility headers like 'gmock' consistently with other utility headers. No other change was made. I did no manual edits, all of this is clang-format. This should allow other changes to have more clear and focused diffs, and is especially motivated by moving some headers into more focused libraries. llvm-svn: 304786
* Try to fix some temp file leaks in SupportTests, PR18335Reid Kleckner2016-09-021-0/+4
| | | | llvm-svn: 280443
* Remove excess white spaceRafael Espindola2015-11-181-6/+0
| | | | llvm-svn: 253408
* Add MemoryBufferRef(MemoryBuffer&) constructor.Rafael Espindola2015-11-171-0/+9
| | | | | | patch by Jonathan Anderson! llvm-svn: 253311
* Use 'override/final' instead of 'virtual' for overridden methodsAlexander Kornienko2015-04-111-1/+1
| | | | | | | | | | | | | | The patch is generated using clang-tidy misc-use-override check. This command was used: tools/clang/tools/extra/clang-tidy/tool/run-clang-tidy.py \ -checks='-*,misc-use-override' -header-filter='llvm|clang' \ -j=32 -fix -format http://reviews.llvm.org/D8925 llvm-svn: 234679
* [Support] Add MemoryBuffer::getFileSlice()Nick Kledzik2014-10-081-0/+50
| | | | | | | | | | mach-o supports "fat" files which are a header/table-of-contents followed by a concatenation of mach-o files built for different architectures. Currently, MemoryBuffer has no easy way to map a subrange (slice) of a file which lld will need to select a mach-o slice of a fat file. The new function provides an easy way to map a slice of a file into a MemoryBuffer. Test case included. llvm-svn: 219260
* Update the MemoryBuffer API to use ErrorOr.Rafael Espindola2014-07-061-7/+8
| | | | llvm-svn: 212405
* Remove the last uses of 'using std::error_code'Rafael Espindola2014-06-131-6/+6
| | | | | | This finishes the transition to std::error_code. llvm-svn: 210877
* Don't use 'using std::error_code' in include/llvm.Rafael Espindola2014-06-121-0/+1
| | | | | | This should make sure that most new uses use the std prefix. llvm-svn: 210835
* [C++11] Use 'nullptr'.Craig Topper2014-06-081-10/+10
| | | | llvm-svn: 210442
* Use std::unique_ptr instead of OwningPtr in the MemoryBuffer unittests.Craig Topper2014-05-181-2/+1
| | | | llvm-svn: 209102
* [C++11] Add overloads for externally used OwningPtr functions.Ahmed Charles2014-03-051-1/+1
| | | | | | | | This will allow external callers of these functions to switch over time rather than forcing a breaking change all a once. These particular functions were determined by building clang/lld/lldb. llvm-svn: 202959
* Re-sort all of the includes with ./utils/sort_includes.py so thatChandler Carruth2014-01-071-1/+1
| | | | | | | | | | subsequent changes are easier to review. About to fix some layering issues, and wanted to separate out the necessary churn. Also comment and sink the include of "Windows.h" in three .inc files to match the usage in Memory.inc. llvm-svn: 198685
* Change MemoryBuffer::getFile to take a Twine.Rafael Espindola2013-10-251-1/+1
| | | | llvm-svn: 193429
* MemoryBufer: add a test: check that a file with size that is a multiple of theDmitri Gribenko2013-09-041-0/+22
| | | | | | page size can be null terminated correctly by MemoryBuffer. llvm-svn: 189965
* [Win32] mapped_file_region: Fix a bug in CreateFileMapping() that Size must ↵NAKAMURA Takumi2013-08-221-5/+0
| | | | | | contain Offset when Offset >= 65536. llvm-svn: 189021
* Whitespace.NAKAMURA Takumi2013-08-221-1/+1
| | | | llvm-svn: 189020
* Suppress MemoryBufferTest.cpp on win32 for now. Investigating.NAKAMURA Takumi2013-08-221-0/+5
| | | | llvm-svn: 189001
* MemoryBufferTest.cpp: Tweak offset corresponding to the case that PageSize ↵NAKAMURA Takumi2013-08-221-1/+1
| | | | | | | | is greater than 8000. PageSize, aka AllocationGranularity, is 65536 on Win32 (and Cygwin). llvm-svn: 188999
* Refactor the unit test for MemoryBuffer::getOpenFileSliceEli Bendersky2013-07-231-6/+27
| | | | | | | Run in two different modes: with and without reopening the temporary file between creating it and mapping it with MemoryBuffer. llvm-svn: 186986
* Split getOpenFile into getOpenFile and getOpenFileSlice.Rafael Espindola2013-07-231-7/+4
| | | | | | | | | | | | | | | | The main observation is that we never need both the filesize and the map size. When mapping a slice of a file, it doesn't make sense to request a null terminator and that would be the only case where the filesize would be used. There are other cleanups that should be done in this area: * A client should not have to pass the size (even an explicit -1) to say if it wants a null terminator or not, so we should probably swap the argument order. * The default should be to not require a null terminator. Very few clients require this, but many end up asking for it just because it is the default. llvm-svn: 186984
* Add a simple unit test for MemoryBuffer::getOpenFileEli Bendersky2013-07-221-0/+33
| | | | llvm-svn: 186887
* Sort the #include lines for unittest/...Chandler Carruth2012-12-041-1/+0
| | | | llvm-svn: 169250
* Adding MCJIT and MemoryBuffer unit testsAndrew Kaylor2012-10-041-0/+99
Patch by Daniel Malea. llvm-svn: 165246
OpenPOWER on IntegriCloud