[llvm-branch-commits] [llvm] d6417ad - [TableGen] Improve error report of unspecified arguments

Tobias Hieta via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Aug 3 22:55:40 PDT 2023


Author: wangpc
Date: 2023-08-04T07:51:16+02:00
New Revision: d6417ad67d9425f7cd8eb2a606f66d7da2aecd4d

URL: https://github.com/llvm/llvm-project/commit/d6417ad67d9425f7cd8eb2a606f66d7da2aecd4d
DIFF: https://github.com/llvm/llvm-project/commit/d6417ad67d9425f7cd8eb2a606f66d7da2aecd4d.diff

LOG: [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

(cherry picked from commit eb6987027e0504adcdc319f080a9ea48aab2a72a)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 759e15f4c443ba..a371bd21f0262c 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -593,10 +593,11 @@ bool TGParser::resolveArguments(Record *Rec, ArrayRef<ArgumentInit *> ArgValues,
   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);
   }

diff  --git a/llvm/test/TableGen/template-args.td b/llvm/test/TableGen/template-args.td
index 172d8289c9fd1e..f3eb02dd823ef5 100644
--- a/llvm/test/TableGen/template-args.td
+++ b/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 Good : TwoArgs<1, "one">;
 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


        


More information about the llvm-branch-commits mailing list