This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Fixed where/elsewhere mask saving in case of conflicts.
ClosedPublic

Authored by vzakhari on Aug 2 2023, 6:11 PM.

Details

Summary

The assignments inside where/elsewhere may affect variables participating
in the mask expression, but execution of the assignments must not affect
the established control mask(s) (F'18 10.2.3.2 p. 13).

The following example must print all 42's:

program test
  integer c(3)
  logical :: mask(3) = .true.
  where (mask)
     c = f()
  end where
  print *, c
contains
  integer function f()
    mask = .false.
    f = 42
  end function f
end program test

Diff Detail

Event Timeline

vzakhari created this revision.Aug 2 2023, 6:11 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2023, 6:11 PM
vzakhari requested review of this revision.Aug 2 2023, 6:11 PM
vzakhari edited the summary of this revision. (Show Details)
tblah added inline comments.Aug 3 2023, 2:15 AM
flang/lib/Optimizer/HLFIR/Transforms/ScheduleOrderedAssignments.cpp
572

I think this applies to FORALL too. See 10.2.4.2.1: the evaluation of the mask-expr happens before execution of the FORALL body.

But it isn't spelt out as clearly as for WHERE/ELSEWHERE

vzakhari added inline comments.Aug 3 2023, 8:29 AM
flang/lib/Optimizer/HLFIR/Transforms/ScheduleOrderedAssignments.cpp
572

At the same time, FORALL has a limitation that only pure function references can appear in the body. And I do not know if an evaluation can modify the mask-expr variables' values without a function reference (note that the assignment effects have been already taken into account in the code). I would like to keep it like this for the time being.

tblah accepted this revision.Aug 4 2023, 2:13 AM

LGTM, thanks for this

This revision is now accepted and ready to land.Aug 4 2023, 2:13 AM