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

    <tr>
        <th>Summary</th>
        <td>
            [flang] Preprocessor substitution in bind(C) names
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

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

<pre>
    ### Issue:
flang does not substitute preprocessor tokens in BIND(C) names. This reproducer contains continuation lines in the same spirit as #78797. This appears to be a workaround in order to get token pasting inside character/string literals. Open to discussing whether this should be intended behavior, but it is used extensively in the a customer codebase and we'd need to find an alternative solution.
### Reproducer:
#### main.F90
```Fortran
program main
  implicit none
#define TEMP_LETTER b
#define VAL c
  integer, parameter :: a_&
    &b_c = 1
  write(*,*) a_b_c
contains
subroutine test_&
&TEMP_LETTER&
&_wrapper_&
&VAL&
& (input) &
  bind(C, name="test_&
    &TEMP_LETTER&
    &_&
    &VAL&
    &_f")
 use iso_c_binding
  integer :: input
end subroutine test_&
&TEMP_LETTER&
&_wrapper_&
&VAL
end program main
```
#### preprocessor output
`flang-new -E main.F90`
```Fortran
      program main
      implicit none


      integer, parameter :: a_b_c = 1

      write(*,*) a_b_c
      contains
      subroutine test_b_wrapper_c(input) bind(C, name="test_TEMP_LETTER_&
 &VAL_f")








      use iso_c_binding
 integer :: input
      end subroutine test_b_wrapper_c



 end program main
```
#### gfortran behavior
`gfortran -E main.F90`
```
program main
  implicit none


  integer, parameter :: a_&
    &b_c = 1
  write(*,*) a_b_c
contains
subroutine test_&
&b&
&_wrapper_&
&c&
& (input) &
  bind(C, name="test_&
    &b&
    &_&
    &c&
 &_f")
  use iso_c_binding
  integer :: input
end subroutine test_&
&b&
&_wrapper_&
&c
end program main
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMll-PozgMwD9N-mJNRU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