From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 33A693858C50; Sun, 27 Nov 2022 21:07:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 33A693858C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669583231; bh=vTrvtgOGmIMC70/AaL7xqBu3qdv+NTIw1594j1Wzfwo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ykyd1M1qay/uidmo7ENGEENXB6xFHyvlFjnELYfGGNFEVQ0C2jLmh4NZ2ts/kNbo4 S9+rcanlnkq7Go8jh7jJxjTZi4xpvWu8peh22pyJJ5N5erBxx2JEJE33pwbgts3GL9 RHXxgJJdQF3PSXTpApHB2NcfaJs6NNxtl/tmubTk= 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 21:07:10 +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 #4 from anlauf at gcc dot gnu.org --- The following patch fixes comment#3: diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index 9c2fea8c5f2..2f69c4369ab 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -4913,6 +4914,11 @@ gfc_simplify_merge (gfc_expr *tsource, gfc_expr *fsource, gfc_expr *mask) if (mask->expr_type =3D=3D EXPR_CONSTANT) { + /* The standard requires evaluation of all function arguments. + Simplify only when TSOURCE, FSOURCE are constant expressions. */ + if (!gfc_is_constant_expr (tsource) || !gfc_is_constant_expr (fsourc= e)) + return NULL; + 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); This leads to a "regression" for gfortran.dg/merge_init_expr_2.f90, which is due to the pattern matching the old, faulty simplification result. That's trivial to fix, though.=