Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flang bug in procedure arguments with local interfaces #53420

Closed
zerothi opened this issue Jan 26, 2022 · 12 comments
Closed

flang bug in procedure arguments with local interfaces #53420

zerothi opened this issue Jan 26, 2022 · 12 comments

Comments

@zerothi
Copy link

zerothi commented Jan 26, 2022

Tested this with flang 11.1.0, 12.0.1 and 13.0.0.

Consider the following two codes:

m.f90:

module m
  implicit none

contains

  subroutine operate(z, process)

    real, intent(inout) :: z

    abstract interface
      subroutine my_sub(a)
        implicit none
        real, intent(inout) :: a
      end subroutine
    end interface
    procedure(my_sub) :: process

    call process(z)
    write(*,*) 'The result is:', z

  contains

    subroutine sint
    end subroutine sint

  end subroutine operate

end module m

and

n.f90:

module n
  implicit none
contains

  subroutine driver
    use m
    implicit none
    real :: x
    x = 1
    call operate(x, process=timestwo)
  end subroutine driver

  subroutine timestwo(y)
    implicit none
    real, intent(inout) :: y
    y = 2 * y
  end subroutine timestwo

end module n

Compiling with llvm generates error reports:
They are simply compiled with:

flang -c m.f90
flang -c n.f90

llvm-11.1.0:

error: 'my_sub' must be an abstract interface or a procedure with an explicit interface
/opt/generic/llvm/11.1.0/bin/f18: semantic errors in n.f90

llvm-12.0.1:

./m.f18.mod:6:11: error: 'my_sub' must be an abstract interface or a procedure with an explicit interface
  procedure(my_sub)::process
            ^^^^^^
/opt/generic/llvm/12.0.1/bin/f18: Semantic errors in n.f90
flang: in /home/nicpa/tmp, f18 failed with exit status 0: /opt/generic/llvm/12.0.1/bin/f18 -module-suffix .f18.mod -intrinsic-module-directory /opt/generic/llvm/12.0.1/include/flang -c n.f90

llvm-13.0.0:

./n.f90:10:5: error: 'my_sub' is not a procedure
      call operate(x, process=timestwo)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
./m.f18.mod:6:11: error: 'my_sub' must be an abstract interface or a procedure with an explicit interface
  procedure(my_sub)::process
            ^^^^^^
error: Semantic errors in n.f90
flang: in /home/nicpa/tmp, flang-new failed with exit status 1: /opt/generic/llvm/13.0.0/bin/flang-new -fc1 -module-suffix .f18.mod -fdebug-unparse -fno-analyzed-objects-for-unparse -c n.f90

This compiles fine with multiple other compilers and as far as we (@jme52) can tell is standard compliant.

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 26, 2022

@llvm/issue-subscribers-flang-frontend

@banach-space
Copy link
Contributor

I was able to re-produce this with d832078904c.

@ekieri
Copy link
Contributor

ekieri commented Mar 8, 2022

The problem is that the interface definition does not make it to the module file (m.mod). I'll take a look, but it will likely take me a while. No hard feelings if somebody with more experience and/or bandwidth wants to take over, just let me know.

@ekieri
Copy link
Contributor

ekieri commented Mar 15, 2022

I have proposed a fix in
https://reviews.llvm.org/D121738

@banach-space
Copy link
Contributor

This is much appreciated, thank you @ekieri !

@ekieri ekieri closed this as completed in b85922c Mar 16, 2022
vdonaldson pushed a commit to flang-compiler/f18-llvm-project that referenced this issue Mar 29, 2022
Interfaces which are internal to a procedure need to be included in
module files if (and only if) they are referenced in the interface of
the procedure. That is, they are needed if they are the interfaces of
dummy or return value procedures.

Fixes llvm#53420

Differential Revision: https://reviews.llvm.org/D121738
@jme52
Copy link

jme52 commented May 2, 2022

Thank you. If I understand correctly, this fix was applied to the main branch, would it be possible to backport it to the 14.x branch?

@ekieri
Copy link
Contributor

ekieri commented May 2, 2022

Applied to main, yes. I am afraid a backport is unlikely. Flang is still a work in progress, with many important features pending implementation. If you need this fix now, I advice you to build flang yourself: you could build the main branch, or locally cherry-pick this fix to a release branch. Please see https://llvm.org/docs/GettingStarted.html and https://github.com/llvm/llvm-project/blob/main/flang/README.md#building-flang for build instructions.

@jme52
Copy link

jme52 commented May 2, 2022

This bug was breaking compilation of our Fortran 2003 electronic structure software with flang. Even if the developer team can patch flang and build a fixed 14.x compiler, there's little point in doing that if our users cannot access a fixed release. No backport means that we will have to consider that our code does not support flang < 15.

@banach-space
Copy link
Contributor

@jme52 Technically speaking, there was no support for generating machine code or executables in LLVM Flang when the release 14 branch was created. Some bits were there, but not everything. And that’s mostly for F95. It’s a bit better now, but there are still a few key bits missing. So I am a bit surprised that you were able to build a F2003 application :) Which driver did you use - “flang” or “flang-new”? Just curious - it’s great to hear that people have been building real code with LLVM Flang!

@ekieri To back port, we could just follow https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches.

@jme52
Copy link

jme52 commented May 3, 2022

At this point I was looking into the compilation of our code, I have not tested the executable yet. As for the driver, I was calling flang for compilation, is that it? (I cannot find the documentation page where drivers are discussed, if you could point me in its direction that would be helpful). Given your comment, I think I must have been using gfortran for machine code generation still...

@banach-space
Copy link
Contributor

banach-space commented May 3, 2022

@jme52 This helps a lot, thank you!

As for the driver, I was calling flang for compilation, is that it?

No :) That's just a bash script.

(I cannot find the documentation page where drivers are discussed, if you could point me in its direction that would be helpful).

Try here.

Given your comment, I think I must have been using gfortran for machine code generation still...

Indeed. It's really our fault not making this clearer. And you are not the first person to get confused by all this :) Perhaps this could help: https://reviews.llvm.org/D124848?

@jme52
Copy link

jme52 commented May 3, 2022

Try here.

Thank you, that whole page is the document I had been looking for, it's really useful. Now I understand it.

I think the addition of that link to the bash script, as suggested, will be helpful. I think #55243 would also help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants