llvm / llvm-project

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

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

Closed Thirumalai-Shaktivel closed 2 months ago

Thirumalai-Shaktivel commented 3 months ago

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
llvmbot commented 3 months ago

@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: ```fortran 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 ```console $ ./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 ```console $ ./build.sh radius = 2.00000000 area = 12.5663710 ```
llvmbot commented 3 months ago

@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: ```fortran 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 ```console $ ./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 ```console $ ./build.sh radius = 2.00000000 area = 12.5663710 ```
llvmbot commented 3 months ago

@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: ```fortran 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 ```console $ ./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 ```console $ ./build.sh radius = 2.00000000 area = 12.5663710 ```
klausler commented 3 months ago

Yes, that's how this compiler works.

Thirumalai-Shaktivel commented 3 months ago

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 commented 3 months ago

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

klausler commented 2 months ago

https://github.com/llvm/llvm-project/pull/98083

Thirumalai-Shaktivel commented 2 months ago

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

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