This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fixed slice offset computation in XEmbox codegen.
ClosedPublic

Authored by vzakhari on Aug 1 2023, 9:41 PM.

Details

Summary

For character type with unknown length we end up generating
a GEP with the base type llvm.ptr<i[width]>. The GEP produces
the address of the first element of the slice, and it should be
using the offset computed in the number of characters, while we were
providing the offset in bytes.

Simple reproducer fails with and w/o HLFIR:

program test
  integer,parameter :: ck = 4
  character(:,ck),allocatable :: res(:,:)
  allocate(character(3,ck) :: res(2,2))
  res(1,1) = ck_'111'
  res(1,2) = ck_'222'
  res(2,1) = ck_'333'
  res(2,2) = ck_'444'
  call check(res)
contains
  subroutine check(res)
    character(:,ck),allocatable :: res(:,:)
    print *, res(2,:)
  end subroutine check
end program test

Diff Detail

Event Timeline

vzakhari created this revision.Aug 1 2023, 9:41 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2023, 9:41 PM
vzakhari requested review of this revision.Aug 1 2023, 9:41 PM
This revision is now accepted and ready to land.Aug 2 2023, 9:34 AM
tblah accepted this revision.Aug 2 2023, 10:15 AM

LGTM