diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp index 90c9b390e103..3fc2e53f208a 100644 --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -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/llvm/test/TableGen/MultiClass-def-fail.td b/llvm/test/TableGen/MultiClass-def-fail.td new file mode 100644 index 000000000000..ed37e5cd71cb --- /dev/null +++ b/llvm/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;