Issue 208669
Summary [Flang] -flto silently truncates COMMON block size past 4 GB
Labels
Assignees
Reporter ejose02
    With -flto, flang silently miscompiles programs whose Fortran COMMON block exceeds 2³² bytes (~4 GB).

Expected behavior: The full COMMON size is preserved through link, and in-bounds stores complete without faulting.

Actual behavior: The COMMON symbol's ELF size is truncated to the low 32 bits of the true size, so less memory is reserved than declared. Stores past that point segfault at runtime, with no compile-time or link-time diagnostic. Without -flto, the full size is retained and the program runs correctly.

Reproducer:

 ```Fortran
program repro
  implicit none
  integer, parameter :: idim = 1501000
  integer, parameter :: idim2 = idim + 1
  integer, parameter :: nbig = 400 * idim2
  integer, parameter :: nmed = nbig / 10
  integer, parameter :: nlist = idim
  integer :: iamawk(nbig), ijvarcomp(nbig)
  integer :: ivarawk(nmed), jvarawk(nmed)
  integer :: ivarawkcomp(nmed), iamindex(nmed)
  integer :: j_offset(idim+1)
  integer :: icompactlist(nlist)
  integer :: jvarawkcomp(nlist), icclist(nlist), irealcomp(nlist)
  common /big/ iamawk, ijvarcomp, ivarawk, jvarawk, ivarawkcomp, iamindex, &
       j_offset, icompactlist, jvarawkcomp, icclist, irealcomp
  integer :: ipart

  iamawk(1) = 1
  iamawk(nbig) = 2
  ijvarcomp(1) = 3
  ipart = 750457
  call touch_past_4gb(ipart)
  print *, 'TEST PASSED'
contains
  subroutine touch_past_4gb(ipart)
    integer, intent(in) :: ipart
    icompactlist(ipart) = 3
  end subroutine
end program
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to