aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Bitcode/Reader
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Bitcode/Reader')
-rw-r--r--lib/Bitcode/Reader/BitReader.cpp1
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.cpp136
-rw-r--r--lib/Bitcode/Reader/BitcodeReader.h11
-rw-r--r--lib/Bitcode/Reader/BitstreamReader.cpp15
4 files changed, 150 insertions, 13 deletions
diff --git a/lib/Bitcode/Reader/BitReader.cpp b/lib/Bitcode/Reader/BitReader.cpp
index 5cd6c55..23630e5 100644
--- a/lib/Bitcode/Reader/BitReader.cpp
+++ b/lib/Bitcode/Reader/BitReader.cpp
@@ -10,6 +10,7 @@
#include "llvm-c/BitReader.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/Module.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cstring>
#include <string>
diff --git a/lib/Bitcode/Reader/BitcodeReader.cpp b/lib/Bitcode/Reader/BitcodeReader.cpp
index f348843..e6d7b50 100644
--- a/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/AutoUpgrade.h"
+#include "llvm/Bitcode/LLVMBitCodes.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InlineAsm.h"
@@ -22,6 +23,7 @@
#include "llvm/Support/DataStream.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
enum {
@@ -405,7 +407,7 @@ Value *BitcodeReaderMDValueList::getValueFwdRef(unsigned Idx) {
}
// Create and return a placeholder, which will later be RAUW'd.
- Value *V = MDNode::getTemporary(Context, ArrayRef<Value*>());
+ Value *V = MDNode::getTemporary(Context, None);
MDValuePtrs[Idx] = V;
return V;
}
@@ -506,6 +508,125 @@ bool BitcodeReader::ParseAttributeBlock() {
}
}
+bool BitcodeReader::ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind) {
+ switch (Code) {
+ case bitc::ATTR_KIND_ALIGNMENT:
+ *Kind = Attribute::Alignment;
+ return false;
+ case bitc::ATTR_KIND_ALWAYS_INLINE:
+ *Kind = Attribute::AlwaysInline;
+ return false;
+ case bitc::ATTR_KIND_BUILTIN:
+ *Kind = Attribute::Builtin;
+ return false;
+ case bitc::ATTR_KIND_BY_VAL:
+ *Kind = Attribute::ByVal;
+ return false;
+ case bitc::ATTR_KIND_COLD:
+ *Kind = Attribute::Cold;
+ return false;
+ case bitc::ATTR_KIND_INLINE_HINT:
+ *Kind = Attribute::InlineHint;
+ return false;
+ case bitc::ATTR_KIND_IN_REG:
+ *Kind = Attribute::InReg;
+ return false;
+ case bitc::ATTR_KIND_MIN_SIZE:
+ *Kind = Attribute::MinSize;
+ return false;
+ case bitc::ATTR_KIND_NAKED:
+ *Kind = Attribute::Naked;
+ return false;
+ case bitc::ATTR_KIND_NEST:
+ *Kind = Attribute::Nest;
+ return false;
+ case bitc::ATTR_KIND_NO_ALIAS:
+ *Kind = Attribute::NoAlias;
+ return false;
+ case bitc::ATTR_KIND_NO_BUILTIN:
+ *Kind = Attribute::NoBuiltin;
+ return false;
+ case bitc::ATTR_KIND_NO_CAPTURE:
+ *Kind = Attribute::NoCapture;
+ return false;
+ case bitc::ATTR_KIND_NO_DUPLICATE:
+ *Kind = Attribute::NoDuplicate;
+ return false;
+ case bitc::ATTR_KIND_NO_IMPLICIT_FLOAT:
+ *Kind = Attribute::NoImplicitFloat;
+ return false;
+ case bitc::ATTR_KIND_NO_INLINE:
+ *Kind = Attribute::NoInline;
+ return false;
+ case bitc::ATTR_KIND_NON_LAZY_BIND:
+ *Kind = Attribute::NonLazyBind;
+ return false;
+ case bitc::ATTR_KIND_NO_RED_ZONE:
+ *Kind = Attribute::NoRedZone;
+ return false;
+ case bitc::ATTR_KIND_NO_RETURN:
+ *Kind = Attribute::NoReturn;
+ return false;
+ case bitc::ATTR_KIND_NO_UNWIND:
+ *Kind = Attribute::NoUnwind;
+ return false;
+ case bitc::ATTR_KIND_OPTIMIZE_FOR_SIZE:
+ *Kind = Attribute::OptimizeForSize;
+ return false;
+ case bitc::ATTR_KIND_READ_NONE:
+ *Kind = Attribute::ReadNone;
+ return false;
+ case bitc::ATTR_KIND_READ_ONLY:
+ *Kind = Attribute::ReadOnly;
+ return false;
+ case bitc::ATTR_KIND_RETURNED:
+ *Kind = Attribute::Returned;
+ return false;
+ case bitc::ATTR_KIND_RETURNS_TWICE:
+ *Kind = Attribute::ReturnsTwice;
+ return false;
+ case bitc::ATTR_KIND_S_EXT:
+ *Kind = Attribute::SExt;
+ return false;
+ case bitc::ATTR_KIND_STACK_ALIGNMENT:
+ *Kind = Attribute::StackAlignment;
+ return false;
+ case bitc::ATTR_KIND_STACK_PROTECT:
+ *Kind = Attribute::StackProtect;
+ return false;
+ case bitc::ATTR_KIND_STACK_PROTECT_REQ:
+ *Kind = Attribute::StackProtectReq;
+ return false;
+ case bitc::ATTR_KIND_STACK_PROTECT_STRONG:
+ *Kind = Attribute::StackProtectStrong;
+ return false;
+ case bitc::ATTR_KIND_STRUCT_RET:
+ *Kind = Attribute::StructRet;
+ return false;
+ case bitc::ATTR_KIND_SANITIZE_ADDRESS:
+ *Kind = Attribute::SanitizeAddress;
+ return false;
+ case bitc::ATTR_KIND_SANITIZE_THREAD:
+ *Kind = Attribute::SanitizeThread;
+ return false;
+ case bitc::ATTR_KIND_SANITIZE_MEMORY:
+ *Kind = Attribute::SanitizeMemory;
+ return false;
+ case bitc::ATTR_KIND_UW_TABLE:
+ *Kind = Attribute::UWTable;
+ return false;
+ case bitc::ATTR_KIND_Z_EXT:
+ *Kind = Attribute::ZExt;
+ return false;
+ default:
+ std::string Buf;
+ raw_string_ostream fmt(Buf);
+ fmt << "Unknown attribute kind (" << Code << ")";
+ fmt.flush();
+ return Error(Buf.c_str());
+ }
+}
+
bool BitcodeReader::ParseAttributeGroupBlock() {
if (Stream.EnterSubBlock(bitc::PARAMATTR_GROUP_BLOCK_ID))
return Error("Malformed block record");
@@ -545,9 +666,16 @@ bool BitcodeReader::ParseAttributeGroupBlock() {
AttrBuilder B;
for (unsigned i = 2, e = Record.size(); i != e; ++i) {
if (Record[i] == 0) { // Enum attribute
- B.addAttribute(Attribute::AttrKind(Record[++i]));
+ Attribute::AttrKind Kind;
+ if (ParseAttrKind(Record[++i], &Kind))
+ return true;
+
+ B.addAttribute(Kind);
} else if (Record[i] == 1) { // Align attribute
- if (Attribute::AttrKind(Record[++i]) == Attribute::Alignment)
+ Attribute::AttrKind Kind;
+ if (ParseAttrKind(Record[++i], &Kind))
+ return true;
+ if (Kind == Attribute::Alignment)
B.addAlignmentAttr(Record[++i]);
else
B.addStackAlignmentAttr(Record[++i]);
@@ -3010,7 +3138,7 @@ bool BitcodeReader::InitLazyStream() {
Stream.init(*StreamFile);
unsigned char buf[16];
- if (Bytes->readBytes(0, 16, buf, NULL) == -1)
+ if (Bytes->readBytes(0, 16, buf) == -1)
return Error("Bitcode stream must be at least 16 bytes in length");
if (!isBitcode(buf, buf + 16))
diff --git a/lib/Bitcode/Reader/BitcodeReader.h b/lib/Bitcode/Reader/BitcodeReader.h
index 28674eb..b095447 100644
--- a/lib/Bitcode/Reader/BitcodeReader.h
+++ b/lib/Bitcode/Reader/BitcodeReader.h
@@ -258,7 +258,7 @@ private:
/// getValueTypePair - Read a value/type pair out of the specified record from
/// slot 'Slot'. Increment Slot past the number of slots used in the record.
/// Return true on failure.
- bool getValueTypePair(SmallVector<uint64_t, 64> &Record, unsigned &Slot,
+ bool getValueTypePair(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
unsigned InstNum, Value *&ResVal) {
if (Slot == Record.size()) return true;
unsigned ValNo = (unsigned)Record[Slot++];
@@ -282,7 +282,7 @@ private:
/// popValue - Read a value out of the specified record from slot 'Slot'.
/// Increment Slot past the number of slots used by the value in the record.
/// Return true if there is an error.
- bool popValue(SmallVector<uint64_t, 64> &Record, unsigned &Slot,
+ bool popValue(SmallVectorImpl<uint64_t> &Record, unsigned &Slot,
unsigned InstNum, Type *Ty, Value *&ResVal) {
if (getValue(Record, Slot, InstNum, Ty, ResVal))
return true;
@@ -292,7 +292,7 @@ private:
}
/// getValue -- Like popValue, but does not increment the Slot number.
- bool getValue(SmallVector<uint64_t, 64> &Record, unsigned Slot,
+ bool getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
unsigned InstNum, Type *Ty, Value *&ResVal) {
ResVal = getValue(Record, Slot, InstNum, Ty);
return ResVal == 0;
@@ -300,7 +300,7 @@ private:
/// getValue -- Version of getValue that returns ResVal directly,
/// or 0 if there is an error.
- Value *getValue(SmallVector<uint64_t, 64> &Record, unsigned Slot,
+ Value *getValue(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
unsigned InstNum, Type *Ty) {
if (Slot == Record.size()) return 0;
unsigned ValNo = (unsigned)Record[Slot];
@@ -311,7 +311,7 @@ private:
}
/// getValueSigned -- Like getValue, but decodes signed VBRs.
- Value *getValueSigned(SmallVector<uint64_t, 64> &Record, unsigned Slot,
+ Value *getValueSigned(SmallVectorImpl<uint64_t> &Record, unsigned Slot,
unsigned InstNum, Type *Ty) {
if (Slot == Record.size()) return 0;
unsigned ValNo = (unsigned)decodeSignRotatedValue(Record[Slot]);
@@ -321,6 +321,7 @@ private:
return getFnValueByID(ValNo, Ty);
}
+ bool ParseAttrKind(uint64_t Code, Attribute::AttrKind *Kind);
bool ParseModule(bool Resume);
bool ParseAttributeBlock();
bool ParseAttributeGroupBlock();
diff --git a/lib/Bitcode/Reader/BitstreamReader.cpp b/lib/Bitcode/Reader/BitstreamReader.cpp
index 942346b..1fd9abd 100644
--- a/lib/Bitcode/Reader/BitstreamReader.cpp
+++ b/lib/Bitcode/Reader/BitstreamReader.cpp
@@ -204,7 +204,16 @@ unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID);
- for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) {
+ // Read the record code first.
+ assert(Abbv->getNumOperandInfos() != 0 && "no record code in abbreviation?");
+ const BitCodeAbbrevOp &CodeOp = Abbv->getOperandInfo(0);
+ if (CodeOp.isLiteral())
+ readAbbreviatedLiteral(CodeOp, Vals);
+ else
+ readAbbreviatedField(CodeOp, Vals);
+ unsigned Code = (unsigned)Vals.pop_back_val();
+
+ for (unsigned i = 1, e = Abbv->getNumOperandInfos(); i != e; ++i) {
const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i);
if (Op.isLiteral()) {
readAbbreviatedLiteral(Op, Vals);
@@ -264,8 +273,6 @@ unsigned BitstreamCursor::readRecord(unsigned AbbrevID,
JumpToBit(NewEnd);
}
- unsigned Code = (unsigned)Vals[0];
- Vals.erase(Vals.begin());
return Code;
}
@@ -292,7 +299,7 @@ void BitstreamCursor::ReadAbbrevRecord() {
Abbv->Add(BitCodeAbbrevOp(0));
continue;
}
-
+
Abbv->Add(BitCodeAbbrevOp(E, Data));
} else
Abbv->Add(BitCodeAbbrevOp(E));