<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56605>56605</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] (Semantic check?) Incorrect error message when using the same name in interfaces and external statements
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
UsmanNadeem
</td>
</tr>
</table>
<pre>
The standard states:
```
Only one appearance of a name in all of the EXTERNAL statements in a scoping unit is permitted. A name that
appears in an EXTERNAL statement must not also appear as a specific procedure name in an interface block in
the scoping unit.
```
I was testing a piece of code (from NumPy) that works fine on Gfortran but did not compile with Flang. I have put a small test case here.
Consider the following two functions where we violate this constraint:
```
function foo1()
external bar1
interface
function bar1(value) result (r)
integer, intent(in) :: value
end function bar1
end interface
end function foo1
function foo2(bar2)
external bar2
interface
function bar2(value) result (r)
integer, intent(in) :: value
end function bar2
end interface
end function foo2
```
On flang the errors dont make much sense:
```
error: Semantic errors in /app/example.f90
/app/example.f90:5:18: error: 'bar1' was previously called as a subroutine
function bar1(value) result (r)
^^^^
/app/example.f90:2:14: Previous call of 'bar1'
external bar1
^^^^
/app/example.f90:15:18: error: 'bar2' is already declared in this scoping unit
function bar2(value) result (r)
^^^^
/app/example.f90:11:15: Previous declaration of 'bar2'
function foo2(bar2)
^^^^
Compiler returned: 1
```
Surprisingly, Gfortran is successfully able to compile the second file but we get an appropriate error `Error: Duplicate EXTERNAL attribute specified` for the first file: https://godbolt.org/z/oKq14a9Kz
Would it be possible to change the error message to something appropriate? Doing so will make debugging much easier.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy9Vktz4zYM_jXyBVOPTMevgw9uHp3MdrI73e20V4qCbDYUqfIRb_bXF6Bsy0mTdJJDNbIsCiTw4SMerFz9uP62QwhR2lr6ml8ihmK6KcqrotwU8_Jw5-Fnax7BWQTZdSi9tArBN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