[PATCH] D147706: [TableGen] Fix null pointer dereferences in TreePattern::ParseTreePattern()
Alexey Vishnyakov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 6 06:54:54 PDT 2023
SweetVishnya created this revision.
SweetVishnya added reviewers: arsenm, craig.topper, gchatelet, nikic.
Herald added a subscriber: StephenFan.
Herald added a project: All.
SweetVishnya requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.
Bugs were found by Svace static analysis tool. Null pointers are
dereferenced right after error checking that does not return from
function.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147706
Files:
llvm/utils/TableGen/CodeGenDAGPatterns.cpp
Index: llvm/utils/TableGen/CodeGenDAGPatterns.cpp
===================================================================
--- llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -2903,16 +2903,20 @@
Init *II = BI->convertInitializerTo(IntRecTy::get(RK));
if (!II || !isa<IntInit>(II))
error("Bits value must be constants!");
- return ParseTreePattern(II, OpName);
+ return II ? ParseTreePattern(II, OpName) : nullptr;
}
DagInit *Dag = dyn_cast<DagInit>(TheInit);
if (!Dag) {
TheInit->print(errs());
error("Pattern has unexpected init kind!");
+ return nullptr;
}
DefInit *OpDef = dyn_cast<DefInit>(Dag->getOperator());
- if (!OpDef) error("Pattern has unexpected operator type!");
+ if (!OpDef) {
+ error("Pattern has unexpected operator type!");
+ return nullptr;
+ }
Record *Operator = OpDef->getDef();
if (Operator->isSubClassOf("ValueType")) {
@@ -3489,7 +3493,8 @@
DefInit *Val = dyn_cast<DefInit>(Dest->getLeafValue());
if (!Val || !Val->getDef()->isSubClassOf("Register"))
I.error("implicitly defined value should be a register!");
- InstImpResults.push_back(Val->getDef());
+ if (Val)
+ InstImpResults.push_back(Val->getDef());
}
return;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147706.511401.patch
Type: text/x-patch
Size: 1308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230406/fb97488a/attachment.bin>
More information about the llvm-commits
mailing list