llvm / llvm/llvm-project

[Flang] Compilation error for generic interface blocks that specify private procedure pointers

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

Description

## Summary

Compilation abnormally terminates when a generic interface block specifies a private procedure pointer and another generic interface block exists for the same generic procedure.

* 15.4.3.2 Interface block

> C1509 (R1501) An interface-specification in a generic interface block shall not specify a procedure that was specified previously in any accessible interface with the same generic identifier.

> An interface body in a generic or specific interface block specifies the EXTERNAL attribute and an explicit specific interface for an external procedure, dummy procedure, or procedure pointer.

### Reproducer

* test.f90

```fortran
MODULE mod
PROCEDURE(r_sub),PRIVATE,POINTER :: pprc
INTERFACE gnr
PROCEDURE pprc
END INTERFACE
CONTAINS
SUBROUTINE r_sub(d)
REAL :: d
d = 5.0
END SUBROUTINE

SUBROUTINE set_pprc()
pprc => r_sub
END SUBROUTINE

SUBROUTINE i_sub(d)
INTEGER :: d
d = 2
END SUBROUTINE
END MODULE

PROGRAM main
USE mod
IMPLICIT NONE
REAL :: a
INTERFACE gnr
PROCEDURE i_sub
END INTERFACE

CALL set_pprc()
CALL gnr(a)

IF(a /= 5.0) THEN
PRINT*,"ERROR"
END IF
PRINT*,"pass"
END PROGRAM
```

* 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: loc("/path/to/test.f90":2:39): redefinition of symbol named '_QMmodEpprc'
error: verification of lowering to FIR failed
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Removing the PRIVATE attribute from the pointer `pprc`.
* Moving the interface block in the main program to the module.
* Calling the specific procedure instead of the generic procedure.

## 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

Open the contributing guide

Research direction

Start by compiling the supplied test.f90 reproducer with flang and confirm the duplicate-symbol and FIR verification errors. Trace the lowering path for the private procedure pointer used in the module generic interface, then add or run a regression test showing that the program compiles and prints "pass" without the redefinition 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
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.