[PATCH] D59294: [TableGen] Give meaningful msg for def use in multiclass

Javed Absar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 04:56:28 PDT 2019


javed.absar created this revision.
javed.absar added reviewers: nhaehnle, simon_tatham, hfinkel, eli.friedman.

When one mistakenly specifies 'def' instead of using 'defm',  the error message presently is quite misleading: 'Couldn't find class..'

This patch makes it more clear in  case the multiclass of same name does actually exist.


https://reviews.llvm.org/D59294

Files:
  lib/TableGen/TGParser.cpp
  test/TableGen/MultiClass-def-fail.td


Index: test/TableGen/MultiClass-def-fail.td
===================================================================
--- /dev/null
+++ test/TableGen/MultiClass-def-fail.td
@@ -0,0 +1,10 @@
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
+// XFAIL: vg_leak
+
+// This test checks that using def instead of defm gives a meaningful error
+multiclass M2 {
+  def X;
+}
+
+// CHECK: error: Couldn't find class 'M2'. Use 'defm' if you meant to use multiclass 'M2'
+def rec1 : M2;
Index: lib/TableGen/TGParser.cpp
===================================================================
--- lib/TableGen/TGParser.cpp
+++ lib/TableGen/TGParser.cpp
@@ -536,8 +536,14 @@
   }
 
   Record *Result = Records.getClass(Lex.getCurStrVal());
-  if (!Result)
-    TokError("Couldn't find class '" + Lex.getCurStrVal() + "'");
+  if (!Result) {
+    std::string Msg("Couldn't find class '" + Lex.getCurStrVal() + "'");
+    if (MultiClasses[Lex.getCurStrVal()].get())
+      TokError(Msg + ". Use 'defm' if you meant to use multiclass '" +
+               Lex.getCurStrVal() + "'");
+    else
+      TokError(Msg);
+  }
 
   Lex.Lex();
   return Result;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59294.190399.patch
Type: text/x-patch
Size: 1126 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190313/46e77daa/attachment.bin>


More information about the llvm-commits mailing list