<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/114064>114064</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Flang fails to scan a Fortran file with preprocessor macros
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
inaki-amatria
</td>
</tr>
</table>
<pre>
- `flang` version is: `flang version 20.0.0git (https://github.com/llvm/llvm-project.git 6233346895abfb57782511cddc263d439fdd537b)`
- Reduced test case:
```f90
! foo.F
#define BAR(A, B) ((A) * 10000 + (B) * 100)
#define FOO(A, B, C, AA, BB) ( \
(defined(AA) && defined(BB)) && \
(BAR(A, B) C BAR(AA, BB)))
#if FOO(9, 5, >, BAZ, FUX)
#endif
```
- `flang` invocation is: `flang -c foo.F`
- Expected behavior is: The code compiles successfully.
- Actual behavior: Compilation aborts with the following error:
```
error: Could not scan foo.F
foo.F:6:5: error: expected ')'
#if FOO(9, 5, >, BAZ, FUX)
^^^^^^
foo.F:2:30: in a macro defined here
#define FOO(A, B, C, AA, BB) ( \
^^
that expanded to:
( (defined(BAZ) && defined(FUX)) && (((9) * 10000 + ( 5) * 100) > ((BAZ) * 10000 + ( FUX) * 100)))
^
```
- Additional info: The following reduced test case also reproduces the issue:
```f90
#define FOO() (defined(BAR))
#if FOO()
#endif
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVU2PqzYU_TVmcxVkbD4XLEhm2D5p1EpVdwab4NbBkW3y-v59ZQMJE0VTTSNE8Mfx9bk-55pZK8-TEDXKjih7i9jsRm1qObG_5YFdmDOSRZ3mv-oDoBwPik1nlGO4CWOlnkBaRJv7yL2b4BjH-CwdIFKOzl39NERaRNqzdOPcxb2-INIqddv-Dlej_xK9iz0qJ5TSNC-rjHVDlxVFSbIk6TnvSU55SquB84wWHSIVyjHCbwg3B_gQfO4FByesg55Z4YOGMT8pPEO1zkYkgUHruN2alItBTgKOzQciZYPICY6IVJ7A0vafDSQYYwyIHP3Acdfrt_K0VPvjx26pE5z8q1na29qAstOCA99ckNzD1pA5Ijk8ugNwN_IZ_rz500bnEXR9lq1uG5bDutnKz8v8C9H3gGn-9H_t73_sCYqJy-Eptdsp7GUip5vumXuhlEO_pv8BfP_nKnonOHRiZDepzYr5bRTQa-5fl6tUwoKd-15YO8xK_Yo3eNO7mak72CNPAbDEZ502zsJP6UZwo4BBK6V_yukMwpgw_SWfbRBOelYcJu3A9mzaa2f5pE2OaJP5qXeM2BghUoS8F4-z-l7OAWXvz8-n4ATRhmIfVE7A4MJ6ozfZwCiM2EX-n_L88rffkxuZ89zZxL0b9T23sCy5l3ng-kLnK_md0IMPl3S9sKJP4N6LPpcr5h7iGbLE2Bt4541ncq_F3nAuvbyYAjkNepPrQ1zmuSYBU1aDEVej_YgNYpTWzl9Xq8-Htp7OPo0fXxv7v9wb8ZryilYsEnVSUEwSQrMyGuuBsaTrioIkHItS0KJkuKhoR7OiIF2GI1kTTNIEkypJKaFl3OdFklUkwzhLyi6tUIrFhUkV-zIfa3OOAt06SVKcp5FinVA2XECELJWDEH8XmTrcC918tijFSlpnH0s46VS4tRZE9gZtqCsDk8qC04tLGbTaOOP9KpVYzH8Nuff1Q5vFJzaajaq_d00h0gYWFpF2JXKryb8BAAD__-rb900">