Hi Mikael, I definitely agree that we need a temporary for the result of MERGE(a,a,.true.), I just haven't found out how to do that.
The reason for the bad one-liner was that in gfc_simplify_merge result = gfc_get_parentheses (result); actually does have issues, in that the subsequent gfc_simplify_expr (result, 1); seems to fail in interesting cases (as in PR105371). So that is something to look into... Cheers, Harald > Gesendet: Donnerstag, 06. Oktober 2022 um 22:32 Uhr > Von: "Mikael Morin" <morin-mik...@orange.fr> > An: "Harald Anlauf" <anl...@gmx.de> > Cc: "gcc-patches" <gcc-patches@gcc.gnu.org>, "fortran" <fort...@gcc.gnu.org> > Betreff: Re: [PATCH, v2] Fortran: reject procedures and procedure pointers as > IO element [PR107074] > > Le 06/10/2022 à 10:37, Mikael Morin a écrit : > > Le 05/10/2022 à 22:40, Harald Anlauf a écrit : > >> Hi Mikael, > >> > >>> Gesendet: Mittwoch, 05. Oktober 2022 um 12:34 Uhr > >>> Von: "Mikael Morin" <morin-mik...@orange.fr> > >>> Please move the check to resolve_transfer in resolve.cc. > >> > >> I have done this, see attached updated patch. > >> > >> Regtests cleanly on x86_64-pc-linux-gnu. > >> > >>> Strangely, the patch doesn't seem to fix the problem on the testcase > >>> here. There is an outer parenthese expression preventing the condition > >>> you added from triggering. Can you double check? > >> > >> You are right: I had a one-liner in my worktree from PR105371 that > >> fixes an issue with gfc_simplify_merge and that seems to help here. > >> It is now included. > >> > > The rest looks good, but I'm not sure about your one-liner. > > I will try to come with a real test later, but in principle, if you have > > a call to FOO(MERGE(A,A,.TRUE.)) you can't simplify it to FOO(A) as > > writes to the argument in FOO should not overwrite the content of A. The > > dummy should be associated with a temporary value, not to A. > > > Here is a test that your patch breaks. > Admittedly it's rejected if A has the INTENT(INOUT) attribute, but > without it, I think it's allowed. > > program p > integer :: b > b = 1 > call foo(merge(b,b,.true.)) > if (b /= 1) stop 1 > contains > subroutine foo(a) > integer :: a > if (a == 1) a = 42 > end subroutine foo > end program p > >