summaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitstreamReader.cpp
AgeCommit message (Collapse)Author
2019-07-03[Bitcode] Move Bitstream to a separate libraryFrancis Visoiu Mistrih
This moves Bitcode/Bitstream*, Bitcode/BitCodes.h to Bitstream/. This is needed to avoid a circular dependency when using the bitstream code for parsing optimization remarks. Since Bitcode uses Core for the IR part: libLLVMRemarks -> Bitcode -> Core and Core uses libLLVMRemarks to generate remarks (see IR/RemarkStreamer.cpp): Core -> libLLVMRemarks we need to separate the Bitstream and Bitcode part. For clang-doc, it seems that it doesn't need the whole bitcode layer, so I updated the CMake to only use the bitstream part. Differential Revision: https://reviews.llvm.org/D63899 llvm-svn: 365091
2019-06-26BitStream reader: propagate errorsJF Bastien
The bitstream reader handles errors poorly. This has two effects: * Bugs in file handling (especially modules) manifest as an "unexpected end of file" crash * Users of clang as a library end up aborting because the code unconditionally calls `report_fatal_error` The bitstream reader should be more resilient and return Expected / Error as soon as an error is encountered, not way late like it does now. This patch starts doing so and adopting the error handling where I think it makes sense. There's plenty more to do: this patch propagates errors to be minimally useful, and follow-ups will propagate them further and improve diagnostics. https://bugs.llvm.org/show_bug.cgi?id=42311 <rdar://problem/33159405> Differential Revision: https://reviews.llvm.org/D63518 llvm-svn: 364464
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
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
2017-01-04Change BitstreamCursor::skipRecord to return the record code (NFC)Mehdi Amini
llvm-svn: 291026
2017-01-04Reapply "Make BitCodeAbbrev ownership explicit using shared_ptr rather than ↵David Blaikie
IntrusiveRefCntPtr"" If this is a problem for anyone (shared_ptr is two pointers in size, whereas IntrusiveRefCntPtr is 1 - and the ref count control block that make_shared adds is probably larger than the one int in RefCountedBase) I'd prefer to address this by adding a lower-overhead version of shared_ptr (possibly refactoring IntrusiveRefCntPtr into such a thing) to avoid the intrusiveness - this allows memory ownership to remain orthogonal to types and at least to me, seems to make code easier to understand (since no implicit ownership acquisition can happen). This recommits 291006, reverted in r291007. llvm-svn: 291016
2017-01-04Revert "Make BitCodeAbbrev ownership explicit using shared_ptr rather than ↵David Blaikie
IntrusiveRefCntPtr" Breaks Clang's use of bitcode. Reverting until I have a fix to go with it there. This reverts commit r291006. llvm-svn: 291007
2017-01-04Make BitCodeAbbrev ownership explicit using shared_ptr rather than ↵David Blaikie
IntrusiveRefCntPtr If this is a problem for anyone (shared_ptr is two pointers in size, whereas IntrusiveRefCntPtr is 1 - and the ref count control block that make_shared adds is probably larger than the one int in RefCountedBase) I'd prefer to address this by adding a lower-overhead version of shared_ptr (possibly refactoring IntrusiveRefCntPtr into such a thing) to avoid the intrusiveness - this allows memory ownership to remain orthogonal to types and at least to me, seems to make code easier to understand (since no implicit ownership acquisition can happen). llvm-svn: 291006
2016-12-01Bitcode: Correctly handle Fixed and VBR arrays in BitstreamCursor::skipRecord().Peter Collingbourne
The assertions were wrong; we need to call getEncodingData() on the element, not the array. While here, simplify the skipRecord() implementation for Fixed and Char6 arrays. This is tested by the code I added to llvm-bcanalyzer which makes sure that we can skip any record. Differential Revision: https://reviews.llvm.org/D27241 llvm-svn: 288315
2016-11-08Bitcode: Decouple block info block state from reader.Peter Collingbourne
As proposed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-October/106630.html Move block info block state to a new class, BitstreamBlockInfo. Clients may set the block info for a particular cursor with the BitstreamCursor::setBlockInfo() method. At this point BitstreamReader is not much more than a container for an ArrayRef<uint8_t>, so remove it and replace all uses with direct uses of memory buffers. Differential Revision: https://reviews.llvm.org/D26259 llvm-svn: 286207
2016-10-27BitcodeReader: Require clients to read the block info block at most once.Peter Collingbourne
This change makes it the client's responsibility to call ReadBlockInfoBlock() at most once. This is in preparation for a future change that will allow there to be multiple block info blocks. See also: http://lists.llvm.org/pipermail/llvm-dev/2016-October/106512.html Differential Revision: https://reviews.llvm.org/D26016 llvm-svn: 285350
2016-08-18[LLVM] Fix some Clang-tidy modernize-use-using and Include What You Use warningsEugene Zelenko
Differential revision: https://reviews.llvm.org/D23675 llvm-svn: 279102
2016-03-27Support: Implement StreamingMemoryObject::getPointerDuncan P. N. Exon Smith
The implementation is fairly obvious. This is preparation for using some blobs in bitcode. For clarity (and perhaps future-proofing?), I moved the call to JumpToBit in BitstreamCursor::readRecord ahead of calling MemoryObject::getPointer, since JumpToBit can theoretically (a) read bytes, which (b) invalidates the blob pointer. This isn't strictly necessary the two memory objects we have: - The return of RawMemoryObject::getPointer is valid until the memory object is destroyed. - StreamingMemoryObject::getPointer is valid until the next chunk is read from the stream. Since the JumpToBit call is only going ahead to a word boundary, we'll never load another chunk. However, reordering makes it clear by inspection that the blob returned by BitstreamCursor::readRecord will be valid. I added some tests for StreamingMemoryObject::getPointer and BitstreamCursor::readRecord. llvm-svn: 264549
2016-03-27Bitcode: Add SimpleBitstreamCursor::getPointerToByte, etc.Duncan P. N. Exon Smith
Add API to SimpleBitstreamCursor to allow users to translate between byte addresses and pointers. - jumpToPointer: move the bit position to a particular pointer. - getPointerToByte: get the pointer for a particular byte. - getPointerToBit: get the pointer for the byte of the current bit. - getCurrentByteNo: convenience function for assertions and tests. Mainly adds unit tests (getPointerToBit/Byte already has a use), but also preparation for eventually using jumpToPointer. llvm-svn: 264546
2016-03-27Bitcode: Split out SimpleBitstreamCursorDuncan P. N. Exon Smith
Split out SimpleBitstreamCursor from BitstreamCursor, which is a lower-level cursor with no knowledge of bitcode blocks, abbreviations, or records. It just knows how to read bits and navigate the stream. This is mainly organizational, to separate the API for manipulating raw bits from that for bitcode concepts like Record and Block. llvm-svn: 264545
2016-03-25Revert "Bitcode: Collect all MDString records into a single blob"Duncan P. N. Exon Smith
This reverts commit r264409 since it failed to bootstrap: http://lab.llvm.org:8080/green/job/clang-stage2-configure-Rlto_build/8302/ llvm-svn: 264410
2016-03-25Bitcode: Collect all MDString records into a single blobDuncan P. N. Exon Smith
Optimize output of MDStrings in bitcode. This emits them in big blocks (currently 1024) in a pair of records: - BULK_STRING_SIZES: the sizes of the strings in the block, and - BULK_STRING_DATA: a single blob, which is the concatenation of all the strings. Inspired by Mehdi's similar patch, http://reviews.llvm.org/D18342, this should (a) slightly reduce bitcode size, since there is less record overhead, and (b) greatly improve reading speed, since blobs are super cheap to deserialize. I needed to add support for blobs to streaming input to get the test suite passing. - StreamingMemoryObject::getPointer reads ahead and returns the address of the blob. - To avoid a possible reallocation of StreamingMemoryObject::Bytes, BitstreamCursor::readRecord needs to move the call to JumpToEnd forward so that getPointer is the last bitstream operation. llvm-svn: 264409
2016-03-07Bitcode reader: Inline readAbbreviatedField in readRecord and move the ↵Mehdi Amini
enclosing loop in each case (NFC) Summary: This make readRecord 20% faster, measured on an LTO build Reviewers: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D17911 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 262811
2015-05-27[BitstreamReader] Make sure the Array operand type is an encodingFilipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 238269
2015-05-27clang-format a couple of linesFilipe Cabecinhas
llvm-svn: 238268
2015-05-26[BitcodeReader] Make sure abbrev records have at least one operand (record code)Filipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 238265
2015-05-25Simplify boolean conditional return statements.Rafael Espindola
Patch by Richard <legalize@xmission.com> llvm-svn: 238134
2015-05-19[BitcodeReader] It's a malformed block if CodeLenWidth is too bigFilipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 237646
2015-04-29Turn an assert into report_fatal_error since it's reachable based on user inputFilipe Cabecinhas
Bug found with AFL fuzz. llvm-svn: 236076
2015-04-23Be more strict about the operand for the array type in BitcodeReaderFilipe Cabecinhas
Summary: Bug found with AFL fuzz. Reviewers: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9016 llvm-svn: 235596
2015-04-23Verify sizes when trying to read a BitcodeAbbrevOpFilipe Cabecinhas
Summary: Make sure the abbrev operands are valid and that we can read/skip them afterwards. Bug found with AFL fuzz. Reviewers: rafael Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9030 llvm-svn: 235595
2015-04-15Revert "Verify sizes when trying to read a VBR"Filipe Cabecinhas
This reverts r234984 since it seems to break some bots (most of them seemed arm*-selfhost). llvm-svn: 234998
2015-04-15Verify sizes when trying to read a VBRFilipe Cabecinhas
Also added an assert to ReadVBR64. llvm-svn: 234984
2015-03-09Simplify expressions involving boolean constants with clang-tidyDavid Blaikie
Patch by Richard (legalize at xmission dot com). Differential Revision: http://reviews.llvm.org/D8154 llvm-svn: 231617
2015-02-13Clean up some inappropriate choices of type in the bitcode reader. None ofRichard Smith
these are expected to fix any 64->32 bit real truncation issues. llvm-svn: 229153
2015-01-24[Bitcode] Diagnose errors instead of asserting from bad inputFilipe Cabecinhas
Eventually we can make some of these pass the error along to the caller. Reports a fatal error if: We find an invalid abbrev record We try to get an invalid abbrev number We can't fill the current word due to an EOF Fixed an invalid bitcode test to check for output with FileCheck Bugs found with afl-fuzz llvm-svn: 226986
2014-11-13Silence MSVC warning on missing return after fully covered switchReid Kleckner
llvm-svn: 221943
2014-11-13Move calls to push_back out of readAbbreviated(Literal|Field).Rafael Espindola
These functions always return a single value and not all callers want to push them into a SmallVector. llvm-svn: 221934
2014-11-13Make a few helper functions static. NFC.Rafael Espindola
llvm-svn: 221930
2014-11-06Factor out call to push_back. NFC.Rafael Espindola
llvm-svn: 221490
2014-09-15Use IntrusiveRefCntPtr to manage the lifetime of BitCodeAbbrevs.Benjamin Kramer
This doesn't change the interface or gives additional safety but removes a ton of retain/release boilerplate. No functionality change. llvm-svn: 217778
2014-06-18Replace some assert(0)'s with llvm_unreachable.Craig Topper
llvm-svn: 211141
2014-04-15[C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper
instead of comparing to nullptr. llvm-svn: 206252
2013-05-10Micro-optimization: don't shift an entire bitcode record over to get the code.Jordan Rose
Previously, BitstreamCursor read an abbreviated record by splatting the whole thing into a data vector, then extracting and removing the /first/ element. Now, it reads the first element--the record code--separately from the actual field values. No (intended) functionality change. llvm-svn: 181639
2013-04-01Whitespace cleanupJoe Abbey
llvm-svn: 178454
2013-02-19Simplify code. No functionality change.Jakub Staszak
llvm-svn: 175501
2013-02-09Fix the underlying problem that was causing read(0) to be called: sometimes theChris Lattner
bitcode writer would generate abbrev records saying that the abbrev should be filled with fixed zero-bit bitfields (this happens in the .bc writer when the number of types used in a module is exactly one, since log2(1) == 0). In this case, just handle it as a literal zero. We can't "just fix" the writer without breaking compatibility with existing bc files, so have the abbrev reader do the substitution. Strengthen the assert in read to reject reads of zero bits so we catch such crimes in the future, and remove the special case designed to handle this. llvm-svn: 174801
2013-02-06Code Custodian (trivial whitespace cleanup)Joe Abbey
llvm-svn: 174550
2013-01-21Fix a heinous inefficiency introduced in r149918, wherein reading each byte of aChris Lattner
BLOB (i.e., large, performance intensive data) in a bitcode file was switched to invoking one virtual method call per byte read. Now we do one virtual call per BLOB. llvm-svn: 173065
2013-01-21wean Blob handling logic off of banging on NextChar directly. Instead, makeChris Lattner
it reason about the current bit position, which is always independent of the underlying cursors word size. llvm-svn: 173063
2013-01-21rename "SkipToWord" to "SkipToFourByteBoundary" since a word is not always 4 ↵Chris Lattner
bytes. llvm-svn: 173062
2013-01-20convert the bitstream reader itself and the IR .bc file parser to use the ↵Chris Lattner
new advance() APIs, simplifying things and making a bunch of details more private to BitstreamCursor. llvm-svn: 172947
2013-01-20stringref'ize readRecord and properly capitalize it. Add a compatibility ↵Chris Lattner
method to easy the transition. llvm-svn: 172940
2013-01-20move some private methods out of line, add a skipRecord() method.Chris Lattner
llvm-svn: 172931
2013-01-19Add a new BitstreamEntry concept, and add two helper methods for walkingChris Lattner
through a BitstreamCursor that produce it: advance() and advanceSkippingSubblocks(), representing the two most common ways clients want to walk through bitcode. llvm-svn: 172919
2013-01-19BitstreamReader hasn't aged well. It's been hacked on by various people andChris Lattner
has past the point of making sense. Lets tidy things up: first step, moving a ton of big functions out of line. llvm-svn: 172904