| 121 | } |
| 122 | |
| 123 | static Expected<BitstreamCursor> initStream(MemoryBufferRef Buffer) { |
| 124 | const unsigned char *BufPtr = (const unsigned char *)Buffer.getBufferStart(); |
| 125 | const unsigned char *BufEnd = BufPtr + Buffer.getBufferSize(); |
| 126 | |
| 127 | if (Buffer.getBufferSize() & 3) |
| 128 | return error("Invalid bitcode signature"); |
| 129 | |
| 130 | // If we have a wrapper header, parse it and ignore the non-bc file contents. |
| 131 | // The magic number is 0x0B17C0DE stored in little endian. |
| 132 | if (isBitcodeWrapper(BufPtr, BufEnd)) |
| 133 | if (SkipBitcodeWrapperHeader(BufPtr, BufEnd, true)) |
| 134 | return error("Invalid bitcode wrapper header"); |
| 135 | |
| 136 | BitstreamCursor Stream(ArrayRef<uint8_t>(BufPtr, BufEnd)); |
| 137 | if (!hasValidBitcodeHeader(Stream)) |
| 138 | return error("Invalid bitcode signature"); |
| 139 | |
| 140 | return std::move(Stream); |
| 141 | } |
| 142 | |
| 143 | /// Convert a string from a record into an std::string, return true on failure. |
| 144 | template <typename StrTy> |
no test coverage detected