[llvm] 9c07aa7 - [TableGen] Fix null pointer dereferences in TreePattern::ParseTreePattern()

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue May 9 18:06:22 PDT 2023


Author: Alexey Vishnyakov
Date: 2023-05-09T18:06:10-07:00
New Revision: 9c07aa75b961fa19875fddd1dcd0deaa57f82e9d

URL: https://github.com/llvm/llvm-project/commit/9c07aa75b961fa19875fddd1dcd0deaa57f82e9d
DIFF: https://github.com/llvm/llvm-project/commit/9c07aa75b961fa19875fddd1dcd0deaa57f82e9d.diff

LOG: [TableGen] Fix null pointer dereferences in TreePattern::ParseTreePattern()

Bugs were found by Svace static analysis tool. Null pointers are
dereferenced right after error checking that does not return from
function.

Reviewed By: arsenm

Differential Revision: https://reviews.llvm.org/D147706

Added: 
    

Modified: 
    llvm/utils/TableGen/CodeGenDAGPatterns.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
index 512358ba915bd..ed2eda8f97923 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -2897,16 +2897,20 @@ TreePatternNodePtr TreePattern::ParseTreePattern(Init *TheInit,
     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")) {
@@ -3480,7 +3484,8 @@ void CodeGenDAGPatterns::FindPatternInputsAndOutputs(
       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;
   }


        


More information about the llvm-commits mailing list