<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/91050>91050</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[TableGen] llvm-tblgen crash error when using class as subroutine with recursion
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kychendev
</td>
</tr>
</table>
<pre>
When using class as subroutine with recursion, llvm-tblgen crashed in resolving references, as demonstrated by the following example.
```cpp
class A <int a, int b, int s> {
int n = !add(a, s, -1);
list<string> ret =
!if(!le(n, b),
!listconcat([a#"-"#n],
A<!add(a, 1), b, s>.ret),
[]);
}
def RecordA : A<0, 3, 2>;
```
Link to failed case: https://godbolt.org/z/5rTGo7TdK
The issue can be worked around by revising the class definition as follows. The only difference is substituting the use of variable "n" at line 4 with the expression "!add(a, s, -1)".
```cpp
class A <int a, int b, int s> {
int n = !add(a, s, -1);
list<string> ret =
!if(!le(!add(a, s, -1), b),
!listconcat([a#"-"#n],
A<!add(a, 1), b, s>.ret),
[]);
}
def RecordA : A<0, 3, 2>;
```
Link to working case: https://godbolt.org/z/zhYGo6Ea3
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMlc1u4zYQx59mdBnEkIaSLR10cOw4h_ZUBCh6pMSRxYYmDZKyN_v0BSWvk027QPe2hCHrY_Sfr5-GMgR9tMwtVI9Q7TM5xdH59vWtH9kqvmSdU2_tnyNbnIK2R-yNDAFlwDB13k1RW8arjiN67icftLNAOzTmcnqInTmyxd7LMLJCbdFzcOaSZDwP7Nn2HJK5DKj45GyIXkZW2L1hHBkHZ4y7JnP-Ik9nwyvI95Bvb8d1vvz683m5s8S2RRA7bSPKJJ1Oum8nAcQTwuZxMcf5nkUQewQqpFJA9fzSHNRDAdSAuBsbHSKIXYhe22MS8hzTu9-epwVU6AGoBioMA9VzMbqkQ7ubXXqkQ-yd7WVMptWjBBJA9ABEQMJCtX83_8-1BbH7PuJi8bGkmtJceY7f-b2vpdNLboi3Wm72H0ureMA_uHdepWJuZ395UhbpQCCe7nW5d2G5_F3bV4wOB6kNK-xl4CQwxngOILZAB6DD0anOmbhy_gh0-Ap0qPzLs9u8qN8-RvEyMuoQJsZeWuwYr86_skLp3WRnSDxf9ExlomXpvuJBWx21s4mqhaCwwqTlrHlDpYcbeahniEPUMWG8iEyB0Q14kV7LzjACkQUilBFNQr1cYE-m_OXsOSTicW7cDwAi-pWp_Qzsj9P4zPE7Tz8H9K_PbsJsHnX_E96v41_Pbv0kxccwMtUK1YhGZtwWm6Ksc1GTyMZ2Q7IfOjlUQ7XedL2om6LLm66s67Kum2qd6ZZyKvMqL_M1iVKs-rwU1bCuqGbVFLWAMueT1GaVpmyKI5u_krYp8irPjOzYhHmeE1m-Lp9Q6kS1z3w7T-ZuOgYo89S28K4SdTTzRvCS0H_m1Ld_T3Jk753H689sCdnkTfupjDqOU7fq3QnokJzc_h7O3v3NfQQ6zIEHoMOc2D8BAAD__9Gc5BE">