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 BA2793857731; Wed, 23 Aug 2023 19:16:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BA2793857731 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=1692818168; x=1693422968; i=anlauf@gmx.de; bh=aBc1LSKYjPP8pt/p+S0d/5sNuLaw4dDwqonvLbDiwTg=; h=X-UI-Sender-Class:From:To:Subject:Date; b=owITXzDfhjP2uciqAlvQSXitQgfrFyekPI+dgL60ibWUiKv5IueU8EpPaq2yHc5bugPAwnK L2Gk7iPIE32F4j1pWEN+mz78na1TEAEKwW7Ma6a2I7ruL8M6+iPo0jyomZWjVD/6OLnLRLesH MoNEEQh9aTW5juZ5eZu1MJIij4bJW9kDumt36z6az3+CkZeMZUyS3uSQH+ebCFxV/dQTUUy8C zHS16FhdlRtSOjpnDfJgtAKNxXmmDau+gEGaNChbH9NwRs1p2+ruddMWvlOmu9vnYi+gKdkEh 9WaitQcc77mnNk4hOW1ytOsSBvmeFl4ihEM4ONqJDfmM9CniaPGg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.84.109] ([93.207.84.109]) by web-mail.gmx.net (3c-app-gmx-bs30.server.lan [172.19.170.82]) (via HTTP); Wed, 23 Aug 2023 21:16:08 +0200 MIME-Version: 1.0 Message-ID: From: Harald Anlauf To: fortran , gcc-patches Subject: [PATCH] Fortran: improve diagnostic message for COMMON with automatic object [PR32986] Content-Type: multipart/mixed; boundary=trekuen-7528b42b-83e9-4aeb-b7e0-1b87c143527a Date: Wed, 23 Aug 2023 21:16:08 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Prov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msEj37z5q/w ZAgJ6TIxvzqN5PzEAH2N0GqfRcn3VJ4+TcOYpn6DCaQIqoU9AkRFFIDtwbmlgcqJgWb+liBiS VUDMx470c6wpOJtDSFwAxLDA== X-Spam-Status: No, score=-12.6 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_H4,RCVD_IN_MSPIKE_WL,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: --trekuen-7528b42b-83e9-4aeb-b7e0-1b87c143527a Content-Type: text/plain; charset=UTF-8 Dear all, here's a simple patch for a very old PR that suggests a more helpful error message for an automatic object in a COMMON. The patch also suppresses the less helpful old error message after the new one has been emitted. Regtested on x86_64-pc-linux-gnu. OK for mainline? Thanks, Harald --trekuen-7528b42b-83e9-4aeb-b7e0-1b87c143527a Content-Type: text/x-patch Content-Disposition: attachment; filename=pr32986.diff Content-Transfer-Encoding: quoted-printable =46rom 829c0c06fe7ba2cf3e83508b95999b884b21236d Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Wed, 23 Aug 2023 21:08:01 +0200 Subject: [PATCH] Fortran: improve diagnostic message for COMMON with autom= atic object [PR32986] gcc/fortran/ChangeLog: PR fortran/32986 * resolve.cc (is_non_constant_shape_array): Add forward declaration. (resolve_common_vars): Diagnose automatic array object in COMMON. (resolve_symbol): Prevent confusing follow-on error. gcc/testsuite/ChangeLog: PR fortran/32986 * gfortran.dg/common_28.f90: New test. =2D-- gcc/fortran/resolve.cc | 15 ++++++++++++++- gcc/testsuite/gfortran.dg/common_28.f90 | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gfortran.dg/common_28.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index ce8261d646a..1042b8c18e8 100644 =2D-- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -959,6 +959,10 @@ cleanup: } +/* Forward declaration. */ +static bool is_non_constant_shape_array (gfc_symbol *sym); + + /* Resolve common variables. */ static void resolve_common_vars (gfc_common_head *common_block, bool named_common) @@ -1007,6 +1011,15 @@ resolve_common_vars (gfc_common_head *common_block,= bool named_common) gfc_error_now ("%qs at %L cannot appear in COMMON " "[F2008:C5100]", csym->name, &csym->declared_at); + if (csym->attr.dimension && is_non_constant_shape_array (csym)) + { + gfc_error_now ("Automatic object %qs at %L cannot appear in " + "COMMON at %L", csym->name, &csym->declared_at, + &common_block->where); + /* Avoid confusing follow-on error. */ + csym->error =3D 1; + } + if (csym->ts.type !=3D BT_DERIVED) continue; @@ -16612,7 +16625,7 @@ resolve_symbol (gfc_symbol *sym) /* Resolve array specifier. Check as well some constraints on COMMON blocks. */ - check_constant =3D sym->attr.in_common && !sym->attr.pointer; + check_constant =3D sym->attr.in_common && !sym->attr.pointer && !sym->e= rror; /* Set the formal_arg_flag so that check_conflict will not throw an error for host associated variables in the specification diff --git a/gcc/testsuite/gfortran.dg/common_28.f90 b/gcc/testsuite/gfort= ran.dg/common_28.f90 new file mode 100644 index 00000000000..9b583b9948d =2D-- /dev/null +++ b/gcc/testsuite/gfortran.dg/common_28.f90 @@ -0,0 +1,7 @@ +! { dg-do compile } +! PR fortran/32986 - Improve diagnostic message for COMMON with automatic= object + +function a(n) + real :: x(n) ! { dg-error "Automatic object" } + common /c/ x ! { dg-error "cannot appear in COMMON" } +end function =2D- 2.35.3 --trekuen-7528b42b-83e9-4aeb-b7e0-1b87c143527a--