<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/61869>61869</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] [tablegen] Crash when generating interface declarations
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Moxinilian
      </td>
    </tr>
</table>

<pre>
    Hi! I just triggered this issue trying to generate interface definitions or declarations for
```td
include "mlir/IR/OpBase.td"

def Foo {}
def Bar : OpInterface<"Bar"> {
  let methods = [InterfaceMethod<[{}], "void", "baz", (ins Foo:$arg)>];
}
```
which leads to the following crash
```
mlir-tblgen: /home/theodegioanni/llvm-project/llvm/include/llvm/Support/Casting.h:579: decltype(auto) llvm::cast(From *) [To = llvm::StringInit, From = llvm::Init]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /home/theodegioanni/llvm-project/build/install/bin/mlir-tblgen -gen-op-interface-decls -I /home/theodegioanni/sw/ns-mlir/include/NextSilicon/Transform/Mem2Reg -I/home/theodegioanni/llvm-project/build/install/include -I/home/theodegioanni/llvm-project/build/install/include -I/home/theodegioanni/sw/ns-mlir/include -I/home/theodegioanni/sw/ns-mlir/build/include /home/theodegioanni/sw/ns-mlir/include/NextSilicon/Transform/Mem2Reg/Interfaces.td --write-if-changed -o include/NextSilicon/Transform/Mem2Reg/Interfaces.h.inc -d include/NextSilicon/Transform/Mem2Reg/Interfaces.h.inc.d
 #0 0x00007faec65b6217 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/theodegioanni/llvm-project/llvm/lib/Support/Unix/Signals.inc:602:13
 #1 0x00007faec65b4450 llvm::sys::RunSignalHandlers() /home/theodegioanni/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x00007faec65b68bf SignalHandler(int) /home/theodegioanni/llvm-project/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007faec669a140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x13140)
 #4 0x00007faec5ec0ce1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007faec5eaa537 abort ./stdlib/abort.c:81:7
 #6 0x00007faec5eaa40f get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
 #7 0x00007faec5eaa40f _nl_load_domain ./intl/loadmsgcat.c:970:34
 #8 0x00007faec5eb9662 (/lib/x86_64-linux-gnu/libc.so.6+0x31662)
 #9 0x00005618a8464bae llvm::DagInit::getArgName(unsigned int) const /home/theodegioanni/llvm-project/llvm/include/llvm/TableGen/Record.h:1452:5
#10 0x00005618a8464bae llvm::DagInit::getArgNameStr(unsigned int) const /home/theodegioanni/llvm-project/llvm/include/llvm/TableGen/Record.h:1457:24
#11 0x00005618a8464bae mlir::tblgen::InterfaceMethod::InterfaceMethod(llvm::Record const*) /home/theodegioanni/llvm-project/mlir/lib/TableGen/Interfaces.cpp:28:16
#12 0x00005618a8464ea6 llvm::SmallVectorBase<unsigned int>::size() const /home/theodegioanni/llvm-project/llvm/include/llvm/ADT/SmallVector.h:91:32
#13 0x00005618a8464ea6 mlir::tblgen::InterfaceMethod& llvm::SmallVectorImpl<mlir::tblgen::InterfaceMethod>::emplace_back<llvm::Record*>(llvm::Record*&&) /home/theodegioanni/llvm-project/llvm/include/llvm/ADT/SmallVector.h:946:26
#14 0x00005618a8464ea6 mlir::tblgen::Interface::Interface(llvm::Record const*) /home/theodegioanni/llvm-project/mlir/lib/TableGen/Interfaces.cpp:81:13
#15 0x00005618a841e7ad (anonymous namespace)::InterfaceGenerator::emitInterfaceDecls() /home/theodegioanni/llvm-project/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp:607:5
#16 0x00005618a842590d (anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/theodegioanni/llvm-project/mlir/tools/mlir-tblgen/OpInterfacesGen.cpp:680:20
#17 0x00005618a842590d bool std::__invoke_impl<bool, (anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)&, llvm::RecordKeeper const&, llvm::raw_ostream&>(std::__invoke_other, (anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)&, llvm::RecordKeeper const&, llvm::raw_ostream&) /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:60:14
#18 0x00005618a842590d std::enable_if<is_invocable_r_v<bool, (anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)&, llvm::RecordKeeper const&, llvm::raw_ostream&>, bool>::type std::__invoke_r<bool, (anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)&, llvm::RecordKeeper const&, llvm::raw_ostream&>((anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)&, llvm::RecordKeeper const&, llvm::raw_ostream&) /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/invoke.h:113:9
#19 0x00005618a842590d std::_Function_handler<bool (llvm::RecordKeeper const&, llvm::raw_ostream&), (anonymous namespace)::InterfaceGenRegistration<(anonymous namespace)::OpInterfaceGenerator>::InterfaceGenRegistration(llvm::StringRef, llvm::StringRef)::'lambda'(llvm::RecordKeeper const&, llvm::raw_ostream&)>::_M_invoke(std::_Any_data const&, llvm::RecordKeeper const&, llvm::raw_ostream&) /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:291:9
#20 0x00005618a8454f85 std::function<bool (llvm::RecordKeeper const&, llvm::raw_ostream&)>::operator()(llvm::RecordKeeper const&, llvm::raw_ostream&) const /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:0:14
#21 0x00005618a8454f85 mlir::GenInfo::invoke(llvm::RecordKeeper const&, llvm::raw_ostream&) const /home/theodegioanni/llvm-project/mlir/include/mlir/TableGen/GenInfo.h:39:12
#22 0x00005618a8454f85 mlirTableGenMain(llvm::raw_ostream&, llvm::RecordKeeper&) /home/theodegioanni/llvm-project/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp:137:21
#23 0x00007faec663cf71 std::function<bool (llvm::raw_ostream&, llvm::RecordKeeper&)>::operator()(llvm::raw_ostream&, llvm::RecordKeeper&) const /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/bits/std_function.h:0:14
#24 0x00007faec663cf71 llvm::TableGenMain(char const*, std::function<bool (llvm::raw_ostream&, llvm::RecordKeeper&)>) /home/theodegioanni/llvm-project/llvm/lib/TableGen/Main.cpp:139:14
#25 0x00005618a84547fb mlir::MlirTblgenMain(int, char**) /home/theodegioanni/llvm-project/mlir/lib/Tools/mlir-tblgen/MlirTblgenMain.cpp:157:10
#26 0x00007faec5eabd0a __libc_start_main ./csu/../csu/libc-start.c:308:16
#27 0x00005618a83975ca _start (/home/theodegioanni/llvm-project/build/install/bin/mlir-tblgen+0x545ca)
Aborted
ninja: build stopped: subcommand failed.
```

CMakeLists to reproduce:
```
set(LLVM_TARGET_DEFINITIONS Interfaces.td)
mlir_tablegen(Interfaces.h.inc -gen-op-interface-decls)
mlir_tablegen(Interfaces.cpp.inc -gen-op-interface-defs)
add_public_tablegen_target(MyInterfaceIncGen)
```
then build with `ninja`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWt1vo7gW_2vcFysR2EDgoQ9p2sxGdzq7anv3FRljiGfARrZpm_3rr2xICFlmtmmnu3ulVhWKv47P73z5-INozUvB2CUIr0B4fUFas5Xq8lY-c8ErTsRFJvPd5S8cIB9u4NdWG2gUL0umWA7NlmvItW4ZNGrHRQmNhCUTTBHDIBeGqYJQBnNWcMENl0JDqWDOaEUU6cqFVMC7Bt4SRF73b_KuggtatTmDAKG64gqg9eYOoPWvzRXRbG5ygFA_0n1zVsC1lBAsrsDieqi7IgoCvIS_Nps9QwCvAEJXRFkS-MYNcf0hrJiBNTNbmWsI8DUE4dVh2K2rt4PDq36W8BqgleXwUXLHUFfKyB-HQsyFtowBvAQoIKoEKAH4xg7F_bQHfg8y6IpPW063sGIk11ayZstgIatKPllRU0X0dnKYldbMZFXJhAUO0HorawbQ2myZzFnJJRGCA7Suqsd61ij5lVHTFwFa93IfKu7bppHK9lgRbbgo51uAl-EisdStMs2uYQDFpDUSoAS6YXgJ8JISbQCK10rWEKClbQTh1YN0oh263RvFRbkR3FiRdb1HHVyTFdgSLrVmypoOBJHHNQF49SCtPFH8O6ncDCgCKLJqcNPj1cOua7eNRJVtzYSBsoBcUFk3xPCsYrDD4Du1LWBBeMXyeSfP3z7fLO9voG6zmhtIYNaWUDErEquVrTGNdspdA7Quudm22ZzKepDfiZidw2iA1pCIHO6t3CrXqRRmhH4zilDWT39vCP0G87Zu7CyuyptD9_ebkqUi9QGVPkvfWcur3ClcG1JVtoYLgNZH9gNnJRMz2cwOzjyzCtdwtvnBPPoJoLXQs95tB4P6wp7NPa84lXaeB0WELqSyMrplNbpjJZxt3sD-Xpbv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