aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 832907a..9c63116 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -815,6 +815,30 @@ private:
return getFnValueByID(ValNo, Ty, TyID, ConstExprInsertBB);
}
+ Expected<ConstantRange> readConstantRange(ArrayRef<uint64_t> Record,
+ unsigned &OpNum) {
+ if (Record.size() - OpNum < 3)
+ return error("Too few records for range");
+ unsigned BitWidth = Record[OpNum++];
+ if (BitWidth > 64) {
+ unsigned LowerActiveWords = Record[OpNum];
+ unsigned UpperActiveWords = Record[OpNum++] >> 32;
+ if (Record.size() - OpNum < LowerActiveWords + UpperActiveWords)
+ return error("Too few records for range");
+ APInt Lower =
+ readWideAPInt(ArrayRef(&Record[OpNum], LowerActiveWords), BitWidth);
+ OpNum += LowerActiveWords;
+ APInt Upper =
+ readWideAPInt(ArrayRef(&Record[OpNum], UpperActiveWords), BitWidth);
+ OpNum += UpperActiveWords;
+ return ConstantRange(Lower, Upper);
+ } else {
+ int64_t Start = BitcodeReader::decodeSignRotatedValue(Record[OpNum++]);
+ int64_t End = BitcodeReader::decodeSignRotatedValue(Record[OpNum++]);
+ return ConstantRange(APInt(BitWidth, Start), APInt(BitWidth, End));
+ }
+ }
+
/// Upgrades old-style typeless byval/sret/inalloca attributes by adding the
/// corresponding argument's pointee type. Also upgrades intrinsics that now
/// require an elementtype attribute.
@@ -2103,6 +2127,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
return Attribute::CoroDestroyOnlyWhenComplete;
case bitc::ATTR_KIND_DEAD_ON_UNWIND:
return Attribute::DeadOnUnwind;
+ case bitc::ATTR_KIND_RANGE:
+ return Attribute::Range;
}
}
@@ -2272,6 +2298,21 @@ Error BitcodeReader::parseAttributeGroupBlock() {
return error("Not a type attribute");
B.addTypeAttr(Kind, HasType ? getTypeByID(Record[++i]) : nullptr);
+ } else if (Record[i] == 7) {
+ Attribute::AttrKind Kind;
+
+ i++;
+ if (Error Err = parseAttrKind(Record[i++], &Kind))
+ return Err;
+ if (!Attribute::isConstantRangeAttrKind(Kind))
+ return error("Not a ConstantRange attribute");
+
+ Expected<ConstantRange> MaybeCR = readConstantRange(Record, i);
+ if (!MaybeCR)
+ return MaybeCR.takeError();
+ i--;
+
+ B.addConstantRangeAttr(Kind, MaybeCR.get());
} else {
return error("Invalid attribute group entry");
}