llvm-project/flang/test/Lower/HLFIR/elemental-user-procedure-stacksave.f90
jeanPerier 94c024aded
[flang][lowering] delay stack save/restor emission in elemental calls (#109142)
stack save/restore emitted for character elemental function result
allocation inside hlfir.elemental in lowering created memory bugs
because result memory is actually still used after the stack restore
when lowering the elemental into a loop where the result element is
copied into the array result storage.

Instead of adding special handling for stack save/restore in lowering,
just avoid emitting those since the stack reclaim pass is able to emit
them in the generated loop. Not having those stack save/restore will
also help optimizations that want to elide the temporary allocation for
the element result when that is possible.
2024-09-19 13:52:58 +02:00

23 lines
690 B
Fortran

! Check that stack save and restore needed for elemental function result
! allocation inside loops are not emitted directly in lowering, but inserted if
! needed in the stack-reclaim pass.
! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s --check-prefix=CHECK-HLFIR
! RUN: %flang_fc1 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-LLVM
subroutine foo(c1, c2)
character(*), dimension(100) :: c1, c2
interface
elemental pure function func(c)
character(*), intent(in) :: c
character(len(c)) :: func
end function
end interface
c1 = func(c2)
end subroutine
! CHECK-HLFIR-NOT: stacksave
! CHECK: return
! CHECK-LLVM: stacksave
! CHECK-LLVM: stackrestore