From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 95F163857413; Thu, 28 Apr 2022 00:10:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95F163857413 From: "xudong.luo@compiler-dev.com" 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: Thu, 28 Apr 2022 00:10:00 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xudong.luo@compiler-dev.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Apr 2022 00:10:00 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105371 --- Comment #6 from luoxudong --- (In reply to Steve Kargl from comment #5) > 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=3D105371 > >=20 > > --- Comment #4 from anlauf at gcc dot gnu.org --- > > The following untested hackish patch leads to the same answer for both = cases: > >=20 > > 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 =3D gfc_copy_expr (mask->value.logical ? tsource : fsourc= e); > > /* Parenthesis is needed to get lower bounds of 1. */ > > - result =3D gfc_get_parentheses (result); > > + if (result->rank) > > + result =3D gfc_get_parentheses (result); > > gfc_simplify_expr (result, 1); > > return result; > > } > >=20 > > Thing is, I have to find a compiler that gives the result the reporter = expects. > > E.g. Intel 2021.5 prints > >=20 > > 1 > >=20 > > for both cases. > >=20 >=20 > Harald, thanks for looking at this! >=20 > I don't use polymorphism in my codes. >=20 > The "class(t) :: x, y, r" declaration clearly gives x, y, r the > type type(t). I assume that the assignments "x =3D t2(1,-1)" and > "y =3D t2(2,-2)" now change the dynamic type of x and y to type(t2). > When "r =3D merge(x,y,...)" is evaluated and assigned the dynamic > type of r becomes type(t2). So, the output should be >=20 > 1 -1 >=20 > But, again, I'm not polymorphic. (In reply to Steve Kargl from comment #5) > 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=3D105371 > >=20 > > --- Comment #4 from anlauf at gcc dot gnu.org --- > > The following untested hackish patch leads to the same answer for both = cases: > >=20 > > 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 =3D gfc_copy_expr (mask->value.logical ? tsource : fsourc= e); > > /* Parenthesis is needed to get lower bounds of 1. */ > > - result =3D gfc_get_parentheses (result); > > + if (result->rank) > > + result =3D gfc_get_parentheses (result); > > gfc_simplify_expr (result, 1); > > return result; > > } > >=20 > > Thing is, I have to find a compiler that gives the result the reporter = expects. > > E.g. Intel 2021.5 prints > >=20 > > 1 > >=20 > > for both cases. > >=20 >=20 > Harald, thanks for looking at this! >=20 > I don't use polymorphism in my codes. >=20 > The "class(t) :: x, y, r" declaration clearly gives x, y, r the > type type(t). I assume that the assignments "x =3D t2(1,-1)" and > "y =3D t2(2,-2)" now change the dynamic type of x and y to type(t2). > When "r =3D merge(x,y,...)" is evaluated and assigned the dynamic > type of r becomes type(t2). So, the output should be >=20 > 1 -1 >=20 > But, again, I'm not polymorphic. I think so,thanks a lot.=