From patchwork Wed Aug 23 19:16:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 1824907 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=A3eKSy3m; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RWGD13BP0z1yZs for ; Thu, 24 Aug 2023 05:16:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 50E91385414F for ; Wed, 23 Aug 2023 19:16:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 50E91385414F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692818191; bh=1K524ze2ela0/c2I6DJ9Y6kxdlKBFaOMgOUscLY7//o=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=A3eKSy3m4v0YUPr6v10OBNi/b1ydCsPTjxEqlmwqw9tpSdnBOCjSgT3Z3Me76ADfo nheALVCRkbxZvO5gjasXM4baw00YvD/0Gd9wbu1O99Igt12pWOUoGggJRxRsfRyvCH +k5Wadqh1yKfCRaOdsWxYYa8Jg2NfdVqHqpUMiR8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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: To: fortran , gcc-patches Subject: [PATCH] Fortran: improve diagnostic message for COMMON with automatic object [PR32986] Date: Wed, 23 Aug 2023 21:16:08 +0200 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:GMHfACnYW25AxX7hK9H0kpRf92bZhti5yn0TNsujA4l3TkcRE7uZx3vOKh5z2EjcGcQYw L8xJQI50yXYvn47KT4gSYFUm5rCOWVqZhj1jrW+KjnmPsQv6w2EajvFxk211D48cqG79HHIsuqrP jwUSpywImuR48ASsPAgqZYed4GDmXcSDPN2h+THWyuFPooIpTKMESmYPA2MCGeGNv2cupey/o4F0 qjP4Ho3QwfkBaWaooT5bEwmc2b98CvMmOYIrWxG1sHxAQ/z33RG35ARgRQ95bBW47hjaNAaTHPS2 ps= UI-OutboundReport: notjunk:1;M01:P0:2s8VP353ufw=;xROMmRXnkotGRVRe6Njax4ajzr9 //r2J4iXKW9uLsFasgwsAsHVjWS18+K14sFCYZ6WLWQ5fGNwtg1e3SGK03gQfWqph2Z9XCQVi /W7A2aO12NDEv9a3NLOBb+dScyyHqIFT96A1RXNSxjnNKSjNvnPOVlXXtS41+WAqivyCsftcT LHh3QBWK3U+b4LqX+aTJ0m/NfgfHmlNlDf/CryC/EnBG6Yt2YWDBwaZNsNwMp+qbuql0EQkmc vLCSl86F4MWireNiSlaUMxr3C/7va1aR4yJNEU3b4ic8t31SHRJgAgjEmTo4rgTT84GOIwP9t V7b5ork4hG6AKM925Yhsqbizyozxwk2yXC2Cf4SiNz9dHDenIGtTvOCUIls8St/9xddSlMxxQ 0rj83mhzygGUlQBKiQza+7N1Tsi/Km0jXwM8Sc2XwCQQM59131px01uc+gsVmWw/yTbminWsu cxrhbIWTqGWnjgFafhRfVdhvS37Ol4JXJrWL4TSfac66fl2CIuS+IRQk5O/v3T86jk22JNZjb hi2lXNxijfX5SUYIfNNvbd87W+sbb297EnaI/EwNN+4GhTtYpidjJ65cAs8K1MnC/On/jln8m knpjzFbgmBxOGIlcQMeM7PMKiCSGN6NAuhm9ytxmIJC9vCMAVTAUx3BFL4IC8YFrJ7WV38vLm 6LlZqPC9WGmNW5X56+Yc5+AGXO1EmtKckxFqSqc7DR5VmMPwh5v1T+m56G02t4msEj37z5q/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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harald Anlauf via Gcc-patches From: Harald Anlauf Reply-To: Harald Anlauf Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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 From 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 automatic 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. --- 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 --- 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 = 1; + } + if (csym->ts.type != 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 = sym->attr.in_common && !sym->attr.pointer; + check_constant = sym->attr.in_common && !sym->attr.pointer && !sym->error; /* 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/gfortran.dg/common_28.f90 new file mode 100644 index 00000000000..9b583b9948d --- /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 -- 2.35.3