aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorShilei Tian <i@tianshilei.me>2024-04-04 20:29:26 -0400
committerGitHub <noreply@github.com>2024-04-04 20:29:26 -0400
commitcfadf3f62230505c1156e07f46c06813271bb5ac (patch)
tree8c72d787c3a2500f9cda037ad80250fa672b34a4 /llvm
parent852eb20b4f091a535ef758407d8555798b0ad809 (diff)
downloadllvm-cfadf3f62230505c1156e07f46c06813271bb5ac.zip
llvm-cfadf3f62230505c1156e07f46c06813271bb5ac.tar.gz
llvm-cfadf3f62230505c1156e07f46c06813271bb5ac.tar.bz2
[TableGen] Fix a potential crash when operand doesn't appear in the instruction pattern (#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.
Diffstat (limited to 'llvm')
-rw-r--r--llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 076d042..7a5d2be 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -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
@@ -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);