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] cannot use real_kinds(i) in program #77282

Closed
k-arrows opened this issue Jan 8, 2024 · 3 comments
Closed

[Flang] cannot use real_kinds(i) in program #77282

k-arrows opened this issue Jan 8, 2024 · 3 comments
Labels
flang Flang issues not falling into any other category

Comments

@k-arrows
Copy link

k-arrows commented Jan 8, 2024

The following test1.f90 works but test2.f90 does not.

$ cat test1.f90
program test1
    use iso_fortran_env
    print *, size(real_kinds)
    print *, real_kinds(1)
    print *, real_kinds(2)
    print *, real_kinds(3)
    print *, real_kinds(4)
    print *, real_kinds(5)
    print *, real_kinds(6)
end program test1
$ flang-new test1.f90
$ ./a.out
 6
 2
 3
 4
 8
 10
 16
$ cat test2.f90
program test2
    use iso_fortran_env
    integer :: i
    do i = 1, size(real_kinds)
        print *, real_kinds(i)
    end do
end program test2
$ flang-new test2.f90
/usr/bin/ld: /tmp/test2-05b748.o: in function `_QQmain':
FIRModule:(.text+0x63): undefined reference to `_QMiso_fortran_envECreal_kinds'
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)

It seems to be a linker issue, so it may be a problem specific to my environment. If so, please close this issue. But in my environment test2.f90 works if I use gfortran.

$ gfortran test2.f90
$ ./a.out
           4
           8
          10
          16
@github-actions github-actions bot added the flang Flang issues not falling into any other category label Jan 8, 2024
@hym3242
Copy link

hym3242 commented Jan 8, 2024

Maybe you should also post linker command invocation with -v

@brtnfld
Copy link

brtnfld commented Apr 4, 2024

It also fails in the same manner for integer_kinds and logical_kinds. This causes HDF5 fail to be configured, as we use this test program if ISO_FORTRAN_ENV is available.

PROGRAM FC08_AVAIL_KINDS
       USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY : stdout=>OUTPUT_UNIT, integer_kinds, real_kinds, logical_kinds
       IMPLICIT NONE
       INTEGER :: ik, jk, k, max_decimal_prec
       INTEGER :: num_rkinds, num_ikinds, num_lkinds
 
       num_ikinds = SIZE(integer_kinds)

       DO k = 1, num_ikinds
          PRINT*, integer_kinds(k)
       ENDDO

 END PROGRAM FC08_AVAIL_KINDS

flang-new version 19.0.0git (https://github.com/llvm/llvm-project.git a4de589)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/12
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/13
Found candidate GCC installation: /usr/lib64/gcc/x86_64-suse-linux/7
Selected GCC installation: /usr/lib64/gcc/x86_64-suse-linux/13
Candidate multilib: .;@m64
Selected multilib: .;@m64
"packages/llvm-project/build/bin/flang-new" -fc1 -triple x86_64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu x86-64 -mframe-pointer=all -o /tmp/test-72928d.o -x f95-cpp-input test.F90
"/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld" --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -pie -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/Scrt1.o /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/13/crtbeginS.o -L/usr/lib64/gcc/x86_64-suse-linux/13 -L/usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/lib -L/lib -L/usr/lib -L/home/brtnfld/packages/aocc-compiler-4.2.0/lib -L/home/brtnfld/packages/aocc-compiler-4.2.0/lib32 -L/usr/lib64 -L/usr/lib -L/home/brtnfld/packages/aocc-compiler-4.2.0/lib -L/home/brtnfld/packages/aocc-compiler-4.2.0/lib32 -L/usr/lib64 -L/usr/lib -L. /tmp/test-72928d.o -L/home/brtnfld/packages/llvm-project/build/lib --whole-archive -lFortran_main --no-whole-archive -lFortranRuntime -lFortranDecimal -lm -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-suse-linux/13/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/13/../../../../lib64/crtn.o
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /tmp/test-72928d.o: in function _QQmain': FIRModule:(.text+0x69): undefined reference to _QMiso_fortran_envECinteger_kinds'
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)

@hakostra
Copy link

hakostra commented Sep 4, 2024

This issue seems to be fixed:

$ flang-new flang-issue-77282.f90 
$ ./a.out 
 2
 3
 4
 8
 10
 16

integer_kinds print:

$ ./a.out 
 1
 2
 4
 8
 16

Tested with:

$ flang-new --version
flang-new version 20.0.0git (https://github.com/llvm/llvm-project.git 6c607cfb2c2d8acd2b92d7ed8106ab1e4fc0d79d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/llvm/llvm-project/install/bin

@k-arrows k-arrows closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang Flang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

4 participants