3030#include " llvm/IR/CallingConv.h"
3131#include " llvm/IR/Comdat.h"
3232#include " llvm/IR/Constant.h"
33+ #include " llvm/IR/ConstantRangeList.h"
3334#include " llvm/IR/Constants.h"
3435#include " llvm/IR/DataLayout.h"
3536#include " llvm/IR/DebugInfo.h"
@@ -838,10 +839,10 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
838839 }
839840
840841 Expected<ConstantRange> readConstantRange (ArrayRef<uint64_t > Record,
841- unsigned &OpNum) {
842- if (Record.size () - OpNum < 3 )
842+ unsigned &OpNum,
843+ unsigned BitWidth) {
844+ if (Record.size () - OpNum < 2 )
843845 return error (" Too few records for range" );
844- unsigned BitWidth = Record[OpNum++];
845846 if (BitWidth > 64 ) {
846847 unsigned LowerActiveWords = Record[OpNum];
847848 unsigned UpperActiveWords = Record[OpNum++] >> 32 ;
@@ -861,6 +862,14 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
861862 }
862863 }
863864
865+ Expected<ConstantRange>
866+ readBitWidthAndConstantRange (ArrayRef<uint64_t > Record, unsigned &OpNum) {
867+ if (Record.size () - OpNum < 1 )
868+ return error (" Too few records for range" );
869+ unsigned BitWidth = Record[OpNum++];
870+ return readConstantRange (Record, OpNum, BitWidth);
871+ }
872+
864873 // / Upgrades old-style typeless byval/sret/inalloca attributes by adding the
865874 // / corresponding argument's pointee type. Also upgrades intrinsics that now
866875 // / require an elementtype attribute.
@@ -2174,6 +2183,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
21742183 return Attribute::DeadOnUnwind;
21752184 case bitc::ATTR_KIND_RANGE:
21762185 return Attribute::Range;
2186+ case bitc::ATTR_KIND_INITIALIZES:
2187+ return Attribute::Initializes;
21772188 }
21782189}
21792190
@@ -2352,12 +2363,39 @@ Error BitcodeReader::parseAttributeGroupBlock() {
23522363 if (!Attribute::isConstantRangeAttrKind (Kind))
23532364 return error (" Not a ConstantRange attribute" );
23542365
2355- Expected<ConstantRange> MaybeCR = readConstantRange (Record, i);
2366+ Expected<ConstantRange> MaybeCR =
2367+ readBitWidthAndConstantRange (Record, i);
23562368 if (!MaybeCR)
23572369 return MaybeCR.takeError ();
23582370 i--;
23592371
23602372 B.addConstantRangeAttr (Kind, MaybeCR.get ());
2373+ } else if (Record[i] == 8 ) {
2374+ Attribute::AttrKind Kind;
2375+
2376+ i++;
2377+ if (Error Err = parseAttrKind (Record[i++], &Kind))
2378+ return Err;
2379+ if (!Attribute::isConstantRangeListAttrKind (Kind))
2380+ return error (" Not a constant range list attribute" );
2381+
2382+ SmallVector<ConstantRange, 2 > Val;
2383+ if (i + 2 > e)
2384+ return error (" Too few records for constant range list" );
2385+ unsigned RangeSize = Record[i++];
2386+ unsigned BitWidth = Record[i++];
2387+ for (unsigned Idx = 0 ; Idx < RangeSize; ++Idx) {
2388+ Expected<ConstantRange> MaybeCR =
2389+ readConstantRange (Record, i, BitWidth);
2390+ if (!MaybeCR)
2391+ return MaybeCR.takeError ();
2392+ Val.push_back (MaybeCR.get ());
2393+ }
2394+ i--;
2395+
2396+ if (!ConstantRangeList::isOrderedRanges (Val))
2397+ return error (" Invalid (unordered or overlapping) range list" );
2398+ B.addConstantRangeListAttr (Kind, Val);
23612399 } else {
23622400 return error (" Invalid attribute group entry" );
23632401 }
@@ -3372,7 +3410,8 @@ Error BitcodeReader::parseConstants() {
33723410 (void )InRangeIndex;
33733411 } else if (BitCode == bitc::CST_CODE_CE_GEP_WITH_INRANGE) {
33743412 Flags = Record[OpNum++];
3375- Expected<ConstantRange> MaybeInRange = readConstantRange (Record, OpNum);
3413+ Expected<ConstantRange> MaybeInRange =
3414+ readBitWidthAndConstantRange (Record, OpNum);
33763415 if (!MaybeInRange)
33773416 return MaybeInRange.takeError ();
33783417 InRange = MaybeInRange.get ();
0 commit comments