[NFC] add check for potentially dereferencing null return value
authorBing1 Yu <bing1.yu@intel.com>
Tue, 11 Apr 2023 06:42:03 +0000 (14:42 +0800)
committerBing1 Yu <bing1.yu@intel.com>
Tue, 11 Apr 2023 06:42:47 +0000 (14:42 +0800)
Reviewed By: pengfei

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

llvm/utils/TableGen/DAGISelMatcherGen.cpp

index 9992535..59e2ecb 100644 (file)
@@ -603,16 +603,17 @@ bool MatcherGen::EmitMatcherCode(unsigned Variant) {
     // Get the slot we recorded the value in from the name on the node.
     unsigned RecNodeEntry = MatchedComplexPatterns[i].second;
 
-    const ComplexPattern &CP = *N->getComplexPatternInfo(CGP);
+    const ComplexPattern *CP = N->getComplexPatternInfo(CGP);
+    assert(CP && "Not a valid ComplexPattern!");
 
     // Emit a CheckComplexPat operation, which does the match (aborting if it
     // fails) and pushes the matched operands onto the recorded nodes list.
-    AddMatcher(new CheckComplexPatMatcher(CP, RecNodeEntry,
-                                          N->getName(), NextRecordedOperandNo));
+    AddMatcher(new CheckComplexPatMatcher(*CP, RecNodeEntry, N->getName(),
+                                          NextRecordedOperandNo));
 
     // Record the right number of operands.
-    NextRecordedOperandNo += CP.getNumOperands();
-    if (CP.hasProperty(SDNPHasChain)) {
+    NextRecordedOperandNo += CP->getNumOperands();
+    if (CP->hasProperty(SDNPHasChain)) {
       // If the complex pattern has a chain, then we need to keep track of the
       // fact that we just recorded a chain input.  The chain input will be
       // matched as the last operand of the predicate if it was successful.