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-new trying to access the imported module inside the .mod file #97398

Closed
Thirumalai-Shaktivel opened this issue Jul 2, 2024 · 8 comments · Fixed by #98083
Closed

Flang-new trying to access the imported module inside the .mod file #97398

Thirumalai-Shaktivel opened this issue Jul 2, 2024 · 8 comments · Fixed by #98083
Assignees

Comments

@Thirumalai-Shaktivel
Copy link
Member

Reproducible files are available here, module-bug.tar.gz

MRE:

program app

  use circle, only : area
  implicit none
  real :: r

  r = 2.0
  write(*,*) 'radius = ', r
  write(*,*) 'area = ', area(r)

end program app

Flang-new

$ ./build.sh
error: Semantic errors in app.f90
../libdummy/include/circle.mod:4:5: error: Cannot read module file for module 'constant_pi': Source file 'constant_pi.mod' was not found
  use constant_pi,only:get_pi
      ^^^^^^^^^^^

GFortran

$ ./build.sh
 radius =    2.00000000    
 area =    12.5663710
@Thirumalai-Shaktivel Thirumalai-Shaktivel added flang:runtime flang Flang issues not falling into any other category labels Jul 2, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 2, 2024

@llvm/issue-subscribers-flang-runtime

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Reproducible files are available here, [module-bug.tar.gz](https://github.com/user-attachments/files/16065435/module-bug.tar.gz)

MRE:

program app

  use circle, only : area
  implicit none
  real :: r

  r = 2.0
  write(*,*) 'radius = ', r
  write(*,*) 'area = ', area(r)

end program app

Flang-new

$ ./build.sh
error: Semantic errors in app.f90
../libdummy/include/circle.mod:4:5: error: Cannot read module file for module 'constant_pi': Source file 'constant_pi.mod' was not found
  use constant_pi,only:get_pi
      ^^^^^^^^^^^

GFortran

$ ./build.sh
 radius =    2.00000000    
 area =    12.5663710

@psteinfeld psteinfeld added the bug Indicates an unexpected problem or unintended behavior label Jul 2, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 2, 2024

@llvm/issue-subscribers-bug

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Reproducible files are available here, [module-bug.tar.gz](https://github.com/user-attachments/files/16065435/module-bug.tar.gz)

MRE:

program app

  use circle, only : area
  implicit none
  real :: r

  r = 2.0
  write(*,*) 'radius = ', r
  write(*,*) 'area = ', area(r)

end program app

Flang-new

$ ./build.sh
error: Semantic errors in app.f90
../libdummy/include/circle.mod:4:5: error: Cannot read module file for module 'constant_pi': Source file 'constant_pi.mod' was not found
  use constant_pi,only:get_pi
      ^^^^^^^^^^^

GFortran

$ ./build.sh
 radius =    2.00000000    
 area =    12.5663710

@EugeneZelenko EugeneZelenko added flang:frontend and removed flang:runtime flang Flang issues not falling into any other category labels Jul 2, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 2, 2024

@llvm/issue-subscribers-flang-frontend

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Reproducible files are available here, [module-bug.tar.gz](https://github.com/user-attachments/files/16065435/module-bug.tar.gz)

MRE:

program app

  use circle, only : area
  implicit none
  real :: r

  r = 2.0
  write(*,*) 'radius = ', r
  write(*,*) 'area = ', area(r)

end program app

Flang-new

$ ./build.sh
error: Semantic errors in app.f90
../libdummy/include/circle.mod:4:5: error: Cannot read module file for module 'constant_pi': Source file 'constant_pi.mod' was not found
  use constant_pi,only:get_pi
      ^^^^^^^^^^^

GFortran

$ ./build.sh
 radius =    2.00000000    
 area =    12.5663710

@klausler
Copy link
Contributor

klausler commented Jul 2, 2024

Yes, that's how this compiler works.

@klausler klausler closed this as completed Jul 2, 2024
@EugeneZelenko EugeneZelenko added question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! and removed bug Indicates an unexpected problem or unintended behavior labels Jul 2, 2024
@Thirumalai-Shaktivel
Copy link
Member Author

Thirumalai-Shaktivel commented Jul 3, 2024

Hi @klausler, the example shared above is the simple reproducible example. But this issue is faced while building an application which has new CMake build system.

The constant_pi module is built and packaged into shared library. The app.f90 uses only the circle module to compute, but it shouldn't have any knowledge of the constant_pi module which is about internal implementation.

This is the same behaviour with classic Flang. But, ifort, ifx and gfortran works fine.

Can you please clarify more and also any possible workarounds?

@ningli-amd
Copy link

Any further comments on this? I believe the reported problem is a valid one.

klausler added a commit to klausler/llvm-project that referenced this issue Jul 8, 2024
Module files emitted by this Fortran compiler are valid Fortran source
files.  Symbols that are USE-associated into modules are represented
in their module files with USE statements and special comments with
hash codes in them to ensure that those USE statements resolve to
the same modules that were used to build the module when its module
file was generated.

This scheme prevents unchecked module file growth in large applications
by not emitting USE-associated symbols redundantly.  This problem can
be especially bad when derived type definitions must be repeated in
the module files of their clients, and the clients of those modules,
and so on.  However, this scheme has the disadvantage that clients of
modules must be compiled with dependent modules in the module search path.

This new -fhermetic-module-files option causes module file output to
be free of dependences on any non-intrinsic module files; dependent
modules are instead emitted as part of the module file, rather than
being USE-associated.  It is intended for top level library module files
that are shipped with binary libraries when it is not convenient to collect
and ship their dependent module files as well.

Fixes llvm#97398.
@klausler
Copy link
Contributor

klausler commented Jul 8, 2024

#98083

@EugeneZelenko EugeneZelenko removed the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Jul 8, 2024
@Thirumalai-Shaktivel
Copy link
Member Author

Thank you @klausler, the PR changes seem to fix the issue.

@ningli-amd, can you please check with the application?

@klausler klausler self-assigned this Jul 10, 2024
aaryanshukla pushed a commit to aaryanshukla/llvm-project that referenced this issue Jul 14, 2024
Module files emitted by this Fortran compiler are valid Fortran source
files. Symbols that are USE-associated into modules are represented in
their module files with USE statements and special comments with hash
codes in them to ensure that those USE statements resolve to the same
modules that were used to build the module when its module file was
generated.

This scheme prevents unchecked module file growth in large applications
by not emitting USE-associated symbols redundantly. This problem can be
especially bad when derived type definitions must be repeated in the
module files of their clients, and the clients of those modules, and so
on. However, this scheme has the disadvantage that clients of modules
must be compiled with dependent modules in the module search path.

This new -fhermetic-module-files option causes module file output to be
free of dependences on any non-intrinsic module files; dependent modules
are instead emitted as part of the module file, rather than being
USE-associated. It is intended for top level library module files that
are shipped with binary libraries when it is not convenient to collect
and ship their dependent module files as well.

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

Successfully merging a pull request may close this issue.

6 participants