diff --git a/llvm/include/llvm/Analysis/AliasSetTracker.h b/llvm/include/llvm/Analysis/AliasSetTracker.h --- a/llvm/include/llvm/Analysis/AliasSetTracker.h +++ b/llvm/include/llvm/Analysis/AliasSetTracker.h @@ -190,7 +190,7 @@ Instruction *getUnknownInst(unsigned i) const { assert(i < UnknownInsts.size()); - return cast_or_null(UnknownInsts[i]); + return cast_if_present(UnknownInsts[i]); } public: diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h --- a/llvm/include/llvm/Analysis/MemorySSA.h +++ b/llvm/include/llvm/Analysis/MemorySSA.h @@ -395,7 +395,7 @@ } MemoryAccess *getOptimized() const { - return cast_or_null(getOperand(1)); + return cast_if_present(getOperand(1)); } bool isOptimized() const { @@ -715,11 +715,12 @@ /// node that exists for that block, if there is one. Otherwise, this will get /// a MemoryUseOrDef. MemoryUseOrDef *getMemoryAccess(const Instruction *I) const { - return cast_or_null(ValueToMemoryAccess.lookup(I)); + return cast_if_present(ValueToMemoryAccess.lookup(I)); } MemoryPhi *getMemoryAccess(const BasicBlock *BB) const { - return cast_or_null(ValueToMemoryAccess.lookup(cast(BB))); + return cast_if_present( + ValueToMemoryAccess.lookup(cast(BB))); } DominatorTree &getDomTree() const { return *DT; } diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -83,7 +83,7 @@ // FIXME: Fix callers and remove condition on N. unsigned size() const { return N ? N->getNumOperands() : 0u; } DIType *operator[](unsigned I) const { - return cast_or_null(N->getOperand(I)); + return cast_if_present(N->getOperand(I)); } class iterator { @@ -99,7 +99,7 @@ iterator() = default; explicit iterator(MDNode::op_iterator I) : I(I) {} - DIType *operator*() const { return cast_or_null(*I); } + DIType *operator*() const { return cast_if_present(*I); } iterator &operator++() { ++I; @@ -140,7 +140,7 @@ ~DINode() = default; template Ty *getOperandAs(unsigned I) const { - return cast_or_null(getOperand(I)); + return cast_if_present(getOperand(I)); } StringRef getStringOperand(unsigned I) const { @@ -476,7 +476,7 @@ ~DIScope() = default; public: - DIFile *getFile() const { return cast_or_null(getRawFile()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } inline StringRef getFilename() const; inline StringRef getDirectory() const; @@ -700,7 +700,7 @@ uint64_t getOffsetInBits() const { return OffsetInBits; } DIFlags getFlags() const { return Flags; } - DIScope *getScope() const { return cast_or_null(getRawScope()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } StringRef getName() const { return getStringOperand(2); } Metadata *getRawScope() const { return getOperand(1); } @@ -895,15 +895,15 @@ } DIVariable *getStringLength() const { - return cast_or_null(getRawStringLength()); + return cast_if_present(getRawStringLength()); } DIExpression *getStringLengthExp() const { - return cast_or_null(getRawStringLengthExp()); + return cast_if_present(getRawStringLengthExp()); } DIExpression *getStringLocationExp() const { - return cast_or_null(getRawStringLocationExp()); + return cast_if_present(getRawStringLocationExp()); } unsigned getEncoding() const { return Encoding; } @@ -989,7 +989,9 @@ TempDIDerivedType clone() const { return cloneImpl(); } /// Get the base type this is derived from. - DIType *getBaseType() const { return cast_or_null(getRawBaseType()); } + DIType *getBaseType() const { + return cast_if_present(getRawBaseType()); + } Metadata *getRawBaseType() const { return getOperand(3); } /// \returns The DWARF address space of the memory pointed to or referenced by @@ -1009,7 +1011,7 @@ /// Get annotations associated with this derived type. DINodeArray getAnnotations() const { - return cast_or_null(getRawAnnotations()); + return cast_if_present(getRawAnnotations()); } Metadata *getRawAnnotations() const { return getOperand(5); } @@ -1172,15 +1174,17 @@ Metadata *DataLocation, Metadata *Associated, Metadata *Allocated, Metadata *Rank, Metadata *Annotations); - DIType *getBaseType() const { return cast_or_null(getRawBaseType()); } + DIType *getBaseType() const { + return cast_if_present(getRawBaseType()); + } DINodeArray getElements() const { - return cast_or_null(getRawElements()); + return cast_if_present(getRawElements()); } DIType *getVTableHolder() const { - return cast_or_null(getRawVTableHolder()); + return cast_if_present(getRawVTableHolder()); } DITemplateParameterArray getTemplateParams() const { - return cast_or_null(getRawTemplateParams()); + return cast_if_present(getRawTemplateParams()); } StringRef getIdentifier() const { return getStringOperand(7); } unsigned getRuntimeLang() const { return RuntimeLang; } @@ -1227,7 +1231,7 @@ Metadata *getRawAnnotations() const { return getOperand(13); } DINodeArray getAnnotations() const { - return cast_or_null(getRawAnnotations()); + return cast_if_present(getRawAnnotations()); } /// Replace operands. @@ -1308,7 +1312,7 @@ uint8_t getCC() const { return CC; } DITypeRefArray getTypeArray() const { - return cast_or_null(getRawTypeArray()); + return cast_if_present(getRawTypeArray()); } Metadata *getRawTypeArray() const { return getOperand(3); } @@ -1459,19 +1463,19 @@ StringRef getFlags() const { return getStringOperand(2); } StringRef getSplitDebugFilename() const { return getStringOperand(3); } DICompositeTypeArray getEnumTypes() const { - return cast_or_null(getRawEnumTypes()); + return cast_if_present(getRawEnumTypes()); } DIScopeArray getRetainedTypes() const { - return cast_or_null(getRawRetainedTypes()); + return cast_if_present(getRawRetainedTypes()); } DIGlobalVariableExpressionArray getGlobalVariables() const { - return cast_or_null(getRawGlobalVariables()); + return cast_if_present(getRawGlobalVariables()); } DIImportedEntityArray getImportedEntities() const { - return cast_or_null(getRawImportedEntities()); + return cast_if_present(getRawImportedEntities()); } DIMacroNodeArray getMacros() const { - return cast_or_null(getRawMacros()); + return cast_if_present(getRawMacros()); } uint64_t getDWOId() const { return DWOId; } void setDWOId(uint64_t DwoId) { DWOId = DwoId; } @@ -1604,7 +1608,7 @@ DILocalScope *getScope() const { return cast(getRawScope()); } DILocation *getInlinedAt() const { - return cast_or_null(getRawInlinedAt()); + return cast_if_present(getRawInlinedAt()); } /// Check if the location corresponds to an implicit code. @@ -1989,7 +1993,7 @@ // Returns true if this subprogram is a thunk generated by the compiler. bool isThunk() const { return getFlags() & FlagThunk; } - DIScope *getScope() const { return cast_or_null(getRawScope()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } StringRef getName() const { return getStringOperand(2); } StringRef getLinkageName() const { return getStringOperand(3); } @@ -1997,10 +2001,10 @@ void replaceLinkageName(MDString *LN) { replaceOperandWith(3, LN); } DISubroutineType *getType() const { - return cast_or_null(getRawType()); + return cast_if_present(getRawType()); } DIType *getContainingType() const { - return cast_or_null(getRawContainingType()); + return cast_if_present(getRawContainingType()); } void replaceType(DISubroutineType *Ty) { assert(isDistinct() && "Only distinct nodes can mutate"); @@ -2008,23 +2012,23 @@ } DICompileUnit *getUnit() const { - return cast_or_null(getRawUnit()); + return cast_if_present(getRawUnit()); } void replaceUnit(DICompileUnit *CU) { replaceOperandWith(5, CU); } DITemplateParameterArray getTemplateParams() const { - return cast_or_null(getRawTemplateParams()); + return cast_if_present(getRawTemplateParams()); } DISubprogram *getDeclaration() const { - return cast_or_null(getRawDeclaration()); + return cast_if_present(getRawDeclaration()); } DINodeArray getRetainedNodes() const { - return cast_or_null(getRawRetainedNodes()); + return cast_if_present(getRawRetainedNodes()); } DITypeArray getThrownTypes() const { - return cast_or_null(getRawThrownTypes()); + return cast_if_present(getRawThrownTypes()); } DINodeArray getAnnotations() const { - return cast_or_null(getRawAnnotations()); + return cast_if_present(getRawAnnotations()); } StringRef getTargetFuncName() const { return (getRawTargetFuncName()) ? getStringOperand(12) : StringRef(); @@ -2291,7 +2295,7 @@ TempDINamespace clone() const { return cloneImpl(); } bool getExportSymbols() const { return ExportSymbols; } - DIScope *getScope() const { return cast_or_null(getRawScope()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } StringRef getName() const { return getStringOperand(2); } Metadata *getRawScope() const { return getOperand(1); } @@ -2355,7 +2359,7 @@ TempDIModule clone() const { return cloneImpl(); } - DIScope *getScope() const { return cast_or_null(getRawScope()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } StringRef getName() const { return getStringOperand(2); } StringRef getConfigurationMacros() const { return getStringOperand(3); } StringRef getIncludePath() const { return getStringOperand(4); } @@ -2388,7 +2392,7 @@ public: StringRef getName() const { return getStringOperand(0); } - DIType *getType() const { return cast_or_null(getRawType()); } + DIType *getType() const { return cast_if_present(getRawType()); } MDString *getRawName() const { return getOperandAs(0); } Metadata *getRawType() const { return getOperand(1); } @@ -2500,10 +2504,10 @@ public: unsigned getLine() const { return Line; } - DIScope *getScope() const { return cast_or_null(getRawScope()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } StringRef getName() const { return getStringOperand(1); } - DIFile *getFile() const { return cast_or_null(getRawFile()); } - DIType *getType() const { return cast_or_null(getRawType()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } + DIType *getType() const { return cast_if_present(getRawType()); } uint32_t getAlignInBits() const { return AlignInBits; } uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; } /// Determines the size of the variable's type. @@ -2935,7 +2939,7 @@ return getImpl(Context, Scope, getCanonicalMDString(Context, Name), getCanonicalMDString(Context, LinkageName), File, Line, Type, IsLocalToUnit, IsDefinition, StaticDataMemberDeclaration, - cast_or_null(TemplateParams), AlignInBits, + cast_if_present(TemplateParams), AlignInBits, Annotations.get(), Storage, ShouldCreate); } static DIGlobalVariable * @@ -2979,10 +2983,10 @@ StringRef getDisplayName() const { return getStringOperand(4); } StringRef getLinkageName() const { return getStringOperand(5); } DIDerivedType *getStaticDataMemberDeclaration() const { - return cast_or_null(getRawStaticDataMemberDeclaration()); + return cast_if_present(getRawStaticDataMemberDeclaration()); } DINodeArray getAnnotations() const { - return cast_or_null(getRawAnnotations()); + return cast_if_present(getRawAnnotations()); } MDString *getRawLinkageName() const { return getOperandAs(5); } @@ -3034,12 +3038,12 @@ TempDICommonBlock clone() const { return cloneImpl(); } - DIScope *getScope() const { return cast_or_null(getRawScope()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } DIGlobalVariable *getDecl() const { - return cast_or_null(getRawDecl()); + return cast_if_present(getRawDecl()); } StringRef getName() const { return getStringOperand(2); } - DIFile *getFile() const { return cast_or_null(getRawFile()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } unsigned getLineNo() const { return LineNo; } Metadata *getRawScope() const { return getOperand(0); } @@ -3122,7 +3126,7 @@ DIFlags getFlags() const { return Flags; } DINodeArray getAnnotations() const { - return cast_or_null(getRawAnnotations()); + return cast_if_present(getRawAnnotations()); } Metadata *getRawAnnotations() const { return getOperand(4); } @@ -3186,11 +3190,11 @@ /// /// Labels must be defined in a local scope. DILocalScope *getScope() const { - return cast_or_null(getRawScope()); + return cast_if_present(getRawScope()); } unsigned getLine() const { return Line; } StringRef getName() const { return getStringOperand(1); } - DIFile *getFile() const { return cast_or_null(getRawFile()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } Metadata *getRawScope() const { return getOperand(0); } MDString *getRawName() const { return getOperandAs(1); } @@ -3261,10 +3265,10 @@ unsigned getLine() const { return Line; } unsigned getAttributes() const { return Attributes; } StringRef getName() const { return getStringOperand(0); } - DIFile *getFile() const { return cast_or_null(getRawFile()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } StringRef getGetterName() const { return getStringOperand(2); } StringRef getSetterName() const { return getStringOperand(3); } - DIType *getType() const { return cast_or_null(getRawType()); } + DIType *getType() const { return cast_if_present(getRawType()); } StringRef getFilename() const { if (auto *F = getFile()) @@ -3335,12 +3339,12 @@ TempDIImportedEntity clone() const { return cloneImpl(); } unsigned getLine() const { return Line; } - DIScope *getScope() const { return cast_or_null(getRawScope()); } - DINode *getEntity() const { return cast_or_null(getRawEntity()); } + DIScope *getScope() const { return cast_if_present(getRawScope()); } + DINode *getEntity() const { return cast_if_present(getRawEntity()); } StringRef getName() const { return getStringOperand(2); } - DIFile *getFile() const { return cast_or_null(getRawFile()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } DINodeArray getElements() const { - return cast_or_null(getRawElements()); + return cast_if_present(getRawElements()); } Metadata *getRawScope() const { return getOperand(0); } @@ -3382,7 +3386,7 @@ Metadata *getRawVariable() const { return getOperand(0); } DIGlobalVariable *getVariable() const { - return cast_or_null(getRawVariable()); + return cast_if_present(getRawVariable()); } Metadata *getRawExpression() const { return getOperand(1); } @@ -3416,7 +3420,7 @@ ~DIMacroNode() = default; template Ty *getOperandAs(unsigned I) const { - return cast_or_null(getOperand(I)); + return cast_if_present(getOperand(I)); } StringRef getStringOperand(unsigned I) const { @@ -3546,10 +3550,10 @@ } unsigned getLine() const { return Line; } - DIFile *getFile() const { return cast_or_null(getRawFile()); } + DIFile *getFile() const { return cast_if_present(getRawFile()); } DIMacroNodeArray getElements() const { - return cast_or_null(getRawElements()); + return cast_if_present(getRawElements()); } Metadata *getRawFile() const { return getOperand(0); } diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h --- a/llvm/include/llvm/IR/Instructions.h +++ b/llvm/include/llvm/IR/Instructions.h @@ -3211,7 +3211,7 @@ BasicBlock *getSuccessor(unsigned i) const { assert(i < getNumSuccessors() && "Successor # out of range for Branch!"); - return cast_or_null((&Op<-1>() - i)->get()); + return cast_if_present((&Op<-1>() - i)->get()); } void setSuccessor(unsigned idx, BasicBlock *NewSucc) { @@ -4162,7 +4162,8 @@ return cast(*(&Op<-1>() - getNumIndirectDests() - 1)); } BasicBlock *getIndirectDest(unsigned i) const { - return cast_or_null(*(&Op<-1>() - getNumIndirectDests() + i)); + return cast_if_present( + *(&Op<-1>() - getNumIndirectDests() + i)); } SmallVector getIndirectDests() const { SmallVector IndirectDests; diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -375,11 +375,11 @@ static ValueAsMetadata *getIfExists(Value *V); static ConstantAsMetadata *getConstantIfExists(Value *C) { - return cast_or_null(getIfExists(C)); + return cast_if_present(getIfExists(C)); } static LocalAsMetadata *getLocalIfExists(Value *Local) { - return cast_or_null(getIfExists(Local)); + return cast_if_present(getIfExists(Local)); } Value *getValue() const { return V; } @@ -499,7 +499,7 @@ /// /// mdconst::hasa <=> isa /// mdconst::extract <=> cast -/// mdconst::extract_or_null <=> cast_or_null +/// mdconst::extract_or_null <=> cast_if_present /// mdconst::dyn_extract <=> dyn_cast /// mdconst::dyn_extract_or_null <=> dyn_cast_if_present /// @@ -566,12 +566,12 @@ /// Extract a Value from Metadata, allowing null. /// -/// As an analogue to \a cast_or_null(), extract the \a Value subclass \c X +/// As an analogue to \a cast_if_present(), extract the \a Value subclass \c X /// from \c MD, allowing \c MD to be null. template inline std::enable_if_t::value, X *> extract_or_null(Y &&MD) { - if (auto *V = cast_or_null(MD)) + if (auto *V = cast_if_present(MD)) return cast(V->getValue()); return nullptr; } @@ -1462,7 +1462,7 @@ TypedMDOperandIterator() = default; explicit TypedMDOperandIterator(MDNode::op_iterator I) : I(I) {} - T *operator*() const { return cast_or_null(*I); } + T *operator*() const { return cast_if_present(*I); } TypedMDOperandIterator &operator++() { ++I; @@ -1512,7 +1512,9 @@ // FIXME: Fix callers and remove condition on N. unsigned size() const { return N ? N->getNumOperands() : 0u; } bool empty() const { return N ? N->getNumOperands() == 0 : true; } - T *operator[](unsigned I) const { return cast_or_null(N->getOperand(I)); } + T *operator[](unsigned I) const { + return cast_if_present(N->getOperand(I)); + } // FIXME: Fix callers and remove condition on N. using iterator = TypedMDOperandIterator; diff --git a/llvm/include/llvm/IR/OperandTraits.h b/llvm/include/llvm/IR/OperandTraits.h --- a/llvm/include/llvm/IR/OperandTraits.h +++ b/llvm/include/llvm/IR/OperandTraits.h @@ -26,20 +26,15 @@ /// when it is a prefix to the User object, and the number of Use objects is /// known at compile time. -template -struct FixedNumOperandTraits { - static Use *op_begin(SubClass* U) { +template struct FixedNumOperandTraits { + static Use *op_begin(SubClass *U) { static_assert( !std::is_polymorphic::value, "adding virtual methods to subclasses of User breaks use lists"); - return reinterpret_cast(U) - ARITY; - } - static Use *op_end(SubClass* U) { - return reinterpret_cast(U); - } - static unsigned operands(const User*) { - return ARITY; + return reinterpret_cast(U) - ARITY; } + static Use *op_end(SubClass *U) { return reinterpret_cast(U); } + static unsigned operands(const User *) { return ARITY; } }; //===----------------------------------------------------------------------===// @@ -51,9 +46,7 @@ template struct OptionalOperandTraits : public FixedNumOperandTraits { - static unsigned operands(const User *U) { - return U->getNumOperands(); - } + static unsigned operands(const User *U) { return U->getNumOperands(); } }; //===----------------------------------------------------------------------===// @@ -66,18 +59,15 @@ template struct VariadicOperandTraits { - static Use *op_begin(SubClass* U) { + static Use *op_begin(SubClass *U) { static_assert( !std::is_polymorphic::value, "adding virtual methods to subclasses of User breaks use lists"); - return reinterpret_cast(U) - static_cast(U)->getNumOperands(); - } - static Use *op_end(SubClass* U) { - return reinterpret_cast(U); - } - static unsigned operands(const User *U) { - return U->getNumOperands(); + return reinterpret_cast(U) - + static_cast(U)->getNumOperands(); } + static Use *op_end(SubClass *U) { return reinterpret_cast(U); } + static unsigned operands(const User *U) { return U->getNumOperands(); } }; //===----------------------------------------------------------------------===// @@ -91,72 +81,69 @@ /// This is the traits class that is needed when the Use array must be /// resizable. -template -struct HungoffOperandTraits { - static Use *op_begin(User* U) { - return U->getOperandList(); - } - static Use *op_end(User* U) { +template struct HungoffOperandTraits { + static Use *op_begin(User *U) { return U->getOperandList(); } + static Use *op_end(User *U) { return U->getOperandList() + U->getNumOperands(); } - static unsigned operands(const User *U) { - return U->getNumOperands(); - } + static unsigned operands(const User *U) { return U->getNumOperands(); } }; /// Macro for generating in-class operand accessor declarations. /// It should only be called in the public section of the interface. /// -#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS) \ - public: \ - inline VALUECLASS *getOperand(unsigned) const; \ - inline void setOperand(unsigned, VALUECLASS*); \ - inline op_iterator op_begin(); \ - inline const_op_iterator op_begin() const; \ - inline op_iterator op_end(); \ - inline const_op_iterator op_end() const; \ - protected: \ - template inline Use &Op(); \ - template inline const Use &Op() const; \ - public: \ +#define DECLARE_TRANSPARENT_OPERAND_ACCESSORS(VALUECLASS) \ +public: \ + inline VALUECLASS *getOperand(unsigned) const; \ + inline void setOperand(unsigned, VALUECLASS *); \ + inline op_iterator op_begin(); \ + inline const_op_iterator op_begin() const; \ + inline op_iterator op_end(); \ + inline const_op_iterator op_end() const; \ + \ +protected: \ + template inline Use &Op(); \ + template inline const Use &Op() const; \ + \ +public: \ inline unsigned getNumOperands() const /// Macro for generating out-of-class operand accessor definitions -#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \ -CLASS::op_iterator CLASS::op_begin() { \ - return OperandTraits::op_begin(this); \ -} \ -CLASS::const_op_iterator CLASS::op_begin() const { \ - return OperandTraits::op_begin(const_cast(this)); \ -} \ -CLASS::op_iterator CLASS::op_end() { \ - return OperandTraits::op_end(this); \ -} \ -CLASS::const_op_iterator CLASS::op_end() const { \ - return OperandTraits::op_end(const_cast(this)); \ -} \ -VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \ - assert(i_nocapture < OperandTraits::operands(this) \ - && "getOperand() out of range!"); \ - return cast_or_null( \ - OperandTraits::op_begin(const_cast(this))[i_nocapture].get()); \ -} \ -void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ - assert(i_nocapture < OperandTraits::operands(this) \ - && "setOperand() out of range!"); \ - OperandTraits::op_begin(this)[i_nocapture] = Val_nocapture; \ -} \ -unsigned CLASS::getNumOperands() const { \ - return OperandTraits::operands(this); \ -} \ -template Use &CLASS::Op() { \ - return this->OpFrom(this); \ -} \ -template const Use &CLASS::Op() const { \ - return this->OpFrom(this); \ -} - - -} // End llvm namespace +#define DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CLASS, VALUECLASS) \ + CLASS::op_iterator CLASS::op_begin() { \ + return OperandTraits::op_begin(this); \ + } \ + CLASS::const_op_iterator CLASS::op_begin() const { \ + return OperandTraits::op_begin(const_cast(this)); \ + } \ + CLASS::op_iterator CLASS::op_end() { \ + return OperandTraits::op_end(this); \ + } \ + CLASS::const_op_iterator CLASS::op_end() const { \ + return OperandTraits::op_end(const_cast(this)); \ + } \ + VALUECLASS *CLASS::getOperand(unsigned i_nocapture) const { \ + assert(i_nocapture < OperandTraits::operands(this) && \ + "getOperand() out of range!"); \ + return cast_if_present( \ + OperandTraits::op_begin(const_cast(this))[i_nocapture] \ + .get()); \ + } \ + void CLASS::setOperand(unsigned i_nocapture, VALUECLASS *Val_nocapture) { \ + assert(i_nocapture < OperandTraits::operands(this) && \ + "setOperand() out of range!"); \ + OperandTraits::op_begin(this)[i_nocapture] = Val_nocapture; \ + } \ + unsigned CLASS::getNumOperands() const { \ + return OperandTraits::operands(this); \ + } \ + template Use &CLASS::Op() { \ + return this->OpFrom(this); \ + } \ + template const Use &CLASS::Op() const { \ + return this->OpFrom(this); \ + } + +} // namespace llvm #endif diff --git a/llvm/include/llvm/IR/ValueMap.h b/llvm/include/llvm/IR/ValueMap.h --- a/llvm/include/llvm/IR/ValueMap.h +++ b/llvm/include/llvm/IR/ValueMap.h @@ -255,7 +255,7 @@ ValueMapCallbackVH(Value *V) : CallbackVH(V), Map(nullptr) {} public: - KeyT Unwrap() const { return cast_or_null(getValPtr()); } + KeyT Unwrap() const { return cast_if_present(getValPtr()); } void deleted() override { // Make a copy that won't get changed even when *this is destroyed. diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -4316,7 +4316,7 @@ ConstantRange RangeV = getAssumedConstantRange(A, CtxI); if (auto *C = RangeV.getSingleElement()) { Type *Ty = getAssociatedValue().getType(); - return cast_or_null( + return cast_if_present( AA::getWithType(*ConstantInt::get(Ty->getContext(), *C), *Ty)); } if (RangeV.isEmptySet()) @@ -4568,7 +4568,7 @@ return nullptr; if (getAssumedSet().size() == 1) { Type *Ty = getAssociatedValue().getType(); - return cast_or_null(AA::getWithType( + return cast_if_present(AA::getWithType( *ConstantInt::get(Ty->getContext(), *(getAssumedSet().begin())), *Ty)); } diff --git a/llvm/lib/Analysis/AssumeBundleQueries.cpp b/llvm/lib/Analysis/AssumeBundleQueries.cpp --- a/llvm/lib/Analysis/AssumeBundleQueries.cpp +++ b/llvm/lib/Analysis/AssumeBundleQueries.cpp @@ -162,7 +162,7 @@ return RetainedKnowledge::none(); if (AC) { for (AssumptionCache::ResultElem &Elem : AC->assumptionsFor(V)) { - auto *II = cast_or_null(Elem.Assume); + auto *II = cast_if_present(Elem.Assume); if (!II || Elem.Index == AssumptionCache::ExprResultIdx) continue; if (RetainedKnowledge RK = getKnowledgeFromBundle( diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -276,7 +276,7 @@ // We just inserted a phi into this block, so the incoming value will // become the phi anyway, so it does not matter what we pass. for (auto &MP : InsertedPHIs) - if (MemoryPhi *Phi = cast_or_null(MP)) + if (MemoryPhi *Phi = cast_if_present(MP)) MSSA->renamePass(Phi->getBlock(), nullptr, Visited); } } @@ -369,7 +369,7 @@ // previous access was optimized; that access needs to be reoptimized. DefiningBlocks.insert(MD->getBlock()); for (const auto &VH : InsertedPHIs) - if (const auto *RealPHI = cast_or_null(VH)) + if (const auto *RealPHI = cast_if_present(VH)) DefiningBlocks.insert(RealPHI->getBlock()); ForwardIDFCalculator IDFs(*MSSA->DT); SmallVector IDFBlocks; @@ -576,7 +576,7 @@ Instruction *DefMUDI = DefMUD->getMemoryInst(); assert(DefMUDI && "Found MemoryUseOrDef with no Instruction."); if (Instruction *NewDefMUDI = - cast_or_null(VMap.lookup(DefMUDI))) { + cast_if_present(VMap.lookup(DefMUDI))) { InsnDefining = MSSA->getMemoryAccess(NewDefMUDI); if (!CloneWasSimplified) assert(InsnDefining && "Defining instruction cannot be nullptr."); @@ -688,7 +688,8 @@ MemoryAccess *IncomingAccess = Phi->getIncomingValue(It); BasicBlock *IncBB = Phi->getIncomingBlock(It); - if (BasicBlock *NewIncBB = cast_or_null(VMap.lookup(IncBB))) + if (BasicBlock *NewIncBB = + cast_if_present(VMap.lookup(IncBB))) IncBB = NewIncBB; else if (IgnoreIncomingWithNoClones) continue; @@ -706,7 +707,7 @@ Instruction *IncI = IncMUD->getMemoryInst(); assert(IncI && "Found MemoryUseOrDef with no Instruction."); if (Instruction *NewIncI = - cast_or_null(VMap.lookup(IncI))) { + cast_if_present(VMap.lookup(IncI))) { IncMUD = MSSA->getMemoryAccess(NewIncI); assert(IncMUD && "MemoryUseOrDef cannot be null, all preds processed."); @@ -728,7 +729,7 @@ }; auto ProcessBlock = [&](BasicBlock *BB) { - BasicBlock *NewBlock = cast_or_null(VMap.lookup(BB)); + BasicBlock *NewBlock = cast_if_present(VMap.lookup(BB)); if (!NewBlock) return; @@ -777,7 +778,8 @@ // Update/insert phis in all successors of exit blocks. for (auto *Exit : ExitBlocks) for (const ValueToValueMapTy *VMap : make_range(ValuesBegin, ValuesEnd)) - if (BasicBlock *NewExit = cast_or_null(VMap->lookup(Exit))) { + if (BasicBlock *NewExit = + cast_if_present(VMap->lookup(Exit))) { BasicBlock *ExitSucc = NewExit->getTerminator()->getSuccessor(0); Updates.push_back({DT.Insert, NewExit, ExitSucc}); } @@ -1092,7 +1094,7 @@ // compute IDF and add Phis there next. SmallVector BlocksToProcess; for (auto &VH : InsertedPhis) - if (auto *MPhi = cast_or_null(VH)) + if (auto *MPhi = cast_if_present(VH)) BlocksToProcess.push_back(MPhi->getBlock()); // Compute IDF and add Phis in all IDF blocks that do not have one. @@ -1364,7 +1366,7 @@ unsigned PhisSize = PhisToOptimize.size(); while (PhisSize-- > 0) if (MemoryPhi *MP = - cast_or_null(PhisToOptimize.pop_back_val())) + cast_if_present(PhisToOptimize.pop_back_val())) tryRemoveTrivialPhi(MP); } } @@ -1401,7 +1403,7 @@ void MemorySSAUpdater::tryRemoveTrivialPhis(ArrayRef UpdatedPHIs) { for (const auto &VH : UpdatedPHIs) - if (auto *MPhi = cast_or_null(VH)) + if (auto *MPhi = cast_if_present(VH)) tryRemoveTrivialPhi(MPhi); } diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp b/llvm/lib/Analysis/TargetLibraryInfo.cpp --- a/llvm/lib/Analysis/TargetLibraryInfo.cpp +++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp @@ -1224,8 +1224,8 @@ } unsigned TargetLibraryInfoImpl::getWCharSize(const Module &M) const { - if (auto *ShortWChar = cast_or_null( - M.getModuleFlag("wchar_size"))) + if (auto *ShortWChar = + cast_if_present(M.getModuleFlag("wchar_size"))) return cast(ShortWChar->getValue())->getZExtValue(); return 0; } diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -1531,7 +1531,7 @@ // Look this name up in the normal function symbol table. GlobalValue *Val = - cast_or_null(M->getValueSymbolTable().lookup(Name)); + cast_if_present(M->getValueSymbolTable().lookup(Name)); // If this is a forward reference for the value, see if we already created a // forward ref record. @@ -1543,7 +1543,7 @@ // If we have the value in the symbol table or fwd-ref table, return it. if (Val) - return cast_or_null( + return cast_if_present( checkValidVariableType(Loc, "@" + Name, Ty, Val)); // Otherwise, create a new forward reference for this value and remember it. @@ -1571,7 +1571,7 @@ // If we have the value in the symbol table or fwd-ref table, return it. if (Val) - return cast_or_null( + return cast_if_present( checkValidVariableType(Loc, "@" + Twine(ID), Ty, Val)); // Otherwise, create a new forward reference for this value and remember it. diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2356,7 +2356,7 @@ return error("Invalid TYPE table"); // Check to see if this was forward referenced, if so fill in the temp. - StructType *Res = cast_or_null(TypeList[NumRecords]); + StructType *Res = cast_if_present(TypeList[NumRecords]); if (Res) { Res->setName(TypeName); TypeList[NumRecords] = nullptr; @@ -2386,7 +2386,7 @@ return error("Invalid TYPE table"); // Check to see if this was forward referenced, if so fill in the temp. - StructType *Res = cast_or_null(TypeList[NumRecords]); + StructType *Res = cast_if_present(TypeList[NumRecords]); if (Res) { Res->setName(TypeName); TypeList[NumRecords] = nullptr; diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1163,7 +1163,7 @@ // This requires that the ID is not really a forward reference. In // particular, the MDString must already have been resolved. auto MDS = getMDOrNull(ID); - return cast_or_null(MDS); + return cast_if_present(MDS); }; // Support for old type refs. diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -2108,7 +2108,7 @@ StringRef Fn; unsigned FileNo = 1; unsigned Discriminator = 0; - if (auto *Scope = cast_or_null(S)) { + if (auto *Scope = cast_if_present(S)) { Fn = Scope->getFilename(); if (Line != 0 && DwarfVersion >= 4) if (auto *LBF = dyn_cast(Scope)) diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -709,7 +709,7 @@ SmallSet Preds; for (auto &Block : Blocks) { - auto *BB = cast_or_null(Block); + auto *BB = cast_if_present(Block); if (!BB) continue; // If the destination block has a single pred, then this is a trivial @@ -734,7 +734,7 @@ // (Repeatedly) merging blocks into their predecessors can create redundant // debug intrinsics. for (const auto &Pred : Preds) - if (auto *BB = cast_or_null(Pred)) + if (auto *BB = cast_if_present(Pred)) RemoveRedundantDbgInstrs(BB); return Changed; @@ -795,7 +795,7 @@ Blocks.push_back(&Block); for (auto &Block : Blocks) { - BasicBlock *BB = cast_or_null(Block); + BasicBlock *BB = cast_if_present(Block); if (!BB) continue; BasicBlock *DestBB = findDestBlockOfMergeableEmptyBlock(BB); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -7744,8 +7744,8 @@ } if (EHPadBB) { - DAG.setRoot(lowerEndEH(getRoot(), cast_or_null(CLI.CB), EHPadBB, - BeginLabel)); + DAG.setRoot(lowerEndEH(getRoot(), cast_if_present(CLI.CB), + EHPadBB, BeginLabel)); } return Result; diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -180,7 +180,7 @@ if (Line) assert(File && "Source location has line number but no file"); unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); - auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null(NS), + auto *M = DIImportedEntity::get(C, Tag, Context, cast_if_present(NS), File, Line, Name, Elements); if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) // A new Imported Entity was just added to the context. @@ -497,7 +497,7 @@ VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, OffsetInBits, Flags, Elements, 0, VTableHolder, - cast_or_null(TemplateParams), UniqueIdentifier); + cast_if_present(TemplateParams), UniqueIdentifier); trackIfUnresolved(R); return R; } @@ -741,9 +741,9 @@ checkGlobalVariableScope(Context); auto *GV = DIGlobalVariable::getDistinct( - VMContext, cast_or_null(Context), Name, LinkageName, F, + VMContext, cast_if_present(Context), Name, LinkageName, F, LineNumber, Ty, IsLocalToUnit, isDefined, - cast_or_null(Decl), TemplateParams, AlignInBits, + cast_if_present(Decl), TemplateParams, AlignInBits, Annotations); if (!Expr) Expr = createExpression(); @@ -759,9 +759,9 @@ checkGlobalVariableScope(Context); return DIGlobalVariable::getTemporary( - VMContext, cast_or_null(Context), Name, LinkageName, F, + VMContext, cast_if_present(Context), Name, LinkageName, F, LineNumber, Ty, IsLocalToUnit, false, - cast_or_null(Decl), TemplateParams, AlignInBits, + cast_if_present(Decl), TemplateParams, AlignInBits, nullptr) .release(); } @@ -779,7 +779,7 @@ DIScope *Context = getNonCompileUnitScope(Scope); auto *Node = DILocalVariable::get( - VMContext, cast_or_null(Context), Name, File, LineNo, Ty, + VMContext, cast_if_present(Context), Name, File, LineNo, Ty, ArgNo, Flags, AlignInBits, Annotations); if (AlwaysPreserve) { // The optimizer may remove local variables. If there is an interest @@ -816,7 +816,7 @@ unsigned LineNo, bool AlwaysPreserve) { DIScope *Context = getNonCompileUnitScope(Scope); - auto *Node = DILabel::get(VMContext, cast_or_null(Context), + auto *Node = DILabel::get(VMContext, cast_if_present(Context), Name, File, LineNo); if (AlwaysPreserve) { diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -148,7 +148,7 @@ for (auto *CU : M.debug_compile_units()) processCompileUnit(CU); for (auto &F : M.functions()) { - if (auto *SP = cast_or_null(F.getSubprogram())) + if (auto *SP = cast_if_present(F.getSubprogram())) processSubprogram(SP); // There could be subprograms from inlined functions referenced from // instructions only. Walk the function to find them. @@ -543,13 +543,13 @@ private: // Create a new DISubprogram, to replace the one given. DISubprogram *getReplacementSubprogram(DISubprogram *MDS) { - auto *FileAndScope = cast_or_null(map(MDS->getFile())); + auto *FileAndScope = cast_if_present(map(MDS->getFile())); StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : ""; DISubprogram *Declaration = nullptr; - auto *Type = cast_or_null(map(MDS->getType())); + auto *Type = cast_if_present(map(MDS->getType())); DIType *ContainingType = - cast_or_null(map(MDS->getContainingType())); - auto *Unit = cast_or_null(map(MDS->getUnit())); + cast_if_present(map(MDS->getContainingType())); + auto *Unit = cast_if_present(map(MDS->getUnit())); auto Variables = nullptr; auto TemplateParams = nullptr; @@ -596,7 +596,7 @@ if (CU->getDWOId()) return nullptr; - auto *File = cast_or_null(map(CU->getFile())); + auto *File = cast_if_present(map(CU->getFile())); MDTuple *EnumTypes = nullptr; MDTuple *RetainedTypes = nullptr; MDTuple *GlobalVariables = nullptr; diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -601,31 +601,31 @@ } DIType *DIDerivedType::getClassType() const { assert(getTag() == dwarf::DW_TAG_ptr_to_member_type); - return cast_or_null(getExtraData()); + return cast_if_present(getExtraData()); } uint32_t DIDerivedType::getVBPtrOffset() const { assert(getTag() == dwarf::DW_TAG_inheritance); - if (auto *CM = cast_or_null(getExtraData())) + if (auto *CM = cast_if_present(getExtraData())) if (auto *CI = dyn_cast_if_present(CM->getValue())) return static_cast(CI->getZExtValue()); return 0; } Constant *DIDerivedType::getStorageOffsetInBits() const { assert(getTag() == dwarf::DW_TAG_member && isBitField()); - if (auto *C = cast_or_null(getExtraData())) + if (auto *C = cast_if_present(getExtraData())) return C->getValue(); return nullptr; } Constant *DIDerivedType::getConstant() const { assert(getTag() == dwarf::DW_TAG_member && isStaticMember()); - if (auto *C = cast_or_null(getExtraData())) + if (auto *C = cast_if_present(getExtraData())) return C->getValue(); return nullptr; } Constant *DIDerivedType::getDiscriminantValue() const { assert(getTag() == dwarf::DW_TAG_member && !isStaticMember()); - if (auto *C = cast_or_null(getExtraData())) + if (auto *C = cast_if_present(getExtraData())) return C->getValue(); return nullptr; } @@ -1811,7 +1811,7 @@ // form the key to the DIArgLists store. eraseFromStore(); } - ValueAsMetadata *NewVM = cast_or_null(New); + ValueAsMetadata *NewVM = cast_if_present(New); for (ValueAsMetadata *&VM : Args) { if (&VM == OldVMPtr) { if (NewVM) diff --git a/llvm/lib/IR/DebugLoc.cpp b/llvm/lib/IR/DebugLoc.cpp --- a/llvm/lib/IR/DebugLoc.cpp +++ b/llvm/lib/IR/DebugLoc.cpp @@ -18,7 +18,7 @@ DebugLoc::DebugLoc(const MDNode *L) : Loc(const_cast(L)) {} DILocation *DebugLoc::get() const { - return cast_or_null(Loc.get()); + return cast_if_present(Loc.get()); } unsigned DebugLoc::getLine() const { diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -1216,7 +1216,7 @@ MDNode *NamedMDNode::getOperand(unsigned i) const { assert(i < getNumOperands() && "Invalid Operand number!"); auto *N = getNMDOps(Operands)[i].get(); - return cast_or_null(N); + return cast_if_present(N); } void NamedMDNode::addOperand(MDNode *M) { getNMDOps(Operands).emplace_back(M); } @@ -1581,7 +1581,7 @@ } DISubprogram *Function::getSubprogram() const { - return cast_or_null(getMetadata(LLVMContext::MD_dbg)); + return cast_if_present(getMetadata(LLVMContext::MD_dbg)); } bool Function::isDebugInfoForProfiling() const { diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -108,7 +108,7 @@ /// the specified name, of arbitrary type. This method returns null /// if a global with the specified name is not found. GlobalValue *Module::getNamedValue(StringRef Name) const { - return cast_or_null(getValueSymbolTable().lookup(Name)); + return cast_if_present(getValueSymbolTable().lookup(Name)); } unsigned Module::getNumNamedValues() const { @@ -546,27 +546,28 @@ } unsigned Module::getNumberRegisterParameters() const { - auto *Val = - cast_or_null(getModuleFlag("NumRegisterParameters")); + auto *Val = cast_if_present( + getModuleFlag("NumRegisterParameters")); if (!Val) return 0; return cast(Val->getValue())->getZExtValue(); } unsigned Module::getDwarfVersion() const { - auto *Val = cast_or_null(getModuleFlag("Dwarf Version")); + auto *Val = + cast_if_present(getModuleFlag("Dwarf Version")); if (!Val) return 0; return cast(Val->getValue())->getZExtValue(); } bool Module::isDwarf64() const { - auto *Val = cast_or_null(getModuleFlag("DWARF64")); + auto *Val = cast_if_present(getModuleFlag("DWARF64")); return Val && cast(Val->getValue())->isOne(); } unsigned Module::getCodeViewFlag() const { - auto *Val = cast_or_null(getModuleFlag("CodeView")); + auto *Val = cast_if_present(getModuleFlag("CodeView")); if (!Val) return 0; return cast(Val->getValue())->getZExtValue(); @@ -586,7 +587,7 @@ } PICLevel::Level Module::getPICLevel() const { - auto *Val = cast_or_null(getModuleFlag("PIC Level")); + auto *Val = cast_if_present(getModuleFlag("PIC Level")); if (!Val) return PICLevel::NotPIC; @@ -602,7 +603,7 @@ } PIELevel::Level Module::getPIELevel() const { - auto *Val = cast_or_null(getModuleFlag("PIE Level")); + auto *Val = cast_if_present(getModuleFlag("PIE Level")); if (!Val) return PIELevel::Default; @@ -616,7 +617,7 @@ } Optional Module::getCodeModel() const { - auto *Val = cast_or_null(getModuleFlag("Code Model")); + auto *Val = cast_if_present(getModuleFlag("Code Model")); if (!Val) return None; @@ -648,7 +649,7 @@ bool Module::getSemanticInterposition() const { Metadata *MF = getModuleFlag("SemanticInterposition"); - auto *Val = cast_or_null(MF); + auto *Val = cast_if_present(MF); if (!Val) return false; @@ -664,7 +665,7 @@ } bool Module::getRtLibUseGOT() const { - auto *Val = cast_or_null(getModuleFlag("RtLibUseGOT")); + auto *Val = cast_if_present(getModuleFlag("RtLibUseGOT")); return Val && (cast(Val->getValue())->getZExtValue() > 0); } @@ -673,7 +674,7 @@ } UWTableKind Module::getUwtable() const { - if (auto *Val = cast_or_null(getModuleFlag("uwtable"))) + if (auto *Val = cast_if_present(getModuleFlag("uwtable"))) return UWTableKind(cast(Val->getValue())->getZExtValue()); return UWTableKind::None; } @@ -683,7 +684,8 @@ } FramePointerKind Module::getFramePointer() const { - auto *Val = cast_or_null(getModuleFlag("frame-pointer")); + auto *Val = + cast_if_present(getModuleFlag("frame-pointer")); return static_cast( Val ? cast(Val->getValue())->getZExtValue() : 0); } diff --git a/llvm/lib/IR/SafepointIRVerifier.cpp b/llvm/lib/IR/SafepointIRVerifier.cpp --- a/llvm/lib/IR/SafepointIRVerifier.cpp +++ b/llvm/lib/IR/SafepointIRVerifier.cpp @@ -185,7 +185,7 @@ if (!DeadEdges.insert(&DeadEdge)) return; - BasicBlock *BB = cast_or_null(DeadEdge.get()); + BasicBlock *BB = cast_if_present(DeadEdge.get()); if (hasLiveIncomingEdges(BB)) return; diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -515,7 +515,7 @@ ELFSymbolData &MSD, const MCAsmLayout &Layout) { const auto &Symbol = cast(*MSD.Symbol); const MCSymbolELF *Base = - cast_or_null(Layout.getBaseSymbol(Symbol)); + cast_if_present(Layout.getBaseSymbol(Symbol)); // This has to be in sync with when computeSymbolTable uses SHN_ABS or // SHN_COMMON. diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -669,7 +669,7 @@ if (UseLastGroup) { MCSectionSubPair CurrentSection = getStreamer().getCurrentSection(); if (const MCSectionELF *Section = - cast_or_null(CurrentSection.first)) + cast_if_present(CurrentSection.first)) if (const MCSymbol *Group = Section->getGroup()) { GroupName = Group->getName(); IsComdat = Section->isComdat(); diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -591,7 +591,8 @@ // TABLE_INDEX relocs implicitly use the default indirect function table. // We require the function table to have already been defined. auto TableName = "__indirect_function_table"; - MCSymbolWasm *Sym = cast_or_null(Ctx.lookupSymbol(TableName)); + MCSymbolWasm *Sym = + cast_if_present(Ctx.lookupSymbol(TableName)); if (!Sym) { report_fatal_error("missing indirect function table symbol"); } else { diff --git a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp --- a/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp +++ b/llvm/lib/Target/Hexagon/HexagonCommonGEP.cpp @@ -676,7 +676,7 @@ return nullptr; BasicBlock *Dom = cast(*I); while (++I != E) { - BasicBlock *B = cast_or_null(*I); + BasicBlock *B = cast_if_present(*I); Dom = B ? DT->findNearestCommonDominator(Dom, B) : nullptr; if (!Dom) return nullptr; @@ -886,7 +886,7 @@ // the Node will be speculated. // For nodes that are not in the main path of the containing loop (i.e. // are not executed in each iteration), do not move them out of the loop. - BasicBlock *LocB = cast_or_null(Loc[Node]); + BasicBlock *LocB = cast_if_present(Loc[Node]); if (LocB) { Loop *Lp = LI->getLoopFor(LocB); while (Lp) { @@ -924,7 +924,7 @@ raw_ostream &operator<< (raw_ostream &OS, const LocationAsBlock &Loc) { for (const auto &I : Loc.Map) { OS << I.first << " -> "; - if (BasicBlock *B = cast_or_null(I.second)) + if (BasicBlock *B = cast_if_present(I.second)) OS << B->getName() << '(' << B << ')'; else OS << ""; @@ -1182,7 +1182,7 @@ if (LastCN != 1) break; GepNode *Child = CF->second.front(); - BasicBlock *ChildB = cast_or_null(Loc[Child]); + BasicBlock *ChildB = cast_if_present(Loc[Child]); if (ChildB != nullptr && LastB != ChildB) break; Last = Child; diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -181,7 +181,7 @@ static MCSymbolWasm *GetOrCreateFunctionTableSymbol(MCContext &Ctx, const StringRef &Name) { - MCSymbolWasm *Sym = cast_or_null(Ctx.lookupSymbol(Name)); + MCSymbolWasm *Sym = cast_if_present(Ctx.lookupSymbol(Name)); if (Sym) { if (!Sym->isFunctionTable()) Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table"); diff --git a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp --- a/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp +++ b/llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp @@ -125,7 +125,7 @@ MCSymbolWasm *WebAssembly::getOrCreateFunctionTableSymbol( MCContext &Ctx, const WebAssemblySubtarget *Subtarget) { StringRef Name = "__indirect_function_table"; - MCSymbolWasm *Sym = cast_or_null(Ctx.lookupSymbol(Name)); + MCSymbolWasm *Sym = cast_if_present(Ctx.lookupSymbol(Name)); if (Sym) { if (!Sym->isFunctionTable()) Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table"); @@ -144,7 +144,7 @@ MCSymbolWasm *WebAssembly::getOrCreateFuncrefCallTableSymbol( MCContext &Ctx, const WebAssemblySubtarget *Subtarget) { StringRef Name = "__funcref_call_table"; - MCSymbolWasm *Sym = cast_or_null(Ctx.lookupSymbol(Name)); + MCSymbolWasm *Sym = cast_if_present(Ctx.lookupSymbol(Name)); if (Sym) { if (!Sym->isFunctionTable()) Ctx.reportError(SMLoc(), "symbol is not a wasm funcref table"); diff --git a/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp --- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp +++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp @@ -164,7 +164,7 @@ LLVM_DEBUG(dbgs() << "Building type info -> vtable map\n"); auto *LTOPostLinkMD = - cast_or_null(M.getModuleFlag("LTOPostLink")); + cast_if_present(M.getModuleFlag("LTOPostLink")); bool LTOPostLink = LTOPostLinkMD && (cast(LTOPostLinkMD->getValue())->getZExtValue() != 0); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -396,7 +396,7 @@ if (Instruction *Res = FoldShiftByConstant(Op0, CUI, I)) return Res; - if (auto *NewShift = cast_or_null( + if (auto *NewShift = cast_if_present( reassociateShiftAmtsOfTwoSameDirectionShifts(&I, SQ))) return NewShift; diff --git a/llvm/lib/Transforms/Scalar/FlattenCFGPass.cpp b/llvm/lib/Transforms/Scalar/FlattenCFGPass.cpp --- a/llvm/lib/Transforms/Scalar/FlattenCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/FlattenCFGPass.cpp @@ -59,7 +59,7 @@ // Loop over all of the basic blocks and try to flatten them. for (WeakVH &BlockHandle : Blocks) { // Skip blocks erased by FlattenCFG. - if (auto *BB = cast_or_null(BlockHandle)) + if (auto *BB = cast_if_present(BlockHandle)) if (FlattenCFG(BB, AA)) LocalChange = true; } diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -1136,7 +1136,7 @@ // Fixes all the undef uses generated by cloneInstructionWithNewAddressSpace. for (const Use *UndefUse : UndefUsesToFix) { User *V = UndefUse->getUser(); - User *NewV = cast_or_null(ValueWithNewAddrSpace.lookup(V)); + User *NewV = cast_if_present(ValueWithNewAddrSpace.lookup(V)); if (!NewV) continue; diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1473,7 +1473,7 @@ SafetyInfo.removeInstruction(&I); SafetyInfo.insertInstructionTo(&I, Dest.getParent()); I.moveBefore(&Dest); - if (MemoryUseOrDef *OldMemAcc = cast_or_null( + if (MemoryUseOrDef *OldMemAcc = cast_if_present( MSSAU.getMemorySSA()->getMemoryAccess(&I))) MSSAU.moveToPlace(OldMemAcc, Dest.getParent(), MemorySSA::BeforeTerminator); if (SE) diff --git a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp --- a/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp @@ -665,7 +665,7 @@ for (auto &Block : Blocks) { // Attempt to merge blocks in the trivial case. Don't modify blocks which // belong to other loops. - BasicBlock *Succ = cast_or_null(Block); + BasicBlock *Succ = cast_if_present(Block); if (!Succ) continue; diff --git a/llvm/lib/Transforms/Scalar/LoopSink.cpp b/llvm/lib/Transforms/Scalar/LoopSink.cpp --- a/llvm/lib/Transforms/Scalar/LoopSink.cpp +++ b/llvm/lib/Transforms/Scalar/LoopSink.cpp @@ -253,7 +253,7 @@ I.moveBefore(&*MoveBB->getFirstInsertionPt()); if (MSSAU) - if (MemoryUseOrDef *OldMemAcc = cast_or_null( + if (MemoryUseOrDef *OldMemAcc = cast_if_present( MSSAU->getMemorySSA()->getMemoryAccess(&I))) MSSAU->moveToPlace(OldMemAcc, MoveBB, MemorySSA::Beginning); diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -404,7 +404,7 @@ // memsets. MemoryDef *LastMemDef = nullptr; for (++BI; !BI->isTerminator(); ++BI) { - auto *CurrentAcc = cast_or_null( + auto *CurrentAcc = cast_if_present( MSSAU->getMemorySSA()->getMemoryAccess(&*BI)); if (CurrentAcc) { MemInsertPoint = CurrentAcc; diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -1203,7 +1203,8 @@ for (auto *LoopBB : L.blocks()) if (SkipBlock(LoopBB)) for (auto *SuccBB : successors(LoopBB)) - if (auto *ClonedSuccBB = cast_or_null(VMap.lookup(SuccBB))) + if (auto *ClonedSuccBB = + cast_if_present(VMap.lookup(SuccBB))) for (PHINode &PN : ClonedSuccBB->phis()) PN.removeIncomingValue(LoopBB, /*DeletePHIIfEmpty*/ false); @@ -1214,7 +1215,7 @@ if (SuccBB == UnswitchedSuccBB) continue; - auto *ClonedSuccBB = cast_or_null(VMap.lookup(SuccBB)); + auto *ClonedSuccBB = cast_if_present(VMap.lookup(SuccBB)); if (!ClonedSuccBB) continue; @@ -1356,7 +1357,7 @@ SmallDenseMap ExitLoopMap; ClonedExitsInLoops.reserve(ExitBlocks.size()); for (auto *ExitBB : ExitBlocks) - if (auto *ClonedExitBB = cast_or_null(VMap.lookup(ExitBB))) + if (auto *ClonedExitBB = cast_if_present(VMap.lookup(ExitBB))) if (Loop *ExitL = LI.getLoopFor(ExitBB)) { ExitLoopMap[ClonedExitBB] = ExitL; ClonedExitsInLoops.push_back(ClonedExitBB); @@ -1374,7 +1375,7 @@ // aren't in unreachable cycles, etc. SmallSetVector ClonedLoopBlocks; for (auto *BB : OrigL.blocks()) - if (auto *ClonedBB = cast_or_null(VMap.lookup(BB))) + if (auto *ClonedBB = cast_if_present(VMap.lookup(BB))) ClonedLoopBlocks.insert(ClonedBB); // Rebuild the set of blocks that will end up in the cloned loop. We may have @@ -1440,7 +1441,7 @@ // that logic, we just re-walk the original blocks (and those of the child // loops) and filter them as we add them into the cloned loop. for (auto *BB : OrigL.blocks()) { - auto *ClonedBB = cast_or_null(VMap.lookup(BB)); + auto *ClonedBB = cast_if_present(VMap.lookup(BB)); if (!ClonedBB || !BlocksInClonedLoop.count(ClonedBB)) continue; @@ -1463,7 +1464,7 @@ // child loop nest. for (Loop *ChildL : OrigL) { auto *ClonedChildHeader = - cast_or_null(VMap.lookup(ChildL->getHeader())); + cast_if_present(VMap.lookup(ChildL->getHeader())); if (!ClonedChildHeader || !BlocksInClonedLoop.count(ClonedChildHeader)) continue; @@ -1570,7 +1571,7 @@ // clone them into whatever outer loop we placed their header into. for (Loop *ChildL : OrigL) { auto *ClonedChildHeader = - cast_or_null(VMap.lookup(ChildL->getHeader())); + cast_if_present(VMap.lookup(ChildL->getHeader())); if (!ClonedChildHeader || BlocksInClonedLoop.count(ClonedChildHeader)) continue; @@ -1593,7 +1594,7 @@ SmallVector DeadBlocks; for (BasicBlock *BB : llvm::concat(L.blocks(), ExitBlocks)) for (const auto &VMap : VMaps) - if (BasicBlock *ClonedBB = cast_or_null(VMap->lookup(BB))) + if (BasicBlock *ClonedBB = cast_if_present(VMap->lookup(BB))) if (!DT.isReachableFromEntry(ClonedBB)) { for (BasicBlock *SuccBB : successors(ClonedBB)) SuccBB->removePredecessor(ClonedBB); diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -291,7 +291,7 @@ // Terminator may be a memory accessing instruction too. if (MSSAU) - if (MemoryUseOrDef *MUD = cast_or_null( + if (MemoryUseOrDef *MUD = cast_if_present( MSSAU->getMemorySSA()->getMemoryAccess(PredBB->getTerminator()))) MSSAU->moveToPlace(MUD, PredBB, MemorySSA::End); } diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -645,7 +645,7 @@ SmallVector PHIToResolve; for (const BasicBlock &BI : *OldFunc) { Value *V = VMap.lookup(&BI); - BasicBlock *NewBB = cast_or_null(V); + BasicBlock *NewBB = cast_if_present(V); if (!NewBB) continue; // Dead block. @@ -687,7 +687,7 @@ PHINode *PN = cast(VMap[OPN]); for (unsigned pred = 0, e = NumPreds; pred != e; ++pred) { Value *V = VMap.lookup(PN->getIncomingBlock(pred)); - if (BasicBlock *MappedBlock = cast_or_null(V)) { + if (BasicBlock *MappedBlock = cast_if_present(V)) { Value *InVal = MapValue(PN->getIncomingValue(pred), VMap, ModuleLevelChanges ? RF_None : RF_NoModuleLevelChanges); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -556,7 +556,7 @@ // Process the dead instruction list until empty. while (!DeadInsts.empty()) { Value *V = DeadInsts.pop_back_val(); - Instruction *I = cast_or_null(V); + Instruction *I = cast_if_present(V); if (!I) continue; assert(isInstructionTriviallyDead(I, TLI) && diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -78,7 +78,7 @@ if (GV->hasInitializer()) { auto *CA = cast(GV->getInitializer()); for (auto &Op : CA->operands()) { - Constant *C = cast_or_null(Op); + Constant *C = cast_if_present(Op); if (InitAsSet.insert(C).second) Init.push_back(C); } diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -149,7 +149,7 @@ void remapFunction(Function &F); Constant *mapConstant(const Constant *C) { - return cast_or_null(mapValue(C)); + return cast_if_present(mapValue(C)); } /// Map metadata. @@ -543,7 +543,7 @@ DelayedBBs.push_back(DelayedBasicBlock(BA)); BB = DelayedBBs.back().TempBB.get(); } else { - BB = cast_or_null(mapValue(BA.getBasicBlock())); + BB = cast_if_present(mapValue(BA.getBasicBlock())); } return getVM()[&BA] = BlockAddress::get(F, BB ? BB : BA.getBasicBlock()); @@ -906,7 +906,7 @@ // handled. while (!DelayedBBs.empty()) { DelayedBasicBlock DBB = DelayedBBs.pop_back_val(); - BasicBlock *BB = cast_or_null(mapValue(DBB.OldBB)); + BasicBlock *BB = cast_if_present(mapValue(DBB.OldBB)); DBB.TempBB->replaceAllUsesWith(BB ? BB : DBB.OldBB); } } @@ -941,7 +941,7 @@ I->getAllMetadata(MDs); for (const auto &MI : MDs) { MDNode *Old = MI.second; - MDNode *New = cast_or_null(mapMetadata(Old)); + MDNode *New = cast_if_present(mapMetadata(Old)); if (New != Old) I->setMetadata(MI.first, New); } @@ -1046,7 +1046,7 @@ Constant *Null = Constant::getNullValue(VoidPtrTy); NewV = ConstantStruct::get(cast(EltTy), E1, E2, Null); } else { - NewV = cast_or_null(mapValue(V)); + NewV = cast_if_present(mapValue(V)); } Elements.push_back(NewV); } @@ -1161,7 +1161,7 @@ } Constant *ValueMapper::mapConstant(const Constant &C) { - return cast_or_null(mapValue(C)); + return cast_if_present(mapValue(C)); } Metadata *ValueMapper::mapMetadata(const Metadata &MD) { @@ -1169,7 +1169,7 @@ } MDNode *ValueMapper::mapMDNode(const MDNode &N) { - return cast_or_null(mapMetadata(N)); + return cast_if_present(mapMetadata(N)); } void ValueMapper::remapInstruction(Instruction &I) { diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8475,7 +8475,7 @@ if (!PredR) continue; auto *RepR = - cast_or_null(PredR->getOperand(0)->getDef()); + cast_if_present(PredR->getOperand(0)->getDef()); assert(RepR->isPredicated() && "expected Replicate recipe to be predicated"); RepR->setAlsoPack(false); diff --git a/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp b/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanSLP.cpp @@ -344,7 +344,7 @@ void VPlanSlp::dumpBundle(ArrayRef Values) { dbgs() << " Ops: "; for (auto *Op : Values) { - if (auto *VPInstr = cast_or_null(Op)) + if (auto *VPInstr = cast_if_present(Op)) if (auto *Instr = VPInstr->getUnderlyingInstr()) { dbgs() << *Instr << " | "; continue; diff --git a/llvm/tools/opt/BreakpointPrinter.cpp b/llvm/tools/opt/BreakpointPrinter.cpp --- a/llvm/tools/opt/BreakpointPrinter.cpp +++ b/llvm/tools/opt/BreakpointPrinter.cpp @@ -46,7 +46,7 @@ if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp")) for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) { std::string Name; - auto *SP = cast_or_null(NMD->getOperand(i)); + auto *SP = cast_if_present(NMD->getOperand(i)); if (!SP) continue; getContextName(SP->getScope(), Name); diff --git a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp --- a/llvm/utils/TableGen/DAGISelMatcherOpt.cpp +++ b/llvm/utils/TableGen/DAGISelMatcherOpt.cpp @@ -365,9 +365,8 @@ // Check to see if this breaks a series of CheckTypeMatcher's. if (AllTypeChecks) { - CheckTypeMatcher *CTM = - cast_or_null(FindNodeWithKind(NewOptionsToMatch[i], - Matcher::CheckType)); + CheckTypeMatcher *CTM = cast_if_present( + FindNodeWithKind(NewOptionsToMatch[i], Matcher::CheckType)); if (!CTM || // iPTR checks could alias any other case without us knowing, don't // bother with them.