TableGen - cryptic error messages (~feature request)

Hello.
     I started implementing a back end in LLVM (and I'm writing some hints I consider useful at https://sites.google.com/site/alexsusu/home/backend-llvm ).
     Unfortunately, I hit quite a few times very cryptic error messages when compiling with TableGen, which required a few good hours of debugging the TableGen program.

     The most cryptic error message was when compiling with TableGen, with the option -gen-asm-matcher . Here I got the following error message:
llvm-tblgen: ~/llvm/lib/TableGen/StringMatcher.cpp:52: bool llvm::StringMatcher::EmitStringMatcherForChar(const std::vector<const std::pair<std::basic_string<char>, std::basic_string<char> >*>&, unsigned int, unsigned int) const: Assertion `Matches.size() == 1 && "Had duplicate keys to match on"' failed.
[...]
Stack dump:
0. Program arguments: ~/llvm/build3/bin/llvm-tblgen -gen-asm-matcher -I ~/llvm/include Connex.td
./run_tblgen.sh: line 13: 27011 Aborted (core dumped) ~/llvm/build3/bin/llvm-tblgen -gen-asm-matcher -I ~/llvm/include Connex.td > ConnexGenAsmMatcher.inc

     It took me quite a few hours to find the source of the error, namely the fact I had defined two registers with the SAME ASM name (string) - so the disassembly (ASM matcher) info had conflicts. I actually sped up my debugging by editing the file ~/llvm/lib/TableGen/StringMatcher.cpp and adding in StringMatcher::
EmitStringMatcherForChar() some printing that explained more clearly why the error happens.

     Therefore I have this IMPORTANT question: would you feel it is useful to make TableGen give more detailed error messages? I personally recommend this.

   Thank you,
     Alex

  Hello.
    I started implementing a back end in LLVM (and I'm writing some hints
I consider useful at
https://sites.google.com/site/alexsusu/home/backend-llvm ).
    Unfortunately, I hit quite a few times very cryptic error messages
when compiling with TableGen, which required a few good hours of debugging
the TableGen program.

    The most cryptic error message was when compiling with TableGen, with
the option -gen-asm-matcher . Here I got the following error message:
llvm-tblgen: ~/llvm/lib/TableGen/StringMatcher.cpp:52: bool
llvm::StringMatcher::EmitStringMatcherForChar(const std::vector<const
std::pair<std::basic_string<char>, std::basic_string<char> >*>&, unsigned
int, unsigned int) const: Assertion `Matches.size() == 1 && "Had duplicate
keys to match on"' failed.
[...]
Stack dump:
0. Program arguments: ~/llvm/build3/bin/llvm-tblgen -gen-asm-matcher
-I ~/llvm/include Connex.td
./run_tblgen.sh: line 13: 27011 Aborted (core dumped)
~/llvm/build3/bin/llvm-tblgen -gen-asm-matcher -I ~/llvm/include Connex.td
> ConnexGenAsmMatcher.inc

    It took me quite a few hours to find the source of the error, namely
the fact I had defined two registers with the SAME ASM name (string) - so
the disassembly (ASM matcher) info had conflicts. I actually sped up my
debugging by editing the file ~/llvm/lib/TableGen/StringMatcher.cpp and
adding in StringMatcher::
EmitStringMatcherForChar() some printing that explained more clearly why
the error happens.

    Therefore I have this IMPORTANT question: would you feel it is useful
to make TableGen give more detailed error messages? I personally recommend
this.

Seems reasonable to add some extra text to the assertion (and possibly use
better error handling - not sure if tblgen aspires to be assertion-free on
unbounded table inputs, but it probably should be... ). Perhaps you could
send a patch to llvm-commits to discuss the specifics there?

- Dave

It definitely aspires to, yeah. An assert() for a user error is not a great experience. Patches making that aspiration a bit closer to the reality are very welcome.

-jim

Hello.
     Sorry for the late reply.
     I'm still writing on llvm-dev (not on llvm-commit as suggested - hope it's not against the rules).

     The error described below (<<Assertion `Matches.size() == 1 && "Had duplicate keys to match on"' failed.>>) is given when running the command:
       $LLVM_BUILD_PATH/bin/llvm-tblgen -gen-asm-matcher -I $LLVM_SRC_PATH/llvm/include Connex.td >ConnexGenAsmMatcher.inc

     This error message lacks any valuable info to help debugging the problem. To help me find the problem I edited the file $LLVM_SRC_PATH/llvm/lib/TableGen/StringMatcher.cpp and patched it with:
         --- Orig/StringMatcher.cpp 2015-11-17 10:59:07.000000000 +0200
         +++ StringMatcher.cpp 2016-03-05 19:00:29.760320952 +0200
         @@ -49,8 +49,22 @@
            // If we have verified that the entire string matches, we're done: output the
            // matching code.
            if (CharNo == Matches[0]->first.size()) {

TableGen_seg_faults_due_to_same_ASM_names_in_FPR_and_AFPR64_registers.zip (8.56 KB)