diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index e5f6f165d13..10e80fb9190 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -77,7 +77,8 @@ bool TGParser::AddValue(Record *CurRec, SMLoc Loc, const RecordVal &RV) { /// SetValue - /// Return true on error, false on success. bool TGParser::SetValue(Record *CurRec, SMLoc Loc, Init *ValName, - const std::vector &BitList, Init *V) { + const std::vector &BitList, Init *V, + bool AllowSelfAssignment) { if (!V) return false; if (!CurRec) CurRec = &CurMultiClass->Rec; @@ -91,8 +92,8 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, Init *ValName, // in the resolution machinery. if (BitList.empty()) if (VarInit *VI = dyn_cast(V)) - if (VI->getNameInit() == ValName) - return false; + if (VI->getNameInit() == ValName && !AllowSelfAssignment) + return true; // If we are assigning to a subset of the bits in the value... then we must be // assigning to a field of BitsRecTy, which must have a BitsInit @@ -2359,7 +2360,8 @@ Record *TGParser::InstantiateMulticlassDef(MultiClass &MC, Record *DefProto, // though, so that uses in nested multiclass names don't get // confused. if (SetValue(CurRec.get(), Ref.RefRange.Start, "NAME", - std::vector(), DefmPrefix)) { + std::vector(), DefmPrefix, + /*AllowSelfAssignment*/true)) { Error(DefmPrefixRange.Start, "Could not resolve " + CurRec->getNameInitAsString() + ":NAME to '" + DefmPrefix->getAsUnquotedString() + "'"); diff --git a/lib/TableGen/TGParser.h b/lib/TableGen/TGParser.h index 8b41134d4ff..b4407041908 100644 --- a/lib/TableGen/TGParser.h +++ b/lib/TableGen/TGParser.h @@ -105,10 +105,13 @@ public: private: // Semantic analysis methods. bool AddValue(Record *TheRec, SMLoc Loc, const RecordVal &RV); bool SetValue(Record *TheRec, SMLoc Loc, Init *ValName, - const std::vector &BitList, Init *V); + const std::vector &BitList, Init *V, + bool AllowSelfAssignment = false); bool SetValue(Record *TheRec, SMLoc Loc, const std::string &ValName, - const std::vector &BitList, Init *V) { - return SetValue(TheRec, Loc, StringInit::get(ValName), BitList, V); + const std::vector &BitList, Init *V, + bool AllowSelfAssignment = false) { + return SetValue(TheRec, Loc, StringInit::get(ValName), BitList, V, + AllowSelfAssignment); } bool AddSubClass(Record *Rec, SubClassReference &SubClass); bool AddSubMultiClass(MultiClass *CurMC,