]> granicus.if.org Git - llvm/commitdiff
[TableGen] Fix null pointer dereferencing in token parser.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 30 Apr 2019 13:09:55 +0000 (13:09 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 30 Apr 2019 13:09:55 +0000 (13:09 +0000)
Reported in https://www.viva64.com/en/b/0629/

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

lib/TableGen/TGParser.cpp

index 937de9e5c52f120adb2746b49d248aa0a7bcad1e..6a460870aa9219a55713a168f53fd3b09c3fc8ed 100644 (file)
@@ -2189,14 +2189,15 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
       // Create a !strconcat() operation, first casting each operand to
       // a string if necessary.
       if (LHS->getType() != StringRecTy::get()) {
-        LHS = dyn_cast<TypedInit>(
+        auto CastLHS = dyn_cast<TypedInit>(
             UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get())
                 ->Fold(CurRec));
-        if (!LHS) {
-          Error(PasteLoc, Twine("can't cast '") + LHS->getAsString() +
-                              "' to string");
+        if (!CastLHS) {
+          Error(PasteLoc,
+                Twine("can't cast '") + LHS->getAsString() + "' to string");
           return nullptr;
         }
+        LHS = CastLHS;
       }
 
       TypedInit *RHS = nullptr;
@@ -2223,14 +2224,15 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
         }
 
         if (RHS->getType() != StringRecTy::get()) {
-          RHS = dyn_cast<TypedInit>(
+          auto CastRHS = dyn_cast<TypedInit>(
               UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get())
                   ->Fold(CurRec));
-          if (!RHS) {
-            Error(PasteLoc, Twine("can't cast '") + RHS->getAsString() +
-                                "' to string");
+          if (!CastRHS) {
+            Error(PasteLoc,
+                  Twine("can't cast '") + RHS->getAsString() + "' to string");
             return nullptr;
           }
+          RHS = CastRHS;
         }
 
         break;