From 7e21ded88d0bd0539ac3672e3080359708b4a8f6 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sat, 17 Jul 2021 15:30:55 +0200 Subject: [PATCH] [IR] Don't accept null type in ConstantExpr::getGetElementPtr() This is the same change as D105653, but for the constant expression version of the API. --- llvm/lib/IR/Constants.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 791c684..6c75085 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -2427,10 +2427,8 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, Optional InRangeIndex, Type *OnlyIfReducedTy) { PointerType *OrigPtrTy = cast(C->getType()->getScalarType()); - if (!Ty) - Ty = OrigPtrTy->getElementType(); - else - assert(OrigPtrTy->isOpaqueOrPointeeTypeMatches(Ty)); + assert(Ty && "Must specify element type"); + assert(OrigPtrTy->isOpaqueOrPointeeTypeMatches(Ty)); if (Constant *FC = ConstantFoldGetElementPtr(Ty, C, InBounds, InRangeIndex, Idxs)) -- 2.7.4