<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/77282>77282</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] cannot use `real_kinds(i)` in program
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          k-arrows
      </td>
    </tr>
</table>

<pre>
    The following `test1.f90` works but `test2.f90` does not.
```console
$ 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
```

```console
$ 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.
```console
$ gfortran test2.f90
$ ./a.out
 4
           8
          10
          16
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVU1v4zgM_TXyhYghyx9xDj6k0zXQwxxmsfdClmhHW1kKJDlp99cv5DhNJ22mCYLQIR8p6_FR4t6rwSA2pHwg5WPCp7CzrnlZcefs0SedlW_NPzuE3mptj8oMQCoa0Ics7TeUVBSO1r146KZwjrBzRFr0YGxICX0kdEsqevoKa7zVuHhZAYIHuNSc3XtnB8fHk_vkAgCYPILy9rm3LjhuntEcLsG9UyYAYVvCfoBX_yFhtUOun1-UkZ6wzQ3oR0yd3Yljd-LyO3HFBXcbVN5ZrHrHoZHwBZeR9V5zM6wMHq-5j8GUsJandgrLctVi2WLzxRaLrReb0fNDddX15e-dUmBfS-G8_B91oEzAAR2QfEvyLahLRFpQQPJHyL6RyG1q1W8tiPRK-zXV7BbV7CPV7eQdYW2nDGGtlvGFCWvDuI-_EbyiZbcu6tTOezHQT0YEZU0ct-dfv0YeM9dxr3PF9unvn1ZOGqOH1WnA10DYA32tZiXmW5iMxF4ZlOCwR4dGIAR7KvfzitS_fnzc_Pq0xPtuYjV0zrr4oJV5QQfCjiM3EnquNEo4qrADfFUBhJUIGRBWx-atDnFNjwjKHKzgcUfvzH6pmacQ4aOPeR0CPy-ovJ9wbqcFFWDkb6fw3tlO4wh-j0L1SsS88Q3QHJSzZkQTUnjqwduYu9fIPYLQ1iOEnfKnsik8TCGS_nvip5PudAaqHp5mZQ4Lg98efGfgZ1l8nsDiorrlU1973ofv4rmewkQ2udzkG55gk61psaYZoyzZNV1ZdkjlRgrBRS-rLCuLLMvKHAUVyDaJahhlBc1oTWtaFSxlgpeIUvQ1FlXZd6SgOHKlU60PY2rdkMwcNus1q1mieYfaz_cMY7OCCGPxynFNxK-6afCkoFr54C8Vggp6vpzaOaN8BMGNsWGmmVT082hWNPZrmcNkcrrZhbD38zS0hLWDCrupS4Ud47zpw9ms9s7-iyIQ1s6v7Qlr5zf_PwAA__-2ORk_">