Index: lib/TableGen/Record.cpp =================================================================== --- lib/TableGen/Record.cpp +++ lib/TableGen/Record.cpp @@ -764,7 +764,7 @@ if (LHS != lhs) return (UnOpInit::get(getOpcode(), lhs, getType())) ->Fold(R.getCurrentRecord()); - return Fold(R.getCurrentRecord()); + return const_cast(this); } std::string UnOpInit::getAsString() const { @@ -947,7 +947,7 @@ if (LHS != lhs || RHS != rhs) return (BinOpInit::get(getOpcode(), lhs, rhs, getType())) ->Fold(R.getCurrentRecord()); - return Fold(R.getCurrentRecord()); + return const_cast(this); } std::string BinOpInit::getAsString() const { @@ -1172,7 +1172,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(this); } std::string TernOpInit::getAsString() const { Index: lib/TableGen/TGParser.cpp =================================================================== --- lib/TableGen/TGParser.cpp +++ lib/TableGen/TGParser.cpp @@ -1960,7 +1960,13 @@ } if (LHS->getType() != StringRecTy::get()) { - LHS = UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get()); + LHS = dyn_cast( + UnOpInit::get(UnOpInit::CAST, LHS, StringRecTy::get()) + ->Fold(CurRec)); + if (!LHS) { + Error(PasteLoc, "LHS of paste not typed after cast!"); + return nullptr; + } } TypedInit *RHS = nullptr; @@ -1987,7 +1993,13 @@ } if (RHS->getType() != StringRecTy::get()) { - RHS = UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get()); + RHS = dyn_cast( + UnOpInit::get(UnOpInit::CAST, RHS, StringRecTy::get()) + ->Fold(CurRec)); + if (!RHS) { + Error(PasteLoc, "RHS of paste not typed after cast!"); + return nullptr; + } } break;