[PATCH] D44198: TableGen: Only fold when some operand made resolve progress

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 19 07:16:56 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL327847: TableGen: Only fold when some operand made resolve progress (authored by nha, committed by ).

Repository:
  rL LLVM

https://reviews.llvm.org/D44198

Files:
  llvm/trunk/lib/TableGen/Record.cpp
  llvm/trunk/lib/TableGen/TGParser.cpp


Index: llvm/trunk/lib/TableGen/Record.cpp
===================================================================
--- llvm/trunk/lib/TableGen/Record.cpp
+++ llvm/trunk/lib/TableGen/Record.cpp
@@ -765,7 +765,7 @@
   if (LHS != lhs)
     return (UnOpInit::get(getOpcode(), lhs, getType()))
         ->Fold(R.getCurrentRecord());
-  return Fold(R.getCurrentRecord());
+  return const_cast<UnOpInit *>(this);
 }
 
 std::string UnOpInit::getAsString() const {
@@ -948,7 +948,7 @@
   if (LHS != lhs || RHS != rhs)
     return (BinOpInit::get(getOpcode(), lhs, rhs, getType()))
         ->Fold(R.getCurrentRecord());
-  return Fold(R.getCurrentRecord());
+  return const_cast<BinOpInit *>(this);
 }
 
 std::string BinOpInit::getAsString() const {
@@ -1173,7 +1173,7 @@
   if (LHS != lhs || MHS != mhs || RHS != rhs)
     return (TernOpInit::get(getOpcode(), lhs, mhs, rhs, getType()))
         ->Fold(R.getCurrentRecord());
-  return Fold(R.getCurrentRecord());
+  return const_cast<TernOpInit *>(this);
 }
 
 std::string TernOpInit::getAsString() const {
Index: llvm/trunk/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/trunk/lib/TableGen/TGParser.cpp
+++ llvm/trunk/lib/TableGen/TGParser.cpp
@@ -1961,7 +1961,14 @@
       }
 
       if (LHS->getType() != StringRecTy::get()) {
-        LHS = UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get());
+        LHS = dyn_cast<TypedInit>(
+            UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get())
+                ->Fold(CurRec));
+        if (!LHS) {
+          Error(PasteLoc, Twine("can't cast '") + LHS->getAsString() +
+                              "' to string");
+          return nullptr;
+        }
       }
 
       TypedInit *RHS = nullptr;
@@ -1988,7 +1995,14 @@
         }
 
         if (RHS->getType() != StringRecTy::get()) {
-          RHS = UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get());
+          RHS = dyn_cast<TypedInit>(
+              UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get())
+                  ->Fold(CurRec));
+          if (!RHS) {
+            Error(PasteLoc, Twine("can't cast '") + RHS->getAsString() +
+                                "' to string");
+            return nullptr;
+          }
         }
 
         break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44198.138914.patch
Type: text/x-patch
Size: 2278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180319/484f00b8/attachment.bin>


More information about the llvm-commits mailing list