llvm / llvm/llvm-project

[Flang] Spurious error for generic resolution, cannot disambiguate dummy between external subroutine and function

Open
#191,407 1 comment 0 reactions 0 assignees View on GitHub
flang
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Flang incorrectly rejects valid Fortran code when resolving a generic procedure call where the actual argument is an external subroutine and one of the specific procedures has a function as the corresponding dummy argument.

Expected Behavior: External subroutine names are global identifiers. The compiler should be able to distinguish between a subroutine and a function, and correctly resolve the generic procedure call to the specific procedure that expects a subroutine dummy argument.

Actual Behavior: Flang produces the following error:
```
error: The actual arguments to the generic procedure 'gen' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface
call gen(s, a)
```

Reproducer:

```fortran
module m
interface gen
module procedure with_sub, with_fun
end interface gen
contains
subroutine with_sub(sub,n)
external sub
call sub(n)
end subroutine with_sub
subroutine with_fun(af,n)
interface
function af(n)
real af(n)
end function
end interface
print *,'[',af(n),']'
end subroutine
end module

program test
use m
external s
integer a

a = 13
call gen(s, a)
end program

subroutine s(n)
if (n==13) print '("ok")'
end subroutine
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling and running the provided Fortran reproducer with Flang, then trace generic resolution for the `gen(s, a)` call and its `with_sub` and `with_fun` specifics. Done means the valid program is accepted and resolves to the specific procedure expecting the external subroutine, without the ambiguity error.

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
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.