@@ -3012,7 +3012,14 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30123012 return nullptr ;
30133013 }
30143014
3015- auto ParseCastOperand = [this ](const DagInit *Dag, StringRef OpName) {
3015+ auto ParseCastOperand =
3016+ [this ](const DagInit *Dag,
3017+ StringRef OpName) -> std::optional<TreePatternNodePtr> {
3018+ if (Dag->getNumArgs () == 0 ) {
3019+ error (" This type cast has zero arguments. It takes only one operand!" );
3020+ return std::nullopt ;
3021+ }
3022+
30163023 if (Dag->getNumArgs () != 1 )
30173024 error (" Type cast only takes one operand!" );
30183025
@@ -3025,7 +3032,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30253032 if (const ListInit *LI = dyn_cast<ListInit>(Dag->getOperator ())) {
30263033 // If the operator is a list (of value types), then this must be "type cast"
30273034 // of a leaf node with multiple results.
3028- TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3035+ auto MaybeNew = ParseCastOperand (Dag, OpName);
3036+ if (!MaybeNew)
3037+ return nullptr ;
3038+ TreePatternNodePtr New = *MaybeNew;
30293039
30303040 size_t NumTypes = New->getNumTypes ();
30313041 if (LI->empty () || LI->size () != NumTypes)
@@ -3050,7 +3060,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30503060 if (Operator->isSubClassOf (" ValueType" )) {
30513061 // If the operator is a ValueType, then this must be "type cast" of a leaf
30523062 // node.
3053- TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3063+ auto MaybeNew = ParseCastOperand (Dag, OpName);
3064+ if (!MaybeNew)
3065+ return nullptr ;
3066+ TreePatternNodePtr New = *MaybeNew;
30543067
30553068 if (New->getNumTypes () != 1 )
30563069 error (" ValueType cast can only have one type!" );
@@ -3608,10 +3621,15 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
36083621 // If this is not a set, verify that the children nodes are not void typed,
36093622 // and recurse.
36103623 for (unsigned i = 0 , e = Pat->getNumChildren (); i != e; ++i) {
3611- if (Pat->getChild (i).getNumTypes () == 0 )
3624+ TreePatternNodePtr Child = Pat->getChildShared (i);
3625+ if (!Child) {
3626+ I.error (" Child node at index " + Twine (i) + " is null!" );
3627+ continue ;
3628+ }
3629+ if (Child->getNumTypes () == 0 )
36123630 I.error (" Cannot have void nodes inside of patterns!" );
3613- FindPatternInputsAndOutputs (I, Pat-> getChildShared (i) , InstInputs,
3614- InstResults, InstImpResults);
3631+ FindPatternInputsAndOutputs (I, Child , InstInputs, InstResults ,
3632+ InstImpResults);
36153633 }
36163634
36173635 // If this is a non-leaf node with no children, treat it basically as if
0 commit comments