public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sgk at troutmask dot apl.washington.edu" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/105371] The result of the merge function is different when it's type of parameters  is the extensions type of derived type
Date: Wed, 27 Apr 2022 22:14:13 +0000	[thread overview]
Message-ID: <bug-105371-4-oqGfOWKnFg@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105371-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Wed, Apr 27, 2022 at 07:51:10PM +0000, anlauf at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105371
> 
> --- Comment #4 from anlauf at gcc dot gnu.org ---
> The following untested hackish patch leads to the same answer for both cases:
> 
> diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc
> index 233cc42137f..abd93956217 100644
> --- a/gcc/fortran/simplify.cc
> +++ b/gcc/fortran/simplify.cc
> @@ -4946,7 +4946,8 @@ gfc_simplify_merge (gfc_expr *tsource, gfc_expr *fsource,
> gfc_expr *mask)
>      {
>        result = gfc_copy_expr (mask->value.logical ? tsource : fsource);
>        /* Parenthesis is needed to get lower bounds of 1.  */
> -      result = gfc_get_parentheses (result);
> +      if (result->rank)
> +       result = gfc_get_parentheses (result);
>        gfc_simplify_expr (result, 1);
>        return result;
>      }
> 
> Thing is, I have to find a compiler that gives the result the reporter expects.
> E.g. Intel 2021.5 prints
> 
>            1
> 
> for both cases.
> 

Harald,  thanks for looking at this!

I don't use polymorphism in my codes.

The "class(t) :: x, y, r" declaration clearly gives x, y, r the
type type(t).  I assume that the assignments "x = t2(1,-1)" and
"y = t2(2,-2)" now change the dynamic type of x and y to type(t2).
When "r = merge(x,y,...)" is evaluated and assigned the dynamic
type of r becomes type(t2).  So, the output should be

1 -1

But, again, I'm not polymorphic.

  parent reply	other threads:[~2022-04-27 22:14 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-25  0:56 [Bug fortran/105371] New: " xudong.luo@compiler-dev.com
2022-04-25  7:03 ` [Bug fortran/105371] " schwab@linux-m68k.org
2022-04-26 18:12 ` kargl at gcc dot gnu.org
2022-04-27  9:28 ` xudong.luo@compiler-dev.com
2022-04-27 19:51 ` anlauf at gcc dot gnu.org
2022-04-27 22:14 ` sgk at troutmask dot apl.washington.edu [this message]
2022-04-28  0:10 ` xudong.luo@compiler-dev.com
2022-04-28  7:00 ` xudong.luo@compiler-dev.com
2022-10-10 19:28 ` anlauf at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105371-4-oqGfOWKnFg@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).