]> granicus.if.org Git - llvm/commitdiff
TGParser::ParseOperation - silence static analyzer dyn_cast<TypedInit> null dereferen...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 26 Sep 2019 17:11:02 +0000 (17:11 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 26 Sep 2019 17:11:02 +0000 (17:11 +0000)
The static analyzer is warning about a potential null dereference, but we should be able to use cast<TypedInit> directly and if not assert will fire for us.

I've also pulled out the repeated getType() call which was the only user of the pointer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@372997 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TableGen/TGParser.cpp

index a076966aff0cb4d5e774526e9dadf9368237f584..c373e2899a5d8cd4bc41fa92319381efea9c677c 100644 (file)
@@ -1147,9 +1147,9 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
       if (!InitList.back()) return nullptr;
 
       // All BinOps require their arguments to be of compatible types.
-      TypedInit *TI = dyn_cast<TypedInit>(InitList.back());
+      RecTy *ListType = cast<TypedInit>(InitList.back())->getType();
       if (!ArgType) {
-        ArgType = TI->getType();
+        ArgType = ListType;
 
         switch (Code) {
         case BinOpInit::LISTCONCAT:
@@ -1198,11 +1198,11 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
         default: llvm_unreachable("other ops have fixed argument types");
         }
       } else {
-        RecTy *Resolved = resolveTypes(ArgType, TI->getType());
+        RecTy *Resolved = resolveTypes(ArgType, ListType);
         if (!Resolved) {
           Error(InitLoc, Twine("expected value of type '") +
-                         ArgType->getAsString() + "', got '" +
-                         TI->getType()->getAsString() + "'");
+                             ArgType->getAsString() + "', got '" +
+                             ListType->getAsString() + "'");
           return nullptr;
         }
         if (Code != BinOpInit::ADD && Code != BinOpInit::AND &&