]> granicus.if.org Git - llvm/commitdiff
[TableGen] Give meaningful msg for def use in multiclass
authorJaved Absar <javed.absar@arm.com>
Tue, 26 Mar 2019 10:49:09 +0000 (10:49 +0000)
committerJaved Absar <javed.absar@arm.com>
Tue, 26 Mar 2019 10:49:09 +0000 (10:49 +0000)
When one mistakenly specifies 'def' instead of using 'defm',
the error message is quite misleading: 'Couldn't find class..'
Instead, it should recommend using defm if the multiclass of
same name exists.

Reviewed By: hfinkel

Differential Revision: https://reviews.llvm.org/D59294

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356985 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TableGen/TGParser.cpp
test/TableGen/MultiClass-def-fail.td [new file with mode: 0644]

index 90c9b390e103f281c8416326cd82feb1e69a6a0f..3fc2e53f208a8f31527b6cea3685b48bc6a24a43 100644 (file)
@@ -536,8 +536,14 @@ Record *TGParser::ParseClassID() {
   }
 
   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;
diff --git a/test/TableGen/MultiClass-def-fail.td b/test/TableGen/MultiClass-def-fail.td
new file mode 100644 (file)
index 0000000..ed37e5c
--- /dev/null
@@ -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;