diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index e76f2a05a4894..331e2bc7942ba 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -765,7 +765,7 @@ Init *UnOpInit::resolveReferences(Resolver &R) const { 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 { @@ -948,7 +948,7 @@ Init *BinOpInit::resolveReferences(Resolver &R) const { 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 { @@ -1173,7 +1173,7 @@ Init *TernOpInit::resolveReferences(Resolver &R) const { 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 { diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 5f19d55e9e8bf..0c92cf7496578 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -1961,7 +1961,14 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) { } 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, Twine("can't cast '") + LHS->getAsString() + + "' to string"); + return nullptr; + } } TypedInit *RHS = nullptr; @@ -1988,7 +1995,14 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) { } 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, Twine("can't cast '") + RHS->getAsString() + + "' to string"); + return nullptr; + } } break;