DAGISelMatcherOpt - TGParser::ParseOperation - silence static analyzer cast_or_null...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 26 Sep 2019 17:38:47 +0000 (17:38 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 26 Sep 2019 17:38:47 +0000 (17:38 +0000)
The static analyzer is warning about a potential null dereference, replace with an null/isa assertion and cast<CheckTypeMatcher>.

llvm-svn: 373001

llvm/utils/TableGen/DAGISelMatcherOpt.cpp

index 7d51b07..6746fdd 100644 (file)
@@ -409,13 +409,14 @@ static void FactorNodes(std::unique_ptr<Matcher> &InputMatcherPtr) {
     DenseMap<unsigned, unsigned> TypeEntry;
     SmallVector<std::pair<MVT::SimpleValueType, Matcher*>, 8> Cases;
     for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) {
-      CheckTypeMatcher *CTM =
-        cast_or_null<CheckTypeMatcher>(FindNodeWithKind(NewOptionsToMatch[i],
-                                                        Matcher::CheckType));
+      Matcher* M = FindNodeWithKind(NewOptionsToMatch[i], Matcher::CheckType);
+      assert(M && isa<CheckTypeMatcher>(M) && "Unknown Matcher type");
+
+      auto *CTM = cast<CheckTypeMatcher>(M);
       Matcher *MatcherWithoutCTM = NewOptionsToMatch[i]->unlinkNode(CTM);
       MVT::SimpleValueType CTMTy = CTM->getType();
       delete CTM;
-      
+
       unsigned &Entry = TypeEntry[CTMTy];
       if (Entry != 0) {
         // If we have unfactored duplicate types, then we should factor them.