diff options
| author | David Majnemer <david.majnemer@gmail.com> | 2015-02-22 23:14:52 +0000 |
|---|---|---|
| committer | David Majnemer <david.majnemer@gmail.com> | 2015-02-22 23:14:52 +0000 |
| commit | 00303b6861a4f3faec2e52864eb87e0075c5835b (patch) | |
| tree | d395b7fda787db7f41ae91419c79a61af96b3a4d /llvm/lib | |
| parent | 3f45d40663171e630f1abff404931ffd39ab9d32 (diff) | |
| download | bcm5719-llvm-00303b6861a4f3faec2e52864eb87e0075c5835b.tar.gz bcm5719-llvm-00303b6861a4f3faec2e52864eb87e0075c5835b.zip | |
AsmParser: Check ConstantExpr GEP operands for validity
llvm-svn: 230188
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index fa4653b30bc..b009dae1880 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -2776,11 +2776,33 @@ bool LLParser::ParseValID(ValID &ID, PerFunctionState *PFS) { if (Opc == Instruction::GetElementPtr) { if (Elts.size() == 0 || !Elts[0]->getType()->getScalarType()->isPointerTy()) - return Error(ID.Loc, "getelementptr requires pointer operand"); + return Error(ID.Loc, "base of getelementptr must be a pointer"); + + Type *BaseType = Elts[0]->getType(); + auto *BasePointerType = cast<PointerType>(BaseType->getScalarType()); ArrayRef<Constant *> Indices(Elts.begin() + 1, Elts.end()); + for (Constant *Val : Indices) { + Type *ValTy = Val->getType(); + if (!ValTy->getScalarType()->isIntegerTy()) + return Error(ID.Loc, "getelementptr index must be an integer"); + if (ValTy->isVectorTy() != BaseType->isVectorTy()) + return Error(ID.Loc, "getelementptr index type missmatch"); + if (ValTy->isVectorTy()) { + unsigned ValNumEl = cast<VectorType>(ValTy)->getNumElements(); + unsigned PtrNumEl = cast<VectorType>(BaseType)->getNumElements(); + if (ValNumEl != PtrNumEl) + return Error( + ID.Loc, + "getelementptr vector index has a wrong number of elements"); + } + } + + if (!Indices.empty() && !BasePointerType->getElementType()->isSized()) + return Error(ID.Loc, "base element of getelementptr must be sized"); + if (!GetElementPtrInst::getIndexedType(Elts[0]->getType(), Indices)) - return Error(ID.Loc, "invalid indices for getelementptr"); + return Error(ID.Loc, "invalid getelementptr indices"); ID.ConstantVal = ConstantExpr::getGetElementPtr(Elts[0], Indices, InBounds); } else if (Opc == Instruction::Select) { |

