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][polymorphic] Type descriptors are not emitted during separate compilation #63775

Closed
rofirrim opened this issue Jul 10, 2023 · 9 comments
Assignees
Labels

Comments

@rofirrim
Copy link
Collaborator

I'm aware the polymorphic support is still experimental but I think it is useful to have this recorded.

Consider the two following files:

! mymod.f90
module mymod
  implicit none
  type, abstract :: myfoo
    integer :: x
  end type myfoo
end module mymod
! mymod2.f90
module mymod2
  use mymod, only: myfoo
  implicit none
  contains
    subroutine mysub(myparam)
      implicit none
      class(myfoo), pointer :: myparam

      nullify(myparam)
    end subroutine mysub
end module mymod2

If we compile them separatedly, mymod2.f90 will crash while generating FIR because the type descriptor of myfoo has not been emitted and nullify needs it.

$ flang-new -flang-experimental-polymorphism -c mymod.f90
$ flang-new -flang-experimental-polymorphism -c mymod2.f90
error: loc("/home/rferrer/fio/upstream/llvm-install/tmp/mymod2.f90":11:7): no type descriptor found for NULLIFY
LLVM ERROR: aborting

I looked into it a bit and IIUC, it seems that the type descriptor is emitted as part of lowerModuleDeclScope in the Bridge. If the two files together are compiled as a single file (e.g. adding an include 'mymod.f90' at the beginning of mymod2.f90) then the crash does not happen because the descriptor is indeed emitted.

In a separate compilation setting, AFAICT the module is loaded and parsed and its names resolved but I don't think we synthesise enough information so the type descriptors get emitted as a consequence of a use-statement. One thing I saw is that the descriptors (and other runtime info) are already emitted as weak global objects so emitting repeated definitions in different object files should not be a problem.

Any hints on how we could address this? I wonder if it makes sense to check use-associations to derived types and emit their descriptors if they haven't been emitted yet?

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 10, 2023

@llvm/issue-subscribers-flang-ir

@clementval clementval self-assigned this Jul 10, 2023
@clementval
Copy link
Contributor

The problem is coming from the fact that we try to find the global before we emit it. I'll have a patch that will fix this issue up for review tomorrow.

@rofirrim
Copy link
Collaborator Author

The problem is coming from the fact that we try to find the global before we emit it. I'll have a patch that will fix this issue up for review tomorrow.

Thanks a lot Valentin!

@clementval
Copy link
Contributor

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 11, 2023

@llvm/issue-subscribers-flang-runtime

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 11, 2023

@llvm/issue-subscribers-flang-ir

clementval added a commit that referenced this issue Jul 11, 2023
Do not look for the global early in nullify codegen. The type descriptor
can be emitted later and it would raise an error as it could not be found.
Use `fir.type_desc` instead so it delays the type descriptor lookup until
evrything is emitted.

#63775

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D154982
@clementval
Copy link
Contributor

@rofirrim The patch has landed upstream. Please confirm it solved your issue.

@rofirrim
Copy link
Collaborator Author

Hi @clementval, yes it fixes my issue.

Thanks again for the prompt fix.

@clementval
Copy link
Contributor

Thanks for confirming and reporting the issue!

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

No branches or pull requests

4 participants