<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/65100>65100</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[TableGen] Incorrect preprocessor handling of nested `#ifndef` directives
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
mshockwave
</td>
</tr>
</table>
<pre>
Given the following three TableGen files.
test_rec.td:
```
#ifndef TEST_REC
#define TEST_REC
def foo;
#ifndef HAHA
def haha;
#endif
#endif
```
test_rec2.td:
```
#ifndef TEST_REC2
#define TEST_REC2
include "test_rec.td"
def bar;
#endif
```
test_rec_main.td:
```
#ifndef TEST_REC_MAIN
#define TEST_REC_MAIN
include "test_rec.td"
include "test_rec2.td"
def zoo;
#endif
```
When running with the following command (which effectively only parses the content):
```shell
llvm-tblgen test_rec_main.td
```
It wrongfully gave the following error, despite the facts that the above snippets are legit:
```
error: prepIsDirective() and lexPreprocessor() returned different token kinds
```
My preliminary investigation suggested that this is caused by preprocessor's normalization on the `#ifndef` / `#ifdef` tokens.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVMGO2zYQ_RrqMoghk-baPuiwieNkDymKdoEeF5Q4kqZLkQKHsut8fSHZm3UUb5sAhgy94Qzfm3kaw0yNRyyEfi_0LjNDakMsOm5D9Xw0B8zKYE_FJzqgh9Qi1MG5cCTfQGojIjya0uEn9FCTQ16IfCfy-_MzIaeniNUiWaEumLjLL7_zq1RUe4s1PH788_Hpj48fvuEWa_I4x6fneL4OQaj31-hrrc_3n69OtqY1r0elQm-pniVeYzOG30mRv6RFviVGXtcmX7nBIggprzsm5VxyaeKPkn-W-VNnyP8S-6cv9w-_vaXgOvgzKm6E5W2VX28N9v9U_tWihzh4PxrzSKmdebUKXWe8BSE3x5aqFrCusUp0QHeC4N0JehMZeUqrgk_ok5DbH5vFLTp3xpw7dO9S6Zrxy5h3-RbVhwTHGHxTD86doDEHnLHEGEMU8gNY5J7SJWyqNPIyaXo1ZTggsKe-x8RgIoLDhtJbcz3XVPfQR-wfeEfxrFvIjZBbGJvi8J_fI_YxVMg8EpgiEdMQPVqwVNcY0SdI4Rk9PJO3_B-z-HIa73LUkTfxBOQPyIkakyh44KFpkBPaF0XEQAyVGRgtlFPqFZM1gw-xM46-nvPDeQuNV74YVtzlIOT-G3aBJrK8yGyh7FZtTYbF8m6rlNYrrbO2sJtSL6Wq9bLerldalyu9VhbLcr3V6_V2k1Ehc6nyjcrzXOVaL6pNXm3MWqmNWsqVMWKVY2fILUYnLEJsMmIesLjTyzzPnCnR8bRXpfR4hCk4Gl7vslhM7imHhsUqd8SJX6skSm5ayC-7VegdPPgqxHF233UIWuOtG70TavDnxs57Y19GztkQXdGm1PPoFrkXct9QaodyUYVOyP3I4PL3ro_hb6ySkPuJNwu5n3T9GwAA__8Zyt-v">