[TableGen] Give meaningful msg for def use in multiclass

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 

llvm-svn: 356985
This commit is contained in:
Javed Absar 2019-03-26 10:49:09 +00:00
parent 5c90238479
commit 33888ff66b
2 changed files with 18 additions and 2 deletions

View 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;

View File

@ -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;