flang icon indicating copy to clipboard operation
flang copied to clipboard

Flang fails to match procedure pointer interface

Open jaopaulolc opened this issue 5 years ago • 2 comments

This code:

program main
  implicit none
  abstract interface
    subroutine dgemm_interface(A, B, C, m, k, n)
      double precision, dimension(:), allocatable, intent(in), target :: A, B
      double precision, dimension(:), allocatable, intent(inout), target :: C
      integer, intent(in) :: m, n, k
    end subroutine
  end interface
​
  procedure (dgemm_interface), pointer :: f
​
  f => blas_dgemm
​
contains
  subroutine blas_dgemm(A, B, C, m, k, n)
    double precision, dimension(:), allocatable, intent(in), target :: A, B
    double precision, dimension(:), allocatable, intent(inout), target :: C
    integer, intent(in) :: m, n, k
​
    call dgemm('n', 'n', m, n, k, 1.0, A, k, B, n, 1.0, C, m)
  end subroutine
end program

produces this error:

clang version 7.1.0 
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/flang/bin
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/6
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/7
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/9
Selected GCC installation: /usr/lib64/gcc/x86_64-suse-linux/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version 9.2
 "/opt/flang/bin/flang1" interface.f90 -opt 0 -terse 1 -inform warn -nohpf -nostatic -cmdline '+flang -v interface.f90 -lopenblas' -inform warn -ieee 0 -x 19 0x400000 -quad -x 68 0x1 -x 59 4 -x 15 2 -x 49 0x400004 -x 51 0x20 -x 57 0x4c -x 58 0x10000 -x 124 0x1000 -tp px -x 57 0xfb0000 -x 58 0x78031040 -x 47 0x08 -x 48 4608 -x 49 0x100 -stdinc /opt/flang/bin/../include:/usr/local/include:/opt/flang/lib/clang/7.1.0/include:/include:/usr/include -def __amd64__=1 -def __amd64=1 -def __x86_64=1 -def __x86_64__=1 -def __REGISTER_PREFIX__= -def __NO_MATH_INLINES=1 -def __SSE2__=1 -def __SSE2_MATH__=1 -def __SSE__=1 -def __SSE_MATH__=1 -def __MMX__=1 -def __SIZEOF_FLOAT128__=16 -def unix=1 -def __unix=1 -def __unix__=1 -def linux=1 -def __linux=1 -def __linux__=1 -def __gnu_linux__=1 -def __ELF__=1 -def __FLOAT128__=1 -def __SIZE_TYPE__=long unsigned int -def __PTRDIFF_TYPE__=long int -def _LP64=1 -def __LP64__=1 -def __amd_64__amd64__ -def __k8 -def __k8__ -def __THROW= -def __extension__= -def __PGLLVM__ -freeform -vect 48 -x 54 1 -x 70 0x40000000 -y 163 0xc0000000 -x 189 0x10 -stbfile interface-a2079a.stb -modexport interface-a2079a.cmod -modindex interface-a2079a.cmdx -output interface-a2079a.ilm
F90-S-1008-Interface mismatch in procedure pointer assignment f (interface.f90: 13)
  0 inform,   0 warnings,   1 severes, 0 fatal for main

However it works when pointer f is either initialized in the declaration statement or if the subroutine blas_dgemm is used instead of the abstract interface dgemm_interface. Like this: procedure (dgemm_interface), pointer :: f => blas_dgemm Or like this:

procedure (blas_dgemm), pointer :: f
f => blas_dgemm

The bug also happens with non-abstract interfaces.

jaopaulolc avatar Feb 28 '20 02:02 jaopaulolc

Note: The workaround, "procedure (blas_dgemm), pointer :: f", causes a seg fault for the same reason as Flang #872

mleair avatar Feb 28 '20 19:02 mleair

According to the Fortran 2018 standard, section 15.4.3.6 ("Procedure declaration statement"), a procedure pointer can only be initialized to an non-elemental external or module procedure, not an internal procedure as in the blas_dgemm example. The fact that f can be initialized to blas_dgemm in the declaration is actually a bug, IIUC.

bryanpkc avatar Feb 06 '21 21:02 bryanpkc