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

--- Comment #3 from anlauf at gcc dot gnu.org ---
(In reply to kargl from comment #2)
> Harald, you are likely right the patch can be moved down.  I'll programmed
> up the example from the Fortran 2018 standard, which works as expected.  So,
> there is definitely something about a scalar mask choosing the actual
> argument before both are evaluated.
> 
>    program foo

Steve,

this example from the standard seems to be working down to 7.5 for me.
Am I missing something?  Do we need this in the testsuite?

I'd say it's rather the following two lines replacing the loop in the
reproducer in comment#0:

  print *, merge(tstuff(),fstuff(),.true.)
  print *, merge(tstuff(),fstuff(),.false.)

This is mis-simplified in simplify.cc:4909

gfc_expr *
gfc_simplify_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask)
{
  gfc_expr * result;
  gfc_constructor *tsource_ctor, *fsource_ctor, *mask_ctor;

  if (mask->expr_type == EXPR_CONSTANT)
    {
      result = gfc_copy_expr (mask->value.logical ? tsource : fsource);
      /* Parenthesis is needed to get lower bounds of 1.  */
      result = gfc_get_parentheses (result);
      gfc_simplify_expr (result, 1);
      return result;
    }

So unless tsource and fsource are both constant, we have to give up here.

Reply via email to