From patchwork Tue Feb 7 19:36:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 54059 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3039065wrn; Tue, 7 Feb 2023 11:37:21 -0800 (PST) X-Google-Smtp-Source: AK7set+T1rA2Zujebq6W9tM3OEJEjtMNU0GOl5jR3TE/3Gr5gLoMjUrQeD0W2xVlrJSa3byJn6Pp X-Received: by 2002:a17:906:3888:b0:7c1:765:9cfc with SMTP id q8-20020a170906388800b007c107659cfcmr140585ejd.34.1675798641173; Tue, 07 Feb 2023 11:37:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675798641; cv=none; d=google.com; s=arc-20160816; b=lepSEy6TK25LRuwDxCE1gEjc+sGOq1CFq93aChkDmWobPMTGM81Qqq2bS7bPaAto0W blinwaJmSF3Yi94YEMG/lV3q0/TSrUFxJg4JsNhlRV1ded/1K93wdWCOebnw/tb7fFR1 Tle+/dwgRd5/Dwjq26fDnzOlqCUZEoIXVuk0lGTEJyDsq9S+T/E2NhjQZcntl5wMyxIs DR/a3tacvUFOxJirbdNqvgP0piyxlviuS4dE6b4Wy6UvdvkEJyPNNS5BPHOS+ZlVb7zh yRBB54eloYep8HH4uKJfQ8rgH66iPAaVJczNeMwxO2Vm1yqNHsk5ozBZoETYe6BhFWdp HQxQ== 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=8rEW8waCrkY5lBtrylFvu3EC5uPFTGvGt0aOJ6/BVjE=; b=yvGIaAJPEuXymH0Tl0dtxecBeeK800BE61ZTgpDC8yzKuBCsbROj1MzWviO5VIy6M7 VQHchZ7YXo7XtwOG3MYPLIXWM2bnxk+6GxGhcQm/L8wi91Ks1/dUq8aepbV/hspT8c6w NOcGgXa9DXSOC6YwNffQlyQQ0ctgjHWtuWx67jvDkSuT3XQiBid8n2Bh9YvrVD5Hvkc2 nz+o3ZvNHoyRa7m1OU0ZNJqGMrxSqnhCL/h8M4QKSsdzEJ7/QgKpt5Haq+xz+TorDhp+ ERxElTwwcDde3o7BUdwsSaDMk4sfqcfsmsAerg/LOQrhfFOvQ/R9U5nX9UOl8d+zwGxa JkGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UfyqjKHW; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 7-20020a170906014700b00888c44d9d8dsi22010443ejh.898.2023.02.07.11.37.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Feb 2023 11:37:21 -0800 (PST) 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=UfyqjKHW; 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 016193858D38 for ; Tue, 7 Feb 2023 19:37:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 016193858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675798640; bh=8rEW8waCrkY5lBtrylFvu3EC5uPFTGvGt0aOJ6/BVjE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UfyqjKHWbuKIaPauAPE0mW2ky7xfulqvjjvPranKiKPjXE0a5jo1OVMY490HsN1kF Ir55U9KDSbu+uEqRSj+S36VcvBIIhFp+uRs39Xu8qrQkrZp/oGfaoDyyPx736rpI1D eS8f8X4WHy8qo+U0oNE88e0SU3T8Adv6o0/ElTdg= 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 988D23858D33; Tue, 7 Feb 2023 19:36:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 988D23858D33 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.88.147] ([93.207.88.147]) by web-mail.gmx.net (3c-app-gmx-bs54.server.lan [172.19.170.138]) (via HTTP); Tue, 7 Feb 2023 20:36:33 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: error handling of global entity appearing in COMMON block [PR103259] Date: Tue, 7 Feb 2023 20:36:33 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:1uDHZnectvFItJa3cuY/sgGywx3LqhYNoFlVsrrqnHo8znbaOI73OrQ65GGn15wZ+2Cdy NSQ1pkI7gaQmUVwV3xkDgm2VlgvRUt76Fe2cQcAlBEF4eXS6hGzT97vEfqgo8ODdGc+LIvq6ZEUf UNgtKfdE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No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_STOCKGEN, 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 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757202236296364466?= X-GMAIL-MSGID: =?utf-8?q?1757202236296364466?= Dear all, the attached trivial patch by Steve fixes a NULL pointer dereference that occurs when an error shall be emitted for a global entity that conflicts with a symbol appearing in a COMMON block, but the symbol's location is not set. This may happen e.g. in the testcase in the PR, where the COMMON variables are imported from a module. Regtested on x86_64-pc-linux-gnu with no failures. I intend to commit as obvious within 24h unless there are comments. Thanks, Harald From 1c225608e0cabbe909cc4d6e69fb0281bb99418f Mon Sep 17 00:00:00 2001 From: Steve Kargl Date: Tue, 7 Feb 2023 20:18:42 +0100 Subject: [PATCH] Fortran: error handling of global entity appearing in COMMON block [PR103259] gcc/fortran/ChangeLog: PR fortran/103259 * resolve.cc (resolve_common_vars): Avoid NULL pointer dereference when a symbol's location is not set. gcc/testsuite/ChangeLog: PR fortran/103259 * gfortran.dg/pr103259.f90: New test. --- gcc/fortran/resolve.cc | 12 +++++++++--- gcc/testsuite/gfortran.dg/pr103259.f90 | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/pr103259.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 100b2382e22..549916c2b53 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -953,9 +953,15 @@ resolve_common_vars (gfc_common_head *common_block, bool named_common) { gsym = gfc_find_gsymbol (gfc_gsym_root, csym->name); if (gsym && (gsym->type == GSYM_MODULE || gsym->type == GSYM_PROGRAM)) - gfc_error_now ("Global entity %qs at %L cannot appear in a " - "COMMON block at %L", gsym->name, - &gsym->where, &csym->common_block->where); + { + if (csym->common_block) + gfc_error_now ("Global entity %qs at %L cannot appear in a " + "COMMON block at %L", gsym->name, + &gsym->where, &csym->common_block->where); + else + gfc_error_now ("Global entity %qs at %L cannot appear in a " + "COMMON block", gsym->name, &gsym->where); + } /* gfc_add_in_common may have been called before, but the reported errors have been ignored to continue parsing. diff --git a/gcc/testsuite/gfortran.dg/pr103259.f90 b/gcc/testsuite/gfortran.dg/pr103259.f90 new file mode 100644 index 00000000000..f78ff26180e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr103259.f90 @@ -0,0 +1,11 @@ +! { dg-do compile } +! PR fortran/103259 - ICE in resolve_common_vars +! Contributed by G.Steinmetz + +module m + integer :: p + common /c/ p +end +program p ! { dg-error "cannot appear in a COMMON block" } + use m ! { dg-error "is also the name of the current program unit" } +end -- 2.35.3