diff options
author | Nikita Popov <npopov@redhat.com> | 2022-03-10 15:47:58 +0100 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-03-10 15:48:47 +0100 |
commit | 22f9159bed3eb0694682590b68b879df64f010c4 (patch) | |
tree | fc64a6eb8c7c4eace6db20dabb1c0680d975faa7 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 21a97a2ac11b81240c08753277dc1a234c6a7816 (diff) | |
download | llvm-22f9159bed3eb0694682590b68b879df64f010c4.zip llvm-22f9159bed3eb0694682590b68b879df64f010c4.tar.gz llvm-22f9159bed3eb0694682590b68b879df64f010c4.tar.bz2 |
[BitcodeReader] Support GEP without indices
LLVM considers these to be legal, so make sure the bitcode reader
can read them. I broke this when implementing opaque pointer
auto upgrade support.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index edeacf4..214eb15 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -4456,18 +4456,20 @@ Error BitcodeReader::parseFunctionBody(Function *F) { I = GetElementPtrInst::Create(Ty, BasePtr, GEPIdx); ResTypeID = TyID; - auto GTI = std::next(gep_type_begin(I)); - for (Value *Idx : drop_begin(cast<GEPOperator>(I)->indices())) { - unsigned SubType = 0; - if (GTI.isStruct()) { - ConstantInt *IdxC = - Idx->getType()->isVectorTy() - ? cast<ConstantInt>(cast<Constant>(Idx)->getSplatValue()) - : cast<ConstantInt>(Idx); - SubType = IdxC->getZExtValue(); + if (cast<GEPOperator>(I)->getNumIndices() != 0) { + auto GTI = std::next(gep_type_begin(I)); + for (Value *Idx : drop_begin(cast<GEPOperator>(I)->indices())) { + unsigned SubType = 0; + if (GTI.isStruct()) { + ConstantInt *IdxC = + Idx->getType()->isVectorTy() + ? cast<ConstantInt>(cast<Constant>(Idx)->getSplatValue()) + : cast<ConstantInt>(Idx); + SubType = IdxC->getZExtValue(); + } + ResTypeID = getContainedTypeID(ResTypeID, SubType); + ++GTI; } - ResTypeID = getContainedTypeID(ResTypeID, SubType); - ++GTI; } // At this point ResTypeID is the result element type. We need a pointer |