llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

[Flang] Compilation error when the same subroutine name but different arugment types #71367

Closed ohno-fj closed 11 months ago

ohno-fj commented 1 year ago
Version of flang-new : 18.0.0(1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4)

A compilation error occurs if subroutine with the same name is declared in interface and subroutine statements but their argument types are not the same.
When I specify -flang-experimental-hlfir at the compilation, I can avoid the compilation error.

The following are the test program, Flang-new, Gfortran and ifort compilation result.

gc_e157_2.f90:

program main
  interface
     subroutine sub(a)
       integer,dimension(3):: a
     end subroutine sub
  end interface

  integer,dimension(3):: a
  call sub(a)
end program main

subroutine sub(s)
  integer,dimension(:):: s
end subroutine sub
$ flang-new gc_e157_2.f90
./gc_e157_2.f90:3:17: warning: The global subprogram 'sub' is not compatible with its local procedure declaration (incompatible dummy argument #1: incompatible dummy data object attributes)
       subroutine sub(a)
                  ^^^
./gc_e157_2.f90:12:12: Declaration of 'sub'
  subroutine sub(s)
             ^^^
./gc_e157_2.f90:3:17: Declaration of 'sub'
       subroutine sub(a)
                  ^^^
error: loc("/work/home/ohno/CT/test/fort/tp/reproducer/Metro/gc_err/gc_e157_2.f90":9:3): 'fir.convert' op invalid type conversion
error: verification of lowering to FIR failed

$
$ flang-new gc_e157_2.f90 -flang-experimental-hlfir
./gc_e157_2.f90:3:17: warning: The global subprogram 'sub' is not compatible with its local procedure declaration (incompatible dummy argument #1: incompatible dummy data object attributes)
       subroutine sub(a)
                  ^^^
./gc_e157_2.f90:12:12: Declaration of 'sub'
  subroutine sub(s)
             ^^^
./gc_e157_2.f90:3:17: Declaration of 'sub'
       subroutine sub(a)
                  ^^^
$ gfortran gc_e157_2.f90
gc_e157_2.f90:3:19:

    3 |      subroutine sub(a)
      |                   1
Warning: Interface mismatch in global procedure ‘sub’ at (1): Shape mismatch in argument 'a'
$
$ ifort gc_e157_2.f90
$
llvmbot commented 1 year ago

@llvm/issue-subscribers-flang-frontend

Author: None (ohno-fj)

``` Version of flang-new : 18.0.0(1c876ff5155c4feeb2b2885eb3e6abda17c4b7f4) ``` A compilation error occurs if `subroutine` with the same name is declared in `interface` and `subroutine` statements but their argument types are not the same. When I specify `-flang-experimental-hlfir` at the compilation, I can avoid the compilation error. The following are the test program, Flang-new, Gfortran and ifort compilation result. gc_e157_2.f90: ```fortran program main interface subroutine sub(a) integer,dimension(3):: a end subroutine sub end interface integer,dimension(3):: a call sub(a) end program main subroutine sub(s) integer,dimension(:):: s end subroutine sub ``` ``` $ flang-new gc_e157_2.f90 ./gc_e157_2.f90:3:17: warning: The global subprogram 'sub' is not compatible with its local procedure declaration (incompatible dummy argument #1: incompatible dummy data object attributes) subroutine sub(a) ^^^ ./gc_e157_2.f90:12:12: Declaration of 'sub' subroutine sub(s) ^^^ ./gc_e157_2.f90:3:17: Declaration of 'sub' subroutine sub(a) ^^^ error: loc("/work/home/ohno/CT/test/fort/tp/reproducer/Metro/gc_err/gc_e157_2.f90":9:3): 'fir.convert' op invalid type conversion error: verification of lowering to FIR failed $ ``` ``` $ flang-new gc_e157_2.f90 -flang-experimental-hlfir ./gc_e157_2.f90:3:17: warning: The global subprogram 'sub' is not compatible with its local procedure declaration (incompatible dummy argument #1: incompatible dummy data object attributes) subroutine sub(a) ^^^ ./gc_e157_2.f90:12:12: Declaration of 'sub' subroutine sub(s) ^^^ ./gc_e157_2.f90:3:17: Declaration of 'sub' subroutine sub(a) ^^^ ``` ``` $ gfortran gc_e157_2.f90 gc_e157_2.f90:3:19: 3 | subroutine sub(a) | 1 Warning: Interface mismatch in global procedure ‘sub’ at (1): Shape mismatch in argument 'a' $ ``` ``` $ ifort gc_e157_2.f90 $ ```
yus3710-fj commented 11 months ago

This issue isn't reproduced now because HLFIR is enabled by default.

$ flang-new -v gc_e157_2.f90
flang-new version 18.0.0 (https://github.com/llvm/llvm-project.git ba89749cd24950c9c51f4cc64277ce0421d86d20)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
 :
$