public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/107874] New: merge not using all its arguments
@ 2022-11-26  4:57 john.harper at vuw dot ac.nz
  2022-11-26 20:30 ` [Bug fortran/107874] " anlauf at gcc dot gnu.org
                   ` (23 more replies)
  0 siblings, 24 replies; 25+ messages in thread
From: john.harper at vuw dot ac.nz @ 2022-11-26  4:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107874

            Bug ID: 107874
           Summary: merge not using all its arguments
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: john.harper at vuw dot ac.nz
  Target Milestone: ---

The F2018 standard 15.5.3 requires all actual arguments in a function reference
to be evaluated.

In the program below, merge has three scalar arguments; ifort evaluates
all three, gfortran evaluates only the useful two, which violates 15.5.3.

program testmerge9
  implicit none
  integer i
  logical:: x(2)=(/.true., .false./), y ! avoiding [ ] allows f95 option
  do i = 1,2
     y = merge(tstuff(),fstuff(),x(i))
     print *,y
  end do
contains
  logical function tstuff()
    print *,'tstuff'
    tstuff = .true.
  end function tstuff

  logical function fstuff()
    print *,'fstuff'
    fstuff = .false.
  end function fstuff
end program testmerge9

Steve Kargl said "Looks like a bug. Feel free to send a bug report with this
patch."

diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index bb938026828..c5b63d356e1 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -7538,9 +7538,9 @@ gfc_conv_intrinsic_merge (gfc_se * se, gfc_expr * expr)
   gfc_conv_intrinsic_function_args (se, expr, args, num_args);
   if (expr->ts.type != BT_CHARACTER)
     {
-      tsource = args[0];
-      fsource = args[1];
-      mask = args[2];
+      tsource = gfc_evaluate_now (args[0], &se->pre);
+      fsource = gfc_evaluate_now (args[1], &se->pre);
+      mask = gfc_evaluate_now (args[2], &se->pre);
     }
   else
     {

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2022-12-07 21:22 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-26  4:57 [Bug fortran/107874] New: merge not using all its arguments john.harper at vuw dot ac.nz
2022-11-26 20:30 ` [Bug fortran/107874] " anlauf at gcc dot gnu.org
2022-11-27  1:03 ` kargl at gcc dot gnu.org
2022-11-27 20:00 ` anlauf at gcc dot gnu.org
2022-11-27 21:07 ` anlauf at gcc dot gnu.org
2022-11-27 21:24 ` sgk at troutmask dot apl.washington.edu
2022-11-28 20:07 ` anlauf at gcc dot gnu.org
2022-11-29 18:19 ` cvs-commit at gcc dot gnu.org
2022-12-01 20:28 ` anlauf at gcc dot gnu.org
2022-12-01 21:36 ` jvdelisle2 at gmail dot com
2022-12-01 21:55 ` anlauf at gcc dot gnu.org
2022-12-01 22:17 ` anlauf at gcc dot gnu.org
2022-12-01 23:46 ` jvdelisle at gcc dot gnu.org
2022-12-01 23:54 ` jvdelisle at gcc dot gnu.org
2022-12-02  0:34 ` jvdelisle at gcc dot gnu.org
2022-12-02 17:48 ` anlauf at gcc dot gnu.org
2022-12-02 19:44 ` jvdelisle at gcc dot gnu.org
2022-12-02 20:22 ` anlauf at gcc dot gnu.org
2022-12-02 20:50 ` john.harper at vuw dot ac.nz
2022-12-02 21:05 ` anlauf at gcc dot gnu.org
2022-12-02 21:26 ` anlauf at gcc dot gnu.org
2022-12-02 21:27 ` john.harper at vuw dot ac.nz
2022-12-02 21:35 ` cvs-commit at gcc dot gnu.org
2022-12-02 21:42 ` jvdelisle at gcc dot gnu.org
2022-12-07 21:22 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).