From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 24A523858D3C; Sun, 27 Nov 2022 20:00:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 24A523858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669579237; bh=OT1KSL2g41V43d1TtTo9BpjdnKVtonaelro3hWc5Hjg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=r20J/T8zmn+m1oamLKR/eHwiQAzy/MApxJrZkCRvGj6LiTPFPIUWFFpNHYLUjnVMN qtQrXnuyQLZTYAwE+YdOID6prSB1yM7iJVB4Sl2aC9aW2d3GMg8yJHkTsu+cUcXrw6 ZtaWcsjws4nnHS4mFZf94Vqr7aWfi+GTRDcA3DcU= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/107874] merge not using all its arguments Date: Sun, 27 Nov 2022 20:00:35 +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: unknown X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: NEW 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107874 --- 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. >=20 > 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 =3D=3D EXPR_CONSTANT) { result =3D gfc_copy_expr (mask->value.logical ? tsource : fsource); /* Parenthesis is needed to get lower bounds of 1. */ result =3D 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.=