Issue 204301
Summary [Flang] Variable declarations in an interface body are not ignored
Labels flang:frontend
Assignees
Reporter yus3710-fj
    ## Summary

The Fortran 2023 standard specifies that variable declarations within an interface body should be ignored. However, Flang appears to violate this requirement.

* 15.4.3.2 Interface block
> An interface body specifies all of the characteristics of the explicit specific interface or abstract interface. The specification part of an interface body may specify attributes or define values for data entities that do not determine characteristics of the procedure. Such specifications have no effect.

* 15.3.1 Characteristics of procedures
> The characteristics of a procedure are the classification of the procedure as a function or subroutine, whether it is pure, whether it is simple, whether it is elemental, whether it has the BIND attribute, the characteristics of its dummy arguments, and the characteristics of its function result if it is a function.

### Reproducer

* test.f90

```fortran
module m
  interface
    module subroutine sub
      integer:: y=1
    end subroutine
  end interface
contains
  module procedure sub
    integer:: y=10
    if (y/=10) print *,102
  end procedure
end

use m
call sub
print *,'pass'
end
```

* commands

```console
$ flang --version
flang version 23.0.0git (https://github.com/llvm/llvm-project.git e84e480bb5a53c794f303683df6460ddb44bb7ac)
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:9:15: error: The type of 'y' has already been declared as INTEGER(4)
      integer:: y=10
 ^
test.f90:4:17: Declaration of 'y'
        integer:: y=1
 ^
```

## Non-problematic Conditions

The issue does not occur under the following conditions:
* Using a submodule for the procedure definition:
  ```diff
  @@ -4,6 +4,9 @@
         integer:: y=1
       end subroutine
     end interface
  +end
  +
  +submodule (m) smod
 contains
     module procedure sub
       integer:: y=10
  ```

## 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
  ```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to