@@ -3010,7 +3010,13 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30103010 return nullptr ;
30113011 }
30123012
3013- auto ParseCastOperand = [this ](const DagInit *Dag, StringRef OpName) {
3013+ auto ParseCastOperand = [this ](const DagInit *Dag,
3014+ StringRef OpName) -> TreePatternNodePtr {
3015+ if (Dag->getNumArgs () == 0 ) {
3016+ error (" type cast should not have zero arguments!" );
3017+ return nullptr ;
3018+ }
3019+
30143020 if (Dag->getNumArgs () != 1 )
30153021 error (" Type cast only takes one operand!" );
30163022
@@ -3024,6 +3030,8 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30243030 // If the operator is a list (of value types), then this must be "type cast"
30253031 // of a leaf node with multiple results.
30263032 TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3033+ if (!New)
3034+ return nullptr ;
30273035
30283036 size_t NumTypes = New->getNumTypes ();
30293037 if (LI->empty () || LI->size () != NumTypes)
@@ -3049,6 +3057,8 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30493057 // If the operator is a ValueType, then this must be "type cast" of a leaf
30503058 // node.
30513059 TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3060+ if (!New)
3061+ return nullptr ;
30523062
30533063 if (New->getNumTypes () != 1 )
30543064 error (" ValueType cast can only have one type!" );
@@ -3606,10 +3616,15 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
36063616 // If this is not a set, verify that the children nodes are not void typed,
36073617 // and recurse.
36083618 for (unsigned i = 0 , e = Pat->getNumChildren (); i != e; ++i) {
3609- if (Pat->getChild (i).getNumTypes () == 0 )
3619+ TreePatternNodePtr Child = Pat->getChildShared (i);
3620+ if (!Child) {
3621+ I.error (" Child node at index " + Twine (i) + " is null!" );
3622+ continue ;
3623+ }
3624+ if (Child->getNumTypes () == 0 )
36103625 I.error (" Cannot have void nodes inside of patterns!" );
3611- FindPatternInputsAndOutputs (I, Pat-> getChildShared (i) , InstInputs,
3612- InstResults, InstImpResults);
3626+ FindPatternInputsAndOutputs (I, Child , InstInputs, InstResults ,
3627+ InstImpResults);
36133628 }
36143629
36153630 // If this is a non-leaf node with no children, treat it basically as if
0 commit comments