[Flang] Interface declaration in BLOCK constructs incorrectly affects outside scope
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
## Summary
When there is an interface block in a BLOCK construct and the procedure name declared within this interface block conflicts with an external variable's name, Flang fails to distinguish between them, leading to compilation errors.
* 11.1.4 BLOCK construct
> Except for the ASYNCHRONOUS, IMPORT, and VOLATILE statements, specifications in a BLOCK construct declare construct entities whose scope is that of the BLOCK construct (19.4). The appearance of the name of an object that is not a construct entity in an ASYNCHRONOUS or VOLATILE statement in a BLOCK construct specifies that the object has the attribute within the construct even if it does not have the attribute outside the construct.
### Reproducer
* test.f90
```fortran
integer :: fun2
block
interface
function fun()
integer :: fun
end function
end interface
procedure(fun) :: fun2
if(fun2()/=5) print*,102
end block
fun2=5
if(fun2/=5 ) print*,110
print *,'pass'
end
function fun2()
integer :: fun2
fun2=5
end function
```
* commands
```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git 349542f7e122b8fda1d60f0b37c8f92ad65635d6)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/llvm/build/bin
Build config: +assertions
$ flang test.f90 && ./a.out
error: Semantic errors in test.f90
test.f90:12:1: error: Assignment to procedure 'fun2' is not allowed
fun2=5
^^^^
test.f90:13:4: error: Function call must have argument list
if(fun2/=5 ) print*,110
^^^^
```
## Other Compilers
* GFortran
```console
$ gfortran --version
GNU Fortran (GCC) 15.2.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gfortran test.f90 && ./a.out
pass
```
* Intel Fortran
```console
$ ifx --version
ifx (IFX) 2025.3.2 20260112
Copyright (C) 1985-2026 Intel Corporation. All rights reserved.
$ ifx -O0 test.f90 && ./a.out
pass
```
Contributor guide
Research direction
Start by compiling the reported test.f90 reproducer with flang and compare its result with GFortran or Intel Fortran. Trace Flang's handling of name resolution for the interface and BLOCK construct, then add a regression test showing that the external fun2 remains assignable and callable as expected outside the block.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fortran
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100