llvm-project
40ad00be - [flang] Define array named constants from the iso_fortran_env intrins… (#201190)

Commit
103 days ago
[flang] Define array named constants from the iso_fortran_env intrins… (#201190) …ic module createIntrinsicModuleDefinitions() only emitted definitions for array named constants belonging to the __fortran_ieee_exceptions intrinsic module. Array constants declared directly in the iso_fortran_env intrinsic module -- in practice character_kinds -- were therefore only lowered as bodyless `fir.global` external declarations at their use site and never defined anywhere, producing an undefined reference at link time. This is usually hidden because scalar iso_fortran_env parameters fold to immediates and constant-shape array accesses are folded away, so the dangling external symbol is DCE'd before linking. It surfaces when the address of the array genuinely escapes to runtime, e.g.: ``` use iso_fortran_env integer :: i, x(1) do i = 1, size(character_kinds) x = findloc(character_kinds, character_kinds(i)) end do ``` which fails with: undefined reference to `_QMiso_fortran_envECcharacter_kinds' Fix by also processing the iso_fortran_env scope in createIntrinsicModuleDefinitions(), so its array constants are emitted as linkonce_odr definitions with initializers. Note that integer_kinds/real_kinds/logical_kinds are unaffected: they are renamed from iso_fortran_env_impl, a non-intrinsic module that is compiled into the runtime, so their definitions already exist there. Assisted-by: AI
Author
Parents
Loading