From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.15.15]) by sourceware.org (Postfix) with ESMTPS id 052053858D39; Sat, 20 Aug 2022 19:11:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 052053858D39 X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [79.232.158.156] ([79.232.158.156]) by web-mail.gmx.net (3c-app-gmx-bs01.server.lan [172.19.170.50]) (via HTTP); Sat, 20 Aug 2022 21:11:20 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: fix simplification of intrinsics IBCLR and IBSET [PR106557] Content-Type: multipart/mixed; boundary=rekceb-d0aea007-0357-4165-8bff-f4b3539bcc58 Date: Sat, 20 Aug 2022 21:11:20 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:q7ENeqRps9MbWlDDmMgtNhMFWQVgwTzOjdg06QKIfj82z52zvfrlz9EkLpvUKnzZ/z0RV pK1xjn5nfyJhyoC8CEsjiqxMEqTBgxHrw5aRTDJtl1gaDVy6s5zTneSXZleGj4AnBJcJJmQQVWlb cTz+oBJPIYXUqOA7FMKQAcgfLpSYZ0qMe7T0amSABm28biS8tTkYF5rB3FOyknd7yr0iZPKGFBZ8 3W99KURhM7Bjp/gMXnALNaGvvOf602BojCSgYo2JJb5g/zCvwLjxPcjUpq77+5LnS/e95R+KXJqc gA= X-UI-Out-Filterresults: notjunk:1;V03:K0:KdS1qwQhWyk=:AmzUL63gzAxcq8OqyFCeQn WhMIUbgLl5MgN/lTmGL/UiTyJQkxUv8Wird8CskROFll/XZKh4dMR/1sHrntPujjBiOKSmFg6 bh+2eHHbWAUqVL0aXea9/7k7qF3IrDd4X7SEXP/mVv15DJmQb3LRy01aSMya3fTRQN4xdFafI MzP7UHO8d29Mzgm0vTwVxeCNw1HMqDXEx4pK4Rvb+W9x9KKSqjxpxRRim8lSv/qEfTsNwnRhW DEYZvt8EWia1AgyKc+B7WfpFJSt2DCpFkHtRrRIRmprDC1tA5f9y2prxAZmHAqlZa0KhqnNbK MCvOn2OT7FMQ7tH7D/eDWAQk9bdQqNmHqLCvWBFwp7KBS3LDLcdHbqLXStbKvCZYGncVh6NQr T1oWNcNjJHS9FtC12fhgS2kBMvctusoE1bh7OJivGA/a/Cso/O50PLgavOAYd600w2/4u4OE5 a884hjOQ09S7RWs7kNg1PY9RklTm61inEzhXnIm5SWktY0fp3BQ/Eupj5GvUv+QsuExd8fBNu 0FO2awaqU/AKZdhKDU7pjt/Lh++pQjx3QgQT1dy0GaipC3eqUJ+zyC+VOYfHP0qbAoVdziM/A sXcq/0X9dSGCl//J+Gh+8ZYLurJiMvSvgY7UalVSxJ+LZsS3O3nUYI9s99xnOtJS+9fFSvGCa xao4hKJFD1355H+TLstKYaaj5gh+sUGVVVxzkNKfsoDWh9QhgziyFMd8YP5iAlC1kthAA544J AWUcNRJIjB0P/kSogGya0ePkwrRBtH6NZkr4Gbts805lSJ/8YUM/bE9bcW4ZcUfmt6ZHQxrM/ kPsxKol X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Aug 2022 19:11:24 -0000 --rekceb-d0aea007-0357-4165-8bff-f4b3539bcc58 Content-Type: text/plain; charset=UTF-8 Dear all, the simplification of the TRANSFER intrinsic produces a redundant representation of the result, one in expr->value and another in expr->representation.string. This is done to ensure a safe "round-trip" for nested TRANSFER. In a subsequent use of this result we either need to make sure that both parts stay consistent, or drop the latter part. The simplifications of IBCLR and IBSET do a gfc_copy_expr of their argument x and modify only the former part. Depending on context, either value.integer or representation.string (if non-NULL) are used later, leading to surprising results. A conservative approach to fix this PR is to simply drop the unneeded representation.string in the simplification of the intrinsics IBCLR and IBSET, see attached patch. (A quick glance did not turn up other intrinsics affected the same way.) Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --rekceb-d0aea007-0357-4165-8bff-f4b3539bcc58 Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Fortran-fix-simplification-of-intrinsics-IBCLR-and-I.patch Content-Transfer-Encoding: quoted-printable =46rom a540a806cf02d739a408f129738252e73f03e60c Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sat, 20 Aug 2022 20:36:28 +0200 Subject: [PATCH] Fortran: fix simplification of intrinsics IBCLR and IBSET [PR106557] gcc/fortran/ChangeLog: PR fortran/106557 * simplify.cc (gfc_simplify_ibclr): Ensure consistent results of the simplification by dropping a redundant memory representation of argument x. (gfc_simplify_ibset): Likewise. gcc/testsuite/ChangeLog: PR fortran/106557 * gfortran.dg/pr106557.f90: New test. =2D-- gcc/fortran/simplify.cc | 14 ++++++++++++++ gcc/testsuite/gfortran.dg/pr106557.f90 | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr106557.f90 diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index fb725994653..f992c31e5d7 100644 =2D-- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -3380,6 +3380,13 @@ gfc_simplify_ibclr (gfc_expr *x, gfc_expr *y) k =3D gfc_validate_kind (x->ts.type, x->ts.kind, false); result =3D gfc_copy_expr (x); + /* Drop any separate memory representation of x to avoid potential + inconsistencies in result. */ + if (result->representation.string) + { + free (result->representation.string); + result->representation.string =3D NULL; + } convert_mpz_to_unsigned (result->value.integer, gfc_integer_kinds[k].bit_size); @@ -3471,6 +3478,13 @@ gfc_simplify_ibset (gfc_expr *x, gfc_expr *y) k =3D gfc_validate_kind (x->ts.type, x->ts.kind, false); result =3D gfc_copy_expr (x); + /* Drop any separate memory representation of x to avoid potential + inconsistencies in result. */ + if (result->representation.string) + { + free (result->representation.string); + result->representation.string =3D NULL; + } convert_mpz_to_unsigned (result->value.integer, gfc_integer_kinds[k].bit_size); diff --git a/gcc/testsuite/gfortran.dg/pr106557.f90 b/gcc/testsuite/gfortr= an.dg/pr106557.f90 new file mode 100644 index 00000000000..d073f3e7186 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr106557.f90 @@ -0,0 +1,19 @@ +! { dg-do run } +! { dg-additional-options "-fdump-tree-original" } +! PR fortran/106557 - nesting intrinsics ibset and transfer gives wrong r= esult + +program p + implicit none + character(1) :: s + + write(s,'(i1)') ibset (transfer (0, 0), 0) + if (s /=3D '1') stop 1 + write(s,'(i1)') ibclr (transfer (1, 0), 0) + if (s /=3D '0') stop 2 + + ! These shall be fully resolved at compile time: + if (transfer (ibset (transfer (0, 0), 0), 0) /=3D 1) stop 3 + if (transfer (ibclr (transfer (1, 0), 0), 0) /=3D 0) stop 4 +end + +! { dg-final { scan-tree-dump-times "_gfortran_stop_numeric" 2 "original"= } } =2D- 2.35.3 --rekceb-d0aea007-0357-4165-8bff-f4b3539bcc58--