From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by sourceware.org (Postfix) with ESMTPS id F30C53857365; Wed, 5 Oct 2022 21:40:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F30C53857365 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.net; s=badeba3b8450; t=1665006052; bh=5T9IK8K99dwmuMZ7zwUZ3bDhX6O9JBUxT/Vb7lqruhs=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=U/qQ6NhWtXINc+AvdRGkQDnbY47UoCj65IaeoSRCEsqkw0IE0u6tyIpoZWAPgsuFk uhfb5GaA9vGvSTgeQjhidVkprBJNxwKxEWxGUcA9G+JwXVFOltq6W1MqsDijiT6Hk5 oDnbxvPMUi4Fc5SCW3niJBF6jWeeWFgowhfzRMuI= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [93.207.82.38] ([93.207.82.38]) by web-mail.gmx.net (3c-app-gmx-bap28.server.lan [172.19.172.98]) (via HTTP); Wed, 5 Oct 2022 23:40:52 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: Mikael Morin Cc: fortran , gcc-patches Subject: Re: [PATCH, v2] Fortran: error recovery for invalid types in array constructors [PR107000] Content-Type: multipart/mixed; boundary=refeik-fe8c3f16-7f9c-4474-bb54-025557476bd0 Date: Wed, 5 Oct 2022 23:40:52 +0200 Importance: normal Sensitivity: Normal In-Reply-To: References: <1bf3b7b5-39ac-0c94-256c-f739a4746a7b@orange.fr> X-UI-Message-Type: mail X-Priority: 3 X-Provags-ID: V03:K1:qpGO7jO5rsQGyQyoMmNF12H9CqzQWulaGUbvKIuR231J3ocZJAgOnqYx/+a+IJD4a1JYu AzxPFG5x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ts+yxdw9AD5xXRdu5UvV+PcY vle8nN2KeBALgk0VBEIrFbfuE1MEoS+wPoTvjAheyZCkBHyaQvtkGEJSwdh6BffHgtAgFCy69 CABxHKh8WMdfhaSHn2I/OS0mbUx+BO9mqEbLc8T/OMRNpmSbi1asCiRn17ZPj4GKHoCdThZJB SRKc+BpcN05Lai+wmh+qrbzanwU0S3JMSsP4NX8gdLaCBooTYzObZ9hCp2IYZ2JRiQxquatbK ru8PI4BQ+uujCaNWtHjdPjxnOy7QouZfqt42mgNNxZuRhgUHhJDetG8S8s2e9RJxguxwTD5H4 jxFm8O+dWRgKsG/HDyMQwGq5aLCmn59k8TCSLlQROX9gHb2irxeecvwk9rwmJBnUYt4dglETB 7GkdSlh57xq86aUm/9W/dFRqZP1PHqgrudDE222Rs+Ol5tJFwnCBnun39tvne7NVA4EIU0wSA CLBQ+yjDQYcDJOgqj3HNv9hrDsxuNcRis3he97Vv+Wi2j7hVaUG0WDrUdro1Bb9kl3F8lmzja 2dEbGG99 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,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-fe8c3f16-7f9c-4474-bb54-025557476bd0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Mikael, > Gesendet: Mittwoch, 05. Oktober 2022 um 11:23 Uhr > Von: "Mikael Morin" > An: "Harald Anlauf" , "fortran" , "g= cc-patches" > Betreff: Re: [PATCH] Fortran: error recovery for invalid types in array = constructors [PR107000] > The following does. > > > diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc > index e6e35ef3c42..2c57c796270 100644 > --- a/gcc/fortran/arith.cc > +++ b/gcc/fortran/arith.cc > @@ -1443,7 +1443,7 @@ reduce_binary_aa (arith (*eval) (gfc_expr *, > gfc_expr *, gfc_expr **), > gfc_replace_expr (c->expr, r); > } > > - if (c || d) > + if (rc =3D=3D ARITH_OK && (c || d)) > rc =3D ARITH_INCOMMENSURATE; > > if (rc !=3D ARITH_OK) that's great! It fixes several rather weird cases. (There is at least another PR on the incommensurate arrays, but we should not attempt to fix everything today.) > There is one last thing that I'm dissatisfied with. > The handling of unknown types should be moved to reduce_binary, because > the dispatching in reduce_binary doesn't handle EXPR_OP, so even if > either or both operands are scalar, they are handled by the (array vs > array) reduce_binary_aa function. That's confusing. Do you have an example? Anyway, please find attached an updated patch that incorporates your two changes and regtests fine on x86_64-pc-linux-gnu. Even if you disagree, I think this is really a significant step forwards... (error-recovery wise). OK for mainline? Thanks, Harald --refeik-fe8c3f16-7f9c-4474-bb54-025557476bd0 Content-Type: text/x-patch Content-Disposition: attachment; filename=pr107000-v2.diff Content-Transfer-Encoding: quoted-printable =46rom 1b40214b2b538ec176ff6c118770e6e1cc8796ae Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Tue, 4 Oct 2022 23:04:06 +0200 Subject: [PATCH] Fortran: error recovery for invalid types in array constructors [PR107000] gcc/fortran/ChangeLog: PR fortran/107000 * arith.cc (gfc_arith_error): Define error message for ARITH_INVALID_TYPE. (reduce_unary): Catch arithmetic expressions with invalid type. (reduce_binary_ac): Likewise. (reduce_binary_ca): Likewise. (reduce_binary_aa): Likewise. (eval_intrinsic): Likewise. (gfc_real2complex): Source expression must be of type REAL. * gfortran.h (enum arith): Add ARITH_INVALID_TYPE. gcc/testsuite/ChangeLog: PR fortran/107000 * gfortran.dg/pr107000.f90: New test. Co-authored-by: Mikael Morin =2D-- gcc/fortran/arith.cc | 23 +++++++++++- gcc/fortran/gfortran.h | 2 +- gcc/testsuite/gfortran.dg/pr107000.f90 | 50 ++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr107000.f90 diff --git a/gcc/fortran/arith.cc b/gcc/fortran/arith.cc index d57059a375f..2c57c796270 100644 =2D-- a/gcc/fortran/arith.cc +++ b/gcc/fortran/arith.cc @@ -118,6 +118,9 @@ gfc_arith_error (arith code) case ARITH_WRONGCONCAT: p =3D G_("Illegal type in character concatenation at %L"); break; + case ARITH_INVALID_TYPE: + p =3D G_("Invalid type in arithmetic operation at %L"); + break; default: gfc_internal_error ("gfc_arith_error(): Bad error code"); @@ -1261,6 +1264,9 @@ reduce_unary (arith (*eval) (gfc_expr *, gfc_expr **= ), gfc_expr *op, gfc_expr *r; arith rc; + if (op->expr_type =3D=3D EXPR_OP && op->ts.type =3D=3D BT_UNKNOWN) + return ARITH_INVALID_TYPE; + if (op->expr_type =3D=3D EXPR_CONSTANT) return eval (op, result); @@ -1302,6 +1308,9 @@ reduce_binary_ac (arith (*eval) (gfc_expr *, gfc_exp= r *, gfc_expr **), gfc_expr *r; arith rc =3D ARITH_OK; + if (op1->expr_type =3D=3D EXPR_OP && op1->ts.type =3D=3D BT_UNKNOWN) + return ARITH_INVALID_TYPE; + head =3D gfc_constructor_copy (op1->value.constructor); for (c =3D gfc_constructor_first (head); c; c =3D gfc_constructor_next = (c)) { @@ -1354,6 +1363,9 @@ reduce_binary_ca (arith (*eval) (gfc_expr *, gfc_exp= r *, gfc_expr **), gfc_expr *r; arith rc =3D ARITH_OK; + if (op2->expr_type =3D=3D EXPR_OP && op2->ts.type =3D=3D BT_UNKNOWN) + return ARITH_INVALID_TYPE; + head =3D gfc_constructor_copy (op2->value.constructor); for (c =3D gfc_constructor_first (head); c; c =3D gfc_constructor_next = (c)) { @@ -1414,6 +1426,10 @@ reduce_binary_aa (arith (*eval) (gfc_expr *, gfc_ex= pr *, gfc_expr **), if (!gfc_check_conformance (op1, op2, _("elemental binary operation"))) return ARITH_INCOMMENSURATE; + if ((op1->expr_type =3D=3D EXPR_OP && op1->ts.type =3D=3D BT_UNKNOWN) + || (op2->expr_type =3D=3D EXPR_OP && op2->ts.type =3D=3D BT_UNKNOWN= )) + return ARITH_INVALID_TYPE; + head =3D gfc_constructor_copy (op1->value.constructor); for (c =3D gfc_constructor_first (head), d =3D gfc_constructor_first (op2->value.constructor); @@ -1427,7 +1443,7 @@ reduce_binary_aa (arith (*eval) (gfc_expr *, gfc_exp= r *, gfc_expr **), gfc_replace_expr (c->expr, r); } - if (c || d) + if (rc =3D=3D ARITH_OK && (c || d)) rc =3D ARITH_INCOMMENSURATE; if (rc !=3D ARITH_OK) @@ -1638,6 +1654,8 @@ eval_intrinsic (gfc_intrinsic_op op, else rc =3D reduce_binary (eval.f3, op1, op2, &result); + if (rc =3D=3D ARITH_INVALID_TYPE) + goto runtime; /* Something went wrong. */ if (op =3D=3D INTRINSIC_POWER && rc =3D=3D ARITH_PROHIBIT) @@ -2238,6 +2256,9 @@ gfc_real2complex (gfc_expr *src, int kind) arith rc; bool did_warn =3D false; + if (src->ts.type !=3D BT_REAL) + return NULL; + result =3D gfc_get_constant_expr (BT_COMPLEX, kind, &src->where); mpc_set_fr (result->value.complex, src->value.real, GFC_MPC_RND_MODE); diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 608dda4bf55..10bb098d136 100644 =2D-- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -226,7 +226,7 @@ enum gfc_intrinsic_op enum arith { ARITH_OK =3D 1, ARITH_OVERFLOW, ARITH_UNDERFLOW, ARITH_NAN, ARITH_DIV0, ARITH_INCOMMENSURATE, ARITH_ASYMMETRIC, ARITH_PROHIBIT, - ARITH_WRONGCONCAT + ARITH_WRONGCONCAT, ARITH_INVALID_TYPE }; /* Statements. */ diff --git a/gcc/testsuite/gfortran.dg/pr107000.f90 b/gcc/testsuite/gfortr= an.dg/pr107000.f90 new file mode 100644 index 00000000000..30289078c57 =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr107000.f90 @@ -0,0 +1,50 @@ +! { dg-do compile } +! PR fortran/107000 - ICE in gfc_real2complex, reduce_unary, reduce_binar= y_* +! Contributed by G.Steinmetz + +program p + real :: y(1) + complex :: x(1) + x =3D (1.0, 2.0) * [real :: -'1'] ! { dg-error "Operand of unary num= eric operator" } + x =3D (1.0, 2.0) * [complex :: +'1'] ! { dg-error "Operand of unary num= eric operator" } + x =3D [complex :: -'1'] * (1.0, 2.0) ! { dg-error "Operand of unary num= eric operator" } + y =3D [complex :: -'1'] * 2 ! { dg-error "Operand of unary num= eric operator" } + y =3D 2 * [complex :: -'1'] ! { dg-error "Operand of unary num= eric operator" } + y =3D 2 * [complex :: -(.true.)] ! { dg-error "Operand of unary num= eric operator" } + y =3D [complex :: -(.true.)] * 2 ! { dg-error "Operand of unary num= eric operator" } + print *, - [real :: -'1' ] ! { dg-error "Operand of unary numer= ic operator" } + print *, - [real :: [-'1']] ! { dg-error "Operand of unary numer= ic operator" } + print *, - [real :: +(.true.) ] ! { dg-error "Operand of unary numer= ic operator" } + print *, - [real :: [+(.true.)]] ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [real :: -'1' ] ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [real :: (-'1')] ! { dg-error "Operand of unary numer= ic operator" } + print *, [real :: -'1' ] * 2 ! { dg-error "Operand of unary numer= ic operator" } + print *, [real :: (-'1')] * 2 ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [integer :: -('1')] ! { dg-error "Operand of unary numer= ic operator" } + print *, [integer :: -('1')] * 2 ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [real :: 0, (-'1')] ! { dg-error "Operand of unary numer= ic operator" } + print *, [real :: 0, (-'1')] * 2 ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [real :: 0, -'1'] ! { dg-error "Operand of unary numer= ic operator" } + print *, [real :: 0, -'1'] * 2 ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [real :: 0, 1+'1'] ! { dg-error "Operands of binary num= eric operator" } + print *, [real :: 0, 1+'1'] * 2 ! { dg-error "Operands of binary num= eric operator" } + print *, [real :: 1, +(.true.)] ! { dg-error "Operand of unary numer= ic operator" } + print *, [real :: 1, -(.true.)] ! { dg-error "Operand of unary numer= ic operator" } + print *, 2 * [real :: 1, +(.true.)] ! { dg-error "Operand of unary= numeric operator" } + print *, [real :: 1, +(.true.)] * 2 ! { dg-error "Operand of unary= numeric operator" } + print *, [1, 2] * [real :: 1, +(.true.)] ! { dg-error "Operand of unary= numeric operator" } + print *, [real :: 1, +(.true.)] * [1, 2] ! { dg-error "Operand of unary= numeric operator" } + print *, [real :: 1, 2] * [real :: 1, +(.true.)] ! { dg-error "Operand = of unary numeric operator" } + print *, [real :: 1, +(.true.)] * [real :: 1, 2] ! { dg-error "Operand = of unary numeric operator" } + print *, [real :: 0, -'1'] * [real :: 1, +(+(.true.))] ! { dg-error "Op= erand of unary numeric operator" } + print *, [real :: 1, [(+(.true.))]] * [real :: 0, [(-'1')]] ! { dg-erro= r "Operand of unary numeric operator" } + + ! Legal: + print *, 2 * [real :: 1, [2], 3] + print *, [real :: 1, [2], 3] * 2 + print *, [real :: 1, [2], 3] * [real :: 1, [2], 3] + print *, [real :: 1, [2], 3] * [integer :: 1, [2], 3] + print *, [real :: 1, [2], 3] * [1, [2], 3] + print *, [real :: 1, huge(2.0)] * [real :: 1, real(1.0)] + print *, [real :: 1, -(huge(2.0))] * [real :: 1, +(real(1))] +end =2D- 2.35.3 --refeik-fe8c3f16-7f9c-4474-bb54-025557476bd0--