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: 136715 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp669578vqm; Wed, 23 Aug 2023 12:16:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGckxOL389jgN9r3MkgiSpnEVrsAeHYw+gMIcvgWf7XORsKJlIeS+cfPedqcjc6su7R0tPW X-Received: by 2002:a17:906:1c:b0:99c:bb4d:f596 with SMTP id 28-20020a170906001c00b0099cbb4df596mr11539229eja.6.1692818217720; Wed, 23 Aug 2023 12:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692818217; cv=none; d=google.com; s=arc-20160816; b=fyTX0a0XvnMSwdR/KF6IH5Cy8Qn9YbXUu7YbwB4cUR4Rjxxksg7o1o88+sRuN14zYU JCSG2k9qH+LtJUT9x5uzq+ZdGIi8m3dhnhF9e5H1WbolyLWd+16LFp1WVN3tG+esblVY lTTFw9Y3lIG+SUW5VSI1UAixa9ZfxG1jwDrZgNpr5Um0Za4FRrcPx07FPJkgP2jyTVwR 7fCjg6J9X9v6FlxjJ3yH38jZKl+XherIIkI8ox0J0v6O8NYDqnALNsUCtmPWLkg+X23F 1pkDXxMq8lTNon2hNsPj6hz6ggWOxmC4JvkRJ2AdfRj3UCUh8hiq/E1D4uu1KzQdMy9f lBJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:ui-outboundreport :sensitivity:importance:date:subject:to:message-id:mime-version :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=1K524ze2ela0/c2I6DJ9Y6kxdlKBFaOMgOUscLY7//o=; fh=QK0YdXSiSCa48e9o4Ff7k6xpBN/ax2bSUZqWzYlsl7Q=; b=v8yJrP5kDu0KvcT/aNzkjlhrPUbvNPGrNLm/xdKuqrCLzVQCux3+LPMzQK4QR4crf5 ua0yQKIaOd5k5ufk4qRLsQvztFwoEcIO91HlA7gwrrsAQN/tyUKWn89KbyD34hAhOtKD 14tXAy4wMfkhog5T4iZedbuPyqlDgtKkNKj9aXEpc3QLB/Eyr1zv7zMGC90vfgFJ5J9b WRy38McEcu7/h1exj86QY/BGy2s3ITD59kMILBBr2tD9TMJ8EBKYRnhKbIJ2CiW7pxtO BFVyMtCCeFToCQa8MkVO2WJ50sA5PIPls3XF72ncjy9CthO0GBoQqNyLm5DgydFeYU5a ucOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DreE00Xs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i13-20020a170906698d00b0099cc01fb28csi8801725ejr.780.2023.08.23.12.16.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 12:16:57 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DreE00Xs; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 945D23853D29 for ; Wed, 23 Aug 2023 19:16:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 945D23853D29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692818214; 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=DreE00XsKgtO04PacCr9KhMeCuBJZ+05BYNIrToQdivuxDsDmma1GcnEU6//k86Gp X8l5ikaum0f3e0RNyVVKquPtiV5xPNtUZqaRlT4tiZCpLcRvUKJ0GNjBYsXgxKvN4k KQg82VVZVgeGeas1Fjy5cxF1YZrBRUKNs82kgR+M= 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 L8xJQI50yXYvn47KT4gSYFUm5rCOWVqZhj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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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775048555727296892 X-GMAIL-MSGID: 1775048555727296892 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