[llvm] 7e21ded - [IR] Don't accept null type in ConstantExpr::getGetElementPtr()

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 17 06:59:47 PDT 2021


Author: Nikita Popov
Date: 2021-07-17T15:59:31+02:00
New Revision: 7e21ded88d0bd0539ac3672e3080359708b4a8f6

URL: https://github.com/llvm/llvm-project/commit/7e21ded88d0bd0539ac3672e3080359708b4a8f6
DIFF: https://github.com/llvm/llvm-project/commit/7e21ded88d0bd0539ac3672e3080359708b4a8f6.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/IR/Constants.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 791c684d3bb6..6c75085a6678 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<unsigned> InRangeIndex,
                                          Type *OnlyIfReducedTy) {
   PointerType *OrigPtrTy = cast<PointerType>(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))


        


More information about the llvm-commits mailing list