@@ -3010,7 +3010,14 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30103010 return nullptr ;
30113011 }
30123012
3013- auto ParseCastOperand = [this ](const DagInit *Dag, StringRef OpName) {
3013+ auto ParseCastOperand =
3014+ [this ](const DagInit *Dag,
3015+ StringRef OpName) -> std::optional<TreePatternNodePtr> {
3016+ if (Dag->getNumArgs () == 0 ) {
3017+ error (" type cast should not have zero arguments!" );
3018+ return std::nullopt ;
3019+ }
3020+
30143021 if (Dag->getNumArgs () != 1 )
30153022 error (" Type cast only takes one operand!" );
30163023
@@ -3023,7 +3030,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30233030 if (const ListInit *LI = dyn_cast<ListInit>(Dag->getOperator ())) {
30243031 // If the operator is a list (of value types), then this must be "type cast"
30253032 // of a leaf node with multiple results.
3026- TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3033+ auto MaybeNew = ParseCastOperand (Dag, OpName);
3034+ if (!MaybeNew)
3035+ return nullptr ;
3036+ TreePatternNodePtr New = *MaybeNew;
30273037
30283038 size_t NumTypes = New->getNumTypes ();
30293039 if (LI->empty () || LI->size () != NumTypes)
@@ -3048,7 +3058,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30483058 if (Operator->isSubClassOf (" ValueType" )) {
30493059 // If the operator is a ValueType, then this must be "type cast" of a leaf
30503060 // node.
3051- TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3061+ auto MaybeNew = ParseCastOperand (Dag, OpName);
3062+ if (!MaybeNew)
3063+ return nullptr ;
3064+ TreePatternNodePtr New = *MaybeNew;
30523065
30533066 if (New->getNumTypes () != 1 )
30543067 error (" ValueType cast can only have one type!" );
@@ -3606,10 +3619,15 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
36063619 // If this is not a set, verify that the children nodes are not void typed,
36073620 // and recurse.
36083621 for (unsigned i = 0 , e = Pat->getNumChildren (); i != e; ++i) {
3609- if (Pat->getChild (i).getNumTypes () == 0 )
3622+ TreePatternNodePtr Child = Pat->getChildShared (i);
3623+ if (!Child) {
3624+ I.error (" Child node at index " + Twine (i) + " is null!" );
3625+ continue ;
3626+ }
3627+ if (Child->getNumTypes () == 0 )
36103628 I.error (" Cannot have void nodes inside of patterns!" );
3611- FindPatternInputsAndOutputs (I, Pat-> getChildShared (i) , InstInputs,
3612- InstResults, InstImpResults);
3629+ FindPatternInputsAndOutputs (I, Child , InstInputs, InstResults ,
3630+ InstImpResults);
36133631 }
36143632
36153633 // If this is a non-leaf node with no children, treat it basically as if
0 commit comments