@@ -3012,7 +3012,15 @@ 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+ PrintFatalError (
3020+ " This type cast has zero arguments. It takes only one operand!" );
3021+ return std::nullopt ;
3022+ }
3023+
30163024 if (Dag->getNumArgs () != 1 )
30173025 error (" Type cast only takes one operand!" );
30183026
@@ -3025,7 +3033,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30253033 if (const ListInit *LI = dyn_cast<ListInit>(Dag->getOperator ())) {
30263034 // If the operator is a list (of value types), then this must be "type cast"
30273035 // of a leaf node with multiple results.
3028- TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3036+ auto MaybeNew = ParseCastOperand (Dag, OpName);
3037+ if (!MaybeNew)
3038+ return nullptr ;
3039+ TreePatternNodePtr New = *MaybeNew;
30293040
30303041 size_t NumTypes = New->getNumTypes ();
30313042 if (LI->empty () || LI->size () != NumTypes)
@@ -3050,7 +3061,10 @@ TreePatternNodePtr TreePattern::ParseTreePattern(const Init *TheInit,
30503061 if (Operator->isSubClassOf (" ValueType" )) {
30513062 // If the operator is a ValueType, then this must be "type cast" of a leaf
30523063 // node.
3053- TreePatternNodePtr New = ParseCastOperand (Dag, OpName);
3064+ auto MaybeNew = ParseCastOperand (Dag, OpName);
3065+ if (!MaybeNew)
3066+ return nullptr ;
3067+ TreePatternNodePtr New = *MaybeNew;
30543068
30553069 if (New->getNumTypes () != 1 )
30563070 error (" ValueType cast can only have one type!" );
0 commit comments