[PATCH] D156966: [TableGen] Improve error report of unspecified arguments

Wang Pengcheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 00:00:28 PDT 2023


wangpc created this revision.
wangpc added reviewers: DavidSpickett, reames, craig.topper, michaelmaitland.
Herald added a subscriber: hiraditya.
Herald added a project: All.
wangpc requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Wrong error message is fixed and a note of argument is printed.

Tests are added in `llvm/test/TableGen/template-args.td`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156966

Files:
  llvm/lib/TableGen/TGParser.cpp
  llvm/test/TableGen/template-args.td


Index: llvm/test/TableGen/template-args.td
===================================================================
--- llvm/test/TableGen/template-args.td
+++ llvm/test/TableGen/template-args.td
@@ -6,9 +6,12 @@
 // RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
 // RUN: not llvm-tblgen -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
 // RUN: not llvm-tblgen -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s
+// RUN: not llvm-tblgen -DERROR8 %s 2>&1 | FileCheck --check-prefix=ERROR8 %s
+// RUN: not llvm-tblgen -DERROR9 %s 2>&1 | FileCheck --check-prefix=ERROR9 %s
+// RUN: not llvm-tblgen -DERROR10 %s 2>&1 | FileCheck --check-prefix=ERROR10 %s
 
-// This file tests that template arguments are type-checked and cast
-// if necessary.
+// This file tests that all required arguments are specified and template
+// arguments are type-checked and cast if necessary.
 
 // Class template arguments.
 
@@ -151,3 +154,23 @@
 defm MissingComma : TwoArgs<2 "two">;
 // ERROR7: [[#@LINE-1]]:31: error: Expected comma before next argument
 #endif
+
+#ifdef ERROR8
+def error8: Class1;
+// ERROR8: value not specified for template argument (Class1:nm)
+// ERROR8: 18:21: note: declared in Class1
+#endif
+
+#ifdef ERROR9
+defm error9: MC1;
+// ERROR9: value not specified for template argument (MC1::nm)
+// ERROR9: 99:23: note: declared in MC1
+#endif
+
+#ifdef ERROR10
+def error10 {
+  int value = Class2<>.Code;
+}
+// ERROR10: value not specified for template argument (Class2:cd)
+// ERROR10: 37:22: note: declared in Class2
+#endif
Index: llvm/lib/TableGen/TGParser.cpp
===================================================================
--- llvm/lib/TableGen/TGParser.cpp
+++ llvm/lib/TableGen/TGParser.cpp
@@ -593,10 +593,11 @@
   for (auto *UnsolvedArgName : UnsolvedArgNames) {
     Init *Default = Rec->getValue(UnsolvedArgName)->getValue();
     if (!Default->isComplete()) {
-      return Error(Loc, "value not specified for template argument (" +
-                            UnsolvedArgName->getAsUnquotedString() +
-                            ") of multiclass '" + Rec->getNameInitAsString() +
-                            "'");
+      std::string Name = UnsolvedArgName->getAsUnquotedString();
+      Error(Loc, "value not specified for template argument (" + Name + ")");
+      PrintNote(Rec->getFieldLoc(Name),
+                "declared in '" + Rec->getNameInitAsString() + "'");
+      return true;
     }
     ArgValueHandler(UnsolvedArgName, Default);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156966.546719.patch
Type: text/x-patch
Size: 2512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230803/2843644e/attachment.bin>


More information about the llvm-commits mailing list