diff --git a/llvm/include/llvm/InstrTypes.h b/llvm/include/llvm/InstrTypes.h index 1ee2a4b33180ab63001cb34d46c4d935e2f7417c..c3c48af53f21d02808e5bd28776c329dccaacb6f 100644 --- a/llvm/include/llvm/InstrTypes.h +++ b/llvm/include/llvm/InstrTypes.h @@ -479,7 +479,7 @@ public: const Type *SrcTy, ///< SrcTy of 1st cast const Type *MidTy, ///< DstTy of 1st cast & SrcTy of 2nd cast const Type *DstTy, ///< DstTy of 2nd cast - const Type *IntPtrTy ///< Integer type corresponding to Ptr types + const Type *IntPtrTy ///< Integer type corresponding to Ptr types, or null ); /// @brief Return the opcode of this CastInst diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index e04d54cee379589e5b119893560500e7ab16a8fc..5e5ce64c1cb9567c24727a6de851289e9f3cb3ad 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -1890,6 +1890,8 @@ unsigned CastInst::isEliminableCastPair( return 0; case 7: { // ptrtoint, inttoptr -> bitcast (ptr -> ptr) if int size is >= ptr size + if (!IntPtrTy) + return 0; unsigned PtrSize = IntPtrTy->getScalarSizeInBits(); unsigned MidSize = MidTy->getScalarSizeInBits(); if (MidSize >= PtrSize) @@ -1929,6 +1931,8 @@ unsigned CastInst::isEliminableCastPair( return 0; case 13: { // inttoptr, ptrtoint -> bitcast if SrcSize<=PtrSize and SrcSize==DstSize + if (!IntPtrTy) + return 0; unsigned PtrSize = IntPtrTy->getScalarSizeInBits(); unsigned SrcSize = SrcTy->getScalarSizeInBits(); unsigned DstSize = DstTy->getScalarSizeInBits();