Skip to content

Commit eb69870

Browse files
committed
[TableGen] Improve error report of unspecified arguments
Wrong error message is fixed and a note of argument is printed. Tests are added in `llvm/test/TableGen/template-args.td`. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D156966
1 parent 0da19a2 commit eb69870

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

llvm/lib/TableGen/TGParser.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,11 @@ bool TGParser::resolveArguments(Record *Rec, ArrayRef<ArgumentInit *> ArgValues,
593593
for (auto *UnsolvedArgName : UnsolvedArgNames) {
594594
Init *Default = Rec->getValue(UnsolvedArgName)->getValue();
595595
if (!Default->isComplete()) {
596-
return Error(Loc, "value not specified for template argument (" +
597-
UnsolvedArgName->getAsUnquotedString() +
598-
") of multiclass '" + Rec->getNameInitAsString() +
599-
"'");
596+
std::string Name = UnsolvedArgName->getAsUnquotedString();
597+
Error(Loc, "value not specified for template argument '" + Name + "'");
598+
PrintNote(Rec->getFieldLoc(Name),
599+
"declared in '" + Rec->getNameInitAsString() + "'");
600+
return true;
600601
}
601602
ArgValueHandler(UnsolvedArgName, Default);
602603
}

llvm/test/TableGen/template-args.td

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
// RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
77
// RUN: not llvm-tblgen -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
88
// RUN: not llvm-tblgen -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s
9+
// RUN: not llvm-tblgen -DERROR8 %s 2>&1 | FileCheck --check-prefix=ERROR8 %s
10+
// RUN: not llvm-tblgen -DERROR9 %s 2>&1 | FileCheck --check-prefix=ERROR9 %s
11+
// RUN: not llvm-tblgen -DERROR10 %s 2>&1 | FileCheck --check-prefix=ERROR10 %s
912

10-
// This file tests that template arguments are type-checked and cast
11-
// if necessary.
13+
// This file tests that all required arguments are specified and template
14+
// arguments are type-checked and cast if necessary.
1215

1316
// Class template arguments.
1417

@@ -151,3 +154,23 @@ defm Good : TwoArgs<1, "one">;
151154
defm MissingComma : TwoArgs<2 "two">;
152155
// ERROR7: [[#@LINE-1]]:31: error: Expected comma before next argument
153156
#endif
157+
158+
#ifdef ERROR8
159+
def error8: Class1;
160+
// ERROR8: value not specified for template argument 'Class1:nm'
161+
// ERROR8: 18:21: note: declared in 'Class1'
162+
#endif
163+
164+
#ifdef ERROR9
165+
defm error9: MC1;
166+
// ERROR9: value not specified for template argument 'MC1::nm'
167+
// ERROR9: 99:23: note: declared in 'MC1'
168+
#endif
169+
170+
#ifdef ERROR10
171+
def error10 {
172+
int value = Class2<>.Code;
173+
}
174+
// ERROR10: value not specified for template argument 'Class2:cd'
175+
// ERROR10: 37:22: note: declared in 'Class2'
176+
#endif

0 commit comments

Comments
 (0)