From 22f9159bed3eb0694682590b68b879df64f010c4 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 10 Mar 2022 15:47:58 +0100 Subject: [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. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index edeacf4955c3..214eb159007f 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(I)->indices())) { - unsigned SubType = 0; - if (GTI.isStruct()) { - ConstantInt *IdxC = - Idx->getType()->isVectorTy() - ? cast(cast(Idx)->getSplatValue()) - : cast(Idx); - SubType = IdxC->getZExtValue(); + if (cast(I)->getNumIndices() != 0) { + auto GTI = std::next(gep_type_begin(I)); + for (Value *Idx : drop_begin(cast(I)->indices())) { + unsigned SubType = 0; + if (GTI.isStruct()) { + ConstantInt *IdxC = + Idx->getType()->isVectorTy() + ? cast(cast(Idx)->getSplatValue()) + : cast(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 -- cgit v1.2.3