diff options
author | Eli Friedman <efriedma@quicinc.com> | 2020-05-20 15:08:36 -0700 |
---|---|---|
committer | Eli Friedman <efriedma@quicinc.com> | 2020-06-30 13:23:07 -0700 |
commit | 0ec712afec642fa6a57fe17be0c8d7d096bf7434 (patch) | |
tree | 65667c2a33758242c711d8078f7844242f9d1da4 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | f7b2997ad67b2be7137677c70aa38d13cff18191 (diff) | |
download | llvm-0ec712afec642fa6a57fe17be0c8d7d096bf7434.zip llvm-0ec712afec642fa6a57fe17be0c8d7d096bf7434.tar.gz llvm-0ec712afec642fa6a57fe17be0c8d7d096bf7434.tar.bz2 |
[BitcodeReader] Fix DelayedShuffle handling for ConstantExpr shuffles.
The indexing was messed up, so the result was completely broken.
Shuffle constant exprs are rare in practice; without vscale types,
constant folding generally elminates them. So sort of hard to trip over.
Fixes regression from D72467.
(Recommitting after fix for memory leak.)
Differential Revision: https://reviews.llvm.org/D80330
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 813c1b3..4471302 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2335,6 +2335,7 @@ Error BitcodeReader::parseConstants() { uint64_t Op0Idx; uint64_t Op1Idx; uint64_t Op2Idx; + unsigned CstNo; }; std::vector<DelayedShufTy> DelayedShuffles; while (true) { @@ -2348,9 +2349,6 @@ Error BitcodeReader::parseConstants() { case BitstreamEntry::Error: return error("Malformed block"); case BitstreamEntry::EndBlock: - if (NextCstNo != ValueList.size()) - return error("Invalid constant reference"); - // Once all the constants have been read, go through and resolve forward // references. // @@ -2363,6 +2361,7 @@ Error BitcodeReader::parseConstants() { uint64_t Op0Idx = DelayedShuffle.Op0Idx; uint64_t Op1Idx = DelayedShuffle.Op1Idx; uint64_t Op2Idx = DelayedShuffle.Op2Idx; + uint64_t CstNo = DelayedShuffle.CstNo; Constant *Op0 = ValueList.getConstantFwdRef(Op0Idx, OpTy); Constant *Op1 = ValueList.getConstantFwdRef(Op1Idx, OpTy); Type *ShufTy = @@ -2373,9 +2372,12 @@ Error BitcodeReader::parseConstants() { SmallVector<int, 16> Mask; ShuffleVectorInst::getShuffleMask(Op2, Mask); Value *V = ConstantExpr::getShuffleVector(Op0, Op1, Mask); - ValueList.assignValue(V, NextCstNo, DelayedShuffle.CurFullTy); - ++NextCstNo; + ValueList.assignValue(V, CstNo, DelayedShuffle.CurFullTy); } + + if (NextCstNo != ValueList.size()) + return error("Invalid constant reference"); + ValueList.resolveConstantForwardRefs(); return Error::success(); case BitstreamEntry::Record: @@ -2735,7 +2737,8 @@ Error BitcodeReader::parseConstants() { if (Record.size() < 3 || !OpTy) return error("Invalid record"); DelayedShuffles.push_back( - {OpTy, OpTy, CurFullTy, Record[0], Record[1], Record[2]}); + {OpTy, OpTy, CurFullTy, Record[0], Record[1], Record[2], NextCstNo}); + ++NextCstNo; continue; } case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval] @@ -2745,7 +2748,8 @@ Error BitcodeReader::parseConstants() { if (Record.size() < 4 || !RTy || !OpTy) return error("Invalid record"); DelayedShuffles.push_back( - {OpTy, RTy, CurFullTy, Record[1], Record[2], Record[3]}); + {OpTy, RTy, CurFullTy, Record[1], Record[2], Record[3], NextCstNo}); + ++NextCstNo; continue; } case bitc::CST_CODE_CE_CMP: { // CE_CMP: [opty, opval, opval, pred] |