30
30
#include " llvm/IR/CallingConv.h"
31
31
#include " llvm/IR/Comdat.h"
32
32
#include " llvm/IR/Constant.h"
33
+ #include " llvm/IR/ConstantRangeList.h"
33
34
#include " llvm/IR/Constants.h"
34
35
#include " llvm/IR/DataLayout.h"
35
36
#include " llvm/IR/DebugInfo.h"
@@ -838,10 +839,10 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
838
839
}
839
840
840
841
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 )
843
845
return error (" Too few records for range" );
844
- unsigned BitWidth = Record[OpNum++];
845
846
if (BitWidth > 64 ) {
846
847
unsigned LowerActiveWords = Record[OpNum];
847
848
unsigned UpperActiveWords = Record[OpNum++] >> 32 ;
@@ -861,6 +862,14 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
861
862
}
862
863
}
863
864
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
+
864
873
// / Upgrades old-style typeless byval/sret/inalloca attributes by adding the
865
874
// / corresponding argument's pointee type. Also upgrades intrinsics that now
866
875
// / require an elementtype attribute.
@@ -2174,6 +2183,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
2174
2183
return Attribute::DeadOnUnwind;
2175
2184
case bitc::ATTR_KIND_RANGE:
2176
2185
return Attribute::Range;
2186
+ case bitc::ATTR_KIND_INITIALIZES:
2187
+ return Attribute::Initializes;
2177
2188
}
2178
2189
}
2179
2190
@@ -2352,12 +2363,39 @@ Error BitcodeReader::parseAttributeGroupBlock() {
2352
2363
if (!Attribute::isConstantRangeAttrKind (Kind))
2353
2364
return error (" Not a ConstantRange attribute" );
2354
2365
2355
- Expected<ConstantRange> MaybeCR = readConstantRange (Record, i);
2366
+ Expected<ConstantRange> MaybeCR =
2367
+ readBitWidthAndConstantRange (Record, i);
2356
2368
if (!MaybeCR)
2357
2369
return MaybeCR.takeError ();
2358
2370
i--;
2359
2371
2360
2372
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);
2361
2399
} else {
2362
2400
return error (" Invalid attribute group entry" );
2363
2401
}
@@ -3372,7 +3410,8 @@ Error BitcodeReader::parseConstants() {
3372
3410
(void )InRangeIndex;
3373
3411
} else if (BitCode == bitc::CST_CODE_CE_GEP_WITH_INRANGE) {
3374
3412
Flags = Record[OpNum++];
3375
- Expected<ConstantRange> MaybeInRange = readConstantRange (Record, OpNum);
3413
+ Expected<ConstantRange> MaybeInRange =
3414
+ readBitWidthAndConstantRange (Record, OpNum);
3376
3415
if (!MaybeInRange)
3377
3416
return MaybeInRange.takeError ();
3378
3417
InRange = MaybeInRange.get ();
0 commit comments