Skip to content

Commit 9d74723

Browse files
committed
[TableGen] Fix a potential crash when operand doesn't appear in the instruction pattern
We have a check of whether an operand is in the instruction pattern, and emit an error if it is not, but we simply continue execution, including directly dereferencing a point-like object `InVal`, which will be just created when accessing the map. It contains a `nullptr` so dereferencing it causes crash. This is a very trivial fix.
1 parent c91a0a2 commit 9d74723

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3858,8 +3858,10 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
38583858
for (unsigned i = NumResults, e = CGI.Operands.size(); i != e; ++i) {
38593859
CGIOperandList::OperandInfo &Op = CGI.Operands[i];
38603860
const std::string &OpName = Op.Name;
3861-
if (OpName.empty())
3861+
if (OpName.empty()) {
38623862
I.error("Operand #" + Twine(i) + " in operands list has no name!");
3863+
continue;
3864+
}
38633865

38643866
if (!InstInputs.count(OpName)) {
38653867
// If this is an operand with a DefaultOps set filled in, we can ignore
@@ -3872,16 +3874,19 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
38723874
}
38733875
I.error("Operand $" + OpName +
38743876
" does not appear in the instruction pattern");
3877+
continue;
38753878
}
38763879
TreePatternNodePtr InVal = InstInputs[OpName];
38773880
InstInputs.erase(OpName); // It occurred, remove from map.
38783881

38793882
if (InVal->isLeaf() && isa<DefInit>(InVal->getLeafValue())) {
38803883
Record *InRec = cast<DefInit>(InVal->getLeafValue())->getDef();
3881-
if (!checkOperandClass(Op, InRec))
3884+
if (!checkOperandClass(Op, InRec)) {
38823885
I.error("Operand $" + OpName +
38833886
"'s register class disagrees"
38843887
" between the operand and pattern");
3888+
continue;
3889+
}
38853890
}
38863891
Operands.push_back(Op.Rec);
38873892

0 commit comments

Comments
 (0)