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

    <tr>
        <th>Summary</th>
        <td>
            [flang][OpenMP] 'declare target' appears to require an explicit interface for subroutine calls.
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          scamp-nvidia
      </td>
    </tr>
</table>

<pre>
    Consider the following snippet of code: 

```
program prog_generic
integer :: val_n = 8
!$omp declare target(worker)
   !$omp target
      call worker(val_n)
   !$omp end target
end program
subroutine worker(val_n)
!$omp declare target
integer :: val_n
     print*,"hello from worker"
end subroutine
```
Attempting to compile this snippet with latest flang results in an unexpected failure in comparison to gfortran (14.1) or nvhpc (25.7):

```
scamp:$ gfortran test.F90 -fopenmp -o test
scamp:$ nvfortran test.F90 -fopenmp -o test
scamp:$ flang test.F90 -fopenmp -o test
error: Semantic errors in test.F90
./test.F90:5:12: error: Cannot call function 'worker' like a subroutine
        call worker(val_n)
 ^^^^^^
./test.F90:3:22: Implicit declaration of 'worker'
 !$omp declare target(worker)
                       ^^^^^^
```
Note all flang openmp-versions I tried resulted in the same behavior. The only way I can actually get the code to compile and run is to add an explicit interface: 

```
program prog_generic
  implicit none
  integer :: val_n = 8
 interface
     subroutine worker(val_n)
       integer :: val_n
     end subroutine worker
  end interface
!$omp declare target(worker)
  !$omp target
    call worker(val_n)
  !$omp end target
end program prog_generic
subroutine worker(val_n)
  !$omp declare target
  integer :: val_n
  print*, "hello from worker"
end subroutine worker
```

I suspect that Flang requiring an additional interface that other compilers do not require, with no warning or hints would be a major porting issue for users. Unless otherwise suggested, I believe the original code should compile with Flang in the same way it does with gfortran and nvhpc. 
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVk2PozgQ_TXOpRQEJjTkwIGZ3kh92A9pd88jBxfgG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