<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/102447>102447</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
TableGen: References are not resolved at the top level
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Akshat-Oke
</td>
</tr>
</table>
<pre>
`llvm-tblgen` crashes if "lookup" operators are used on the top level when the looked-up record does not exist.
I define "lookup" operators as `!exists<type>(str)` and `!cast<type>(expr)`.
`td` file to reproduce this issue: (run `llvm-tblgen file.td`)
```td
class Test{}
dump !cast<Test>("non-existent record");
```
Assertion failure:
```
llvm-tblgen: ~/llvm-project/llvm/lib/TableGen/Error.cpp:176: void llvm::dumpMessage(llvm::SMLoc, llvm::Init*): Assertion `MessageInit && "no debug message to print"' failed.
```
This is happening because references to records are only resolved once the Record parsing is finished. But at the top level there is no Record and so the resolution never happens.
I don't see a fix without adding a new mechanism to resolve top level references. The existing `resolveReferences()` method only works on a `Record`, which does not exist here. I can think of two approaches: 1. Create a dummy record for the top level and this single statement (`RecordVal`), or, 2. Create new methods to handle top level resolutions without the enclosing record.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8VM1u6zYTfRp6M4ggUY5sL7RQkusPAb6LArdB9xQ5MtlQpMCh7GTTZy9IOfEP2gKGDFEznHPOzBlBZA4OsWWPT-zxZSXmqH1ou3fSIj789o6r3qvPljWltcfxIfb2gI41JcggSCOBGYBxbr1_nyfGOfgJg4g-EIiAMBMq8A6iRoh-AotHtHDSuBylNFQP8wQBpQ8KlEcC5yPgh6FYsPKFld3yfAWFg3H4r-UIWFMyXuVUYvVz_JyQ1T8Y31IMjO8SbOHUOUwKijdB-DGdo27qsqaMKqUOxiYSEHAKXs0SIWpDYIhmZHUHjG_D7OBWqpxV5AvS3V83Lr-olgNpBRG8IUW2eWKbl-VUzeMEF6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