diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h index 0c43a56daa33..a5cebf0a4626 100644 --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -956,9 +956,13 @@ public: const Twine &NameStr = "", Instruction *InsertBefore = nullptr) { unsigned Values = 1 + unsigned(IdxList.size()); - assert(PointeeType && "Must specify element type"); - assert(cast(Ptr->getType()->getScalarType()) - ->isOpaqueOrPointeeTypeMatches(PointeeType)); + if (!PointeeType) { + PointeeType = + cast(Ptr->getType()->getScalarType())->getElementType(); + } else { + assert(cast(Ptr->getType()->getScalarType()) + ->isOpaqueOrPointeeTypeMatches(PointeeType)); + } return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, NameStr, InsertBefore); } @@ -968,9 +972,13 @@ public: const Twine &NameStr, BasicBlock *InsertAtEnd) { unsigned Values = 1 + unsigned(IdxList.size()); - assert(PointeeType && "Must specify element type"); - assert(cast(Ptr->getType()->getScalarType()) - ->isOpaqueOrPointeeTypeMatches(PointeeType)); + if (!PointeeType) { + PointeeType = + cast(Ptr->getType()->getScalarType())->getElementType(); + } else { + assert(cast(Ptr->getType()->getScalarType()) + ->isOpaqueOrPointeeTypeMatches(PointeeType)); + } return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values, NameStr, InsertAtEnd); }