Skip to content

Commit

Permalink
[TableGen] Fix a potential crash when operand doesn't appear in the i…
Browse files Browse the repository at this point in the history
…nstruction pattern (llvm#87663)

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.
  • Loading branch information
shiltian authored Apr 5, 2024
1 parent 852eb20 commit cfadf3f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3858,8 +3858,10 @@ void CodeGenDAGPatterns::parseInstructionPattern(CodeGenInstruction &CGI,
for (unsigned i = NumResults, e = CGI.Operands.size(); i != e; ++i) {
CGIOperandList::OperandInfo &Op = CGI.Operands[i];
const std::string &OpName = Op.Name;
if (OpName.empty())
if (OpName.empty()) {
I.error("Operand #" + Twine(i) + " in operands list has no name!");
continue;
}

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

if (InVal->isLeaf() && isa<DefInit>(InVal->getLeafValue())) {
Record *InRec = cast<DefInit>(InVal->getLeafValue())->getDef();
if (!checkOperandClass(Op, InRec))
if (!checkOperandClass(Op, InRec)) {
I.error("Operand $" + OpName +
"'s register class disagrees"
" between the operand and pattern");
continue;
}
}
Operands.push_back(Op.Rec);

Expand Down

0 comments on commit cfadf3f

Please sign in to comment.