@@ -776,13 +776,14 @@ ParseSubClassReference(Record *CurRec, bool isDefm) {
776776 return Result;
777777 }
778778
779- if (ParseTemplateArgValueList (Result.TemplateArgs , CurRec, Result.Rec )) {
779+ SmallVector<SMLoc> ArgLocs;
780+ if (ParseTemplateArgValueList (Result.TemplateArgs , ArgLocs, CurRec,
781+ Result.Rec )) {
780782 Result.Rec = nullptr ; // Error parsing value list.
781783 return Result;
782784 }
783785
784- if (CheckTemplateArgValues (Result.TemplateArgs , Result.RefRange .Start ,
785- Result.Rec )) {
786+ if (CheckTemplateArgValues (Result.TemplateArgs , ArgLocs, Result.Rec )) {
786787 Result.Rec = nullptr ; // Error checking value list.
787788 return Result;
788789 }
@@ -812,7 +813,8 @@ ParseSubMultiClassReference(MultiClass *CurMC) {
812813 return Result;
813814 }
814815
815- if (ParseTemplateArgValueList (Result.TemplateArgs , &CurMC->Rec ,
816+ SmallVector<SMLoc> ArgLocs;
817+ if (ParseTemplateArgValueList (Result.TemplateArgs , ArgLocs, &CurMC->Rec ,
816818 &Result.MC ->Rec )) {
817819 Result.MC = nullptr ; // Error parsing value list.
818820 return Result;
@@ -2722,11 +2724,12 @@ const Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType,
27222724 }
27232725
27242726 SmallVector<const ArgumentInit *, 8 > Args;
2727+ SmallVector<SMLoc> ArgLocs;
27252728 Lex.Lex (); // consume the <
2726- if (ParseTemplateArgValueList (Args, CurRec, Class))
2729+ if (ParseTemplateArgValueList (Args, ArgLocs, CurRec, Class))
27272730 return nullptr ; // Error parsing value list.
27282731
2729- if (CheckTemplateArgValues (Args, NameLoc. Start , Class))
2732+ if (CheckTemplateArgValues (Args, ArgLocs , Class))
27302733 return nullptr ; // Error checking template argument values.
27312734
27322735 if (resolveArguments (Class, Args, NameLoc.Start ))
@@ -3201,8 +3204,8 @@ void TGParser::ParseValueList(SmallVectorImpl<const Init *> &Result,
32013204// PostionalArgValueList ::= [Value {',' Value}*]
32023205// NamedArgValueList ::= [NameValue '=' Value {',' NameValue '=' Value}*]
32033206bool TGParser::ParseTemplateArgValueList (
3204- SmallVectorImpl<const ArgumentInit *> &Result, Record *CurRec,
3205- const Record *ArgsRec) {
3207+ SmallVectorImpl<const ArgumentInit *> &Result,
3208+ SmallVectorImpl<SMLoc> &ArgLocs, Record *CurRec, const Record *ArgsRec) {
32063209 assert (Result.empty () && " Result vector is not empty" );
32073210 ArrayRef<const Init *> TArgs = ArgsRec->getTemplateArgs ();
32083211
@@ -3217,7 +3220,7 @@ bool TGParser::ParseTemplateArgValueList(
32173220 return true ;
32183221 }
32193222
3220- SMLoc ValueLoc = Lex.getLoc ();
3223+ SMLoc ValueLoc = ArgLocs. emplace_back ( Lex.getLoc () );
32213224 // If we are parsing named argument, we don't need to know the argument name
32223225 // and argument type will be resolved after we know the name.
32233226 const Init *Value = ParseValue (
@@ -4417,11 +4420,15 @@ bool TGParser::ParseFile() {
44174420// If necessary, replace an argument with a cast to the required type.
44184421// The argument count has already been checked.
44194422bool TGParser::CheckTemplateArgValues (
4420- SmallVectorImpl<const ArgumentInit *> &Values, SMLoc Loc ,
4423+ SmallVectorImpl<const ArgumentInit *> &Values, ArrayRef< SMLoc> ValuesLocs ,
44214424 const Record *ArgsRec) {
4425+ assert (Values.size () == ValuesLocs.size () &&
4426+ " expected as many values as locations" );
4427+
44224428 ArrayRef<const Init *> TArgs = ArgsRec->getTemplateArgs ();
44234429
4424- for (const ArgumentInit *&Value : Values) {
4430+ bool HasError = false ;
4431+ for (auto [Value, Loc] : llvm::zip_equal (Values, ValuesLocs)) {
44254432 const Init *ArgName = nullptr ;
44264433 if (Value->isPositional ())
44274434 ArgName = TArgs[Value->getIndex ()];
@@ -4439,16 +4446,16 @@ bool TGParser::CheckTemplateArgValues(
44394446 " result of template arg value cast has wrong type" );
44404447 Value = Value->cloneWithValue (CastValue);
44414448 } else {
4442- PrintFatalError (Loc, " Value specified for template argument ' " +
4443- Arg-> getNameInitAsString () + " ' is of type " +
4444- ArgValue-> getType ()-> getAsString () +
4445- " ; expected type " + ArgType-> getAsString () +
4446- " : " + ArgValue->getAsString ());
4449+ HasError |= Error (
4450+ Loc, " Value specified for template argument ' " +
4451+ Arg-> getNameInitAsString () + " ' is of type " +
4452+ ArgValue-> getType ()-> getAsString () + " ; expected type " +
4453+ ArgType-> getAsString () + " : " + ArgValue->getAsString ());
44474454 }
44484455 }
44494456 }
44504457
4451- return false ;
4458+ return HasError ;
44524459}
44534460
44544461#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0 commit comments