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 9C3F3392AC30; Tue, 15 Nov 2022 20:45:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C3F3392AC30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1668545104; bh=5Yu+G/gN2cRHi5HlcWzGrj7c2UwntnnOf/VGFEkbgAE=; h=X-UI-Sender-Class:From:To:Subject:Date; b=skcrDDOVtdkIRYpkibujNL1jNsnRQJj+WsstY63eTGqwh+9xNLf+3SpLdSfA0rBFW AeXNHglvcV9gYpLX5X58kqU8R7wi8g5gLJwZStR/sLgPRpKrvybUU6uvbFZmVwP1uD DaKzSENb4Nl0CsbKFLvAARjTGTNor0JhGAYaulvOlWFBvxTGcaoXDUqu5RVjKI37WS KJEVWyUG8J0yMHVe2yD0VEAvW3C9/jTNY8iz1/+LMSrVVspHZjHBJIZJJ3ZO43ulGQ 00cll/7f/R/crm4owDQtUKXCmbLZtkpZUNx7BsEzhmrbrXk0eqY5n6LeOWDsuT9B3I sNpbP668Dt82Q== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.83.65] ([93.207.83.65]) by web-mail.gmx.net (3c-app-gmx-bs61.server.lan [172.19.170.145]) (via HTTP); Tue, 15 Nov 2022 21:45:04 +0100 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: ICE in simplification of array expression involving power [PR107680] Content-Type: multipart/mixed; boundary=refeik-78b1d8d0-32dd-4667-8700-aa299efee834 Date: Tue, 15 Nov 2022 21:45:04 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:b2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RV3jwX+8WNmniugixFu+uC3dqsN bLHqYT+1CnZMgwvwJyqf/tFEwbhhueA5XYjvUmShG5FRqEi55mgBr7NBfjqHg7bWVkpHgaPUv IoFzMi7/x4iAICth0eSshUOQ== X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --refeik-78b1d8d0-32dd-4667-8700-aa299efee834 Content-Type: text/plain; charset=UTF-8 Dear all, when constant expressions involve parentheses, array constructors, typespecs, and the power operator (**), we could fail with an ICE during simplification in arith_power. Debugging of the testcase showed we call the proper type conversions needed for the arithmetic operation, but under certain circumstances we seem to lose the typespec on the way to the invocation of the simplification. We then run into unhandled combinations of operand types. The attached patch is likely a sort of a band-aid to the problem: we check the operand types in arith_power, and if we see that a conversion is (still) needed, we punt and defer the simplification. AFAICT this is safe. It does not address a possibly deeply covered issue in gfortran, which was suspected when analyzing pr107000. But as this is elusive, that may be hard to locate and fix. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --refeik-78b1d8d0-32dd-4667-8700-aa299efee834 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr107680.diff Content-Transfer-Encoding: quoted-printable =46rom efe9dafabc2e2cc2dab079dfa3be3d09b3471c0f Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 15 Nov 2022 21:20:20 +0100 Subject: [PATCH] Fortran: ICE in simplification of array expression involv= ing power [PR107680] gcc/fortran/ChangeLog: PR fortran/107680 * arith.cc (arith_power): Check that operands are properly converted before attempting to simplify. gcc/testsuite/ChangeLog: PR fortran/107680 * gfortran.dg/pr107680.f90: New test. =2D-- gcc/fortran/arith.cc | 7 ++++++ gcc/testsuite/gfortran.dg/pr107680.f90 | 34 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr107680.f90 diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc index fc9224ebc5c..c4ab75b401c 100644 =2D-- a/gcc/fortran/arith.cc +++ b/gcc/fortran/arith.cc @@ -845,6 +845,13 @@ arith_power (gfc_expr *op1, gfc_expr *op2, gfc_expr *= *resultp) if (!gfc_numeric_ts (&op1->ts) || !gfc_numeric_ts (&op2->ts)) return ARITH_INVALID_TYPE; + /* The result type is derived from op1 and must be compatible with the + result of the simplification. Otherwise postpone simplification unt= il + after operand conversions usually done by gfc_type_convert_binary. = */ + if ((op1->ts.type =3D=3D BT_INTEGER && op2->ts.type !=3D BT_INTEGER) + || (op1->ts.type =3D=3D BT_REAL && op2->ts.type =3D=3D BT_COMPLEX)) + return ARITH_NOT_REDUCED; + rc =3D ARITH_OK; result =3D gfc_get_constant_expr (op1->ts.type, op1->ts.kind, &op1->whe= re); diff --git a/gcc/testsuite/gfortran.dg/pr107680.f90 b/gcc/testsuite/gfortr= an.dg/pr107680.f90 new file mode 100644 index 00000000000..4ed431eb06f =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107680.f90 @@ -0,0 +1,34 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! PR fortran/107680 - ICE in arith_power +! Contributed by G.Steinmetz + +program p + real, parameter :: x(*) =3D [real :: ([1])] ** 2.0 + complex, parameter :: y(*) =3D [real :: ([1])] ** (2.0,1.0) + complex, parameter :: z(*) =3D [complex :: ([1])] ** (2.0,1.0) + complex, parameter :: u(*) =3D [complex :: ([1.0])] ** (2.0,1.0) + complex, parameter :: v(*) =3D [real :: ([(1.0,2.0)])] ** (3.0,1.0) + complex, parameter :: w(*) =3D [integer :: ([(1.0,2.0)])] ** (3.0,1.0) + print *, [real :: ([3])] ** 2 + print *, [real :: ([3])] ** 2.0 + print *, [real :: ([1])] ** (1.0,2.0) + print *, [real :: ([1.0])] ** (1.0,2.0) + print *, [complex :: ([3])] ** 2 + print *, [complex :: ([3])] ** 2.0 + print *, [complex :: ([1])] ** (1.0,2.0) + print *, [complex :: ([1.0])] ** (1.0,2.0) + print *, [integer :: ([3.0])] ** 2 + print *, [integer :: ([3.0])] ** 2.0 + print *, [integer :: ([1.0])] ** (1.0,2.0) + print *, [integer :: ([(1.0,2.0)])] ** (3.0,1.0) + print *, v(1) + if (u(1) /=3D 1) stop 1 + if (v(1) /=3D 1) stop 2 + if (w(1) /=3D 1) stop 3 + if (x(1) /=3D 1) stop 4 + if (y(1) /=3D 1) stop 5 + if (z(1) /=3D 1) stop 6 +end + +! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } } =2D- 2.35.3 --refeik-78b1d8d0-32dd-4667-8700-aa299efee834--