From patchwork Thu Mar 9 18:08:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald Anlauf X-Patchwork-Id: 67065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp437245wrd; Thu, 9 Mar 2023 10:08:56 -0800 (PST) X-Google-Smtp-Source: AK7set8Ke6/DhKeT+JBVQ3H/84f4Pb80XDdHUdkCkIsD9gqtWAuz5oFIoH0u8msDwmXunpCOVzsJ X-Received: by 2002:a17:906:271a:b0:8f0:143d:ee34 with SMTP id z26-20020a170906271a00b008f0143dee34mr18997510ejc.1.1678385336097; Thu, 09 Mar 2023 10:08:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678385336; cv=none; d=google.com; s=arc-20160816; b=yznt+19F61DKfJdpJRqjynczd7jx/bZTSmU2QBLwwyuNX7gHCGyg2SA24OgQPFrnoI L5JsRy24F+LobM+RohfWwp2SkADkKlw6FwyoIP+RRpS4D1dRVyOUwJyJIn7o+N19TJ1+ 6+pTzQfok5+7z5yMP5KG6BRmB/VmJNPYPOR9SYtWrsyZ79smErji/UXCq5PfAKY8fMgA 5hdn5m1msvHZyHfZSlTfW/xhLOdh+cKAgD+j1NGW85CTPLGF4587AOKCxDhR8DmysYRZ dn1hcfeCUSQJcwZwQSZpCtCGQGLUbl3y/nnmRs61jspLUEinm6+8Uhpzl7Rv1UvI4aWy 2N4Q== 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=CkI4hT8is3fDuCfFklT84qRsM38o2H9Nl9K1xL0bac4=; b=A5sE+gMvVyAQp8ZJ0IMy17zJP/9C9r0KhlC9xBjWXnL7BBq/M0JfZKV25zV1T0XVj8 OYs4BqSflJaYneODP8E2tegTH0PAJ/h7xeFkd4FMod+aRzzAnU70Fiu4iuADDSRod03t pumGzrx/mA369E26THjIg/LvO6JGgbo7ps1FxiyairYj8/oWKJCNJs4K+raW0X/J23vq mlKytrm4vLFWyhZRJLNjP3GNyyqYUB/8Vmgaxv7bKNcB5TIA/bf9sdUdgTVVxflNtI4s dWDIyb4FPChS1ff4losrIDyk+qZyxOppxDRKqtO8BehPxcUq2ggnyAKamtfTibd1HQdO IndQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CdLFA93K; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s10-20020a1709064d8a00b008dfcc758d90si248022eju.789.2023.03.09.10.08.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 10:08:56 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=CdLFA93K; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 2A5DB385842B for ; Thu, 9 Mar 2023 18:08:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2A5DB385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678385335; bh=CkI4hT8is3fDuCfFklT84qRsM38o2H9Nl9K1xL0bac4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CdLFA93KBTeRhHpjw+lYEVcNizB6cBakqxAc5RXOe0rMSDipzU+EDO3R43956UIPv IM+KX/m8+14ysRfrc6K/WMco3QHwiha73V8JGVD7teaSDvp7HSxU4x6smgjs+WeKpT c6JB70gEOsvFBlHsS0jbEp/kTGALY4Tos30/INNI= 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.17.20]) by sourceware.org (Postfix) with ESMTPS id 685483858D20; Thu, 9 Mar 2023 18:08:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 685483858D20 X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [93.207.86.196] ([93.207.86.196]) by web-mail.gmx.net (3c-app-gmx-bap32.server.lan [172.19.172.102]) (via HTTP); Thu, 9 Mar 2023 19:08:09 +0100 MIME-Version: 1.0 Message-ID: To: fortran , gcc-patches Subject: [PATCH] Fortran: fix ICE with bind(c) in block data [PR104332] Date: Thu, 9 Mar 2023 19:08:09 +0100 Importance: normal Sensitivity: Normal X-Priority: 3 X-Provags-ID: V03:K1:zje+osVa6zhyuH+JqujqwSqTV6AcKQChtEJh6y0tJqNimVoYD6Gg9q65bKe5Z5fhUZIDO B27ojuS6nIVG4R1sUxfIZp4q8jVZGXDyGXOjW+xZqmCdm10SMv5PPTctezFamTiKugnn/AGywILN fcn4o7D3SeK3L4UMZREzyG9Ryw4b9lM37QVSqidAfV8rqiyujejHjZjaDKa8isGf9UHWxm6AFFAm Vf08XAb1WXDPCcBg/s9NB2RA1ck8zzOY2GFJ9QCiu0N9CpSv1OzIrV+7ifT2CYu6PXe2V5dcHMbr iU= UI-OutboundReport: notjunk:1;M01:P0:iwRJllJTKFk=;VIPFUmZ+z0OqMX5eHkCGlwAN2Nv f86dFBtDT5+Am4ZbuVJiZvQAEPkvrBZn/xJ6HVwTBn6594463jko+4y+lURsMDLSKsa7Yun+F UAOIWRK9ePLE6ae7K8wLzfwoLF9RpEaB56zxyzNbWwWdhuz764VjkEvYW9bdkLq0gtAwikh4a Mj7VAZpxhNT5gVRMUJIUXzMi3U8dcjxxnxhauTmGmg3FNOpeOfgicsezkVScD+kvjUsjUG4gK nhFKtmeu31JxO+9oL++JoiQ+uU6/UFiXPfOOIus30BSwbL+h+yKEFTPqwExlHge+Y7dhfrQFq hl/pL0fjEMras1ql1jJ+4NAMeH9JxAP8Xa1YYR7V+NkwesVpZNKrUj31+mmhA4SR4jiNKZY4f 46/dKO0lTQAO4LadUxTOVKPQhPjv7HlI4qdYKDKVvweJtUZbsQZMccuKCoDL9NVxHceUEtm/W Ejr9v9N/TV54qb+GrgF9r06uzKWOipDrrpHnGpmhx39+A/Peo/IkDU3vwO0Kt0KeoT9DWjphd Nj1smEVwB0vEgcDH4/s+hk1Z2E+HYTUHk5YdQEmTW8l0hdiJqjXFASITShU0ESDMDv3sZ5Db1 hYh8fUPZw3sSQAVFd0gLJXsknz3HbNPWTws4T7mx/0BxtgySO2tW9aYSUn+lq3VHbymUWK+eT 5YBt8a7dQ1vs3JGsKi5uCEG1moYTDLZd3khA0bhvXKimThkfhtCm/UZfFfbA9mNuslgGPAkGR sSsIbS61a3shueeeL9OcnLoFYa/D3k8euBva2ykSZRuumdc69CYkrNC89x8DAM64Yg2vTlXEY GBAixio0SeUsdWnv2Rty+vqg== X-Spam-Status: No, score=-12.8 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_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?1759914581911120846?= X-GMAIL-MSGID: =?utf-8?q?1759914581911120846?= Dear all, the attached almost obvious patch fixes a NULL pointer dereference in a check of a symbol with the bind(c) attribute. Regtested on x86_64-pc-linux-gnu. OK for mainline? This PR is marked as 10/11/12/13 regression, thus it should qualify for a backport. It's simple enough anyway. Thanks, Harald From ef96d7d360c088d68e3b405401bdb8b589d562f2 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Thu, 9 Mar 2023 18:59:08 +0100 Subject: [PATCH] Fortran: fix ICE with bind(c) in block data [PR104332] gcc/fortran/ChangeLog: PR fortran/104332 * resolve.cc (resolve_symbol): Avoid NULL pointer dereference while checking a symbol with the BIND(C) attribute. gcc/testsuite/ChangeLog: PR fortran/104332 * gfortran.dg/bind_c_usage_34.f90: New test. --- gcc/fortran/resolve.cc | 4 ++-- gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 2780c82c798..46585879ddc 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -15933,8 +15933,8 @@ resolve_symbol (gfc_symbol *sym) /* First, make sure the variable is declared at the module-level scope (J3/04-007, Section 15.3). */ - if (sym->ns->proc_name->attr.flavor != FL_MODULE && - sym->attr.in_common == 0) + if (!(sym->ns->proc_name && sym->ns->proc_name->attr.flavor == FL_MODULE) + && !sym->attr.in_common) { gfc_error ("Variable %qs at %L cannot be BIND(C) because it " "is neither a COMMON block nor declared at the " diff --git a/gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 b/gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 new file mode 100644 index 00000000000..40c8e9363cf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 @@ -0,0 +1,21 @@ +! { dg-do compile } +! PR fortran/104332 - ICE with bind(c) in block data +! Contributed by G. Steinmetz + +block data + bind(c) :: a ! { dg-error "cannot be BIND\\(C\\)" } +end + +block data aa + real, bind(c) :: a ! { dg-error "cannot be BIND\\(C\\)" } +end + +block data bb + real :: a ! { dg-error "cannot be BIND\\(C\\)" } + bind(c) :: a +end + +block data cc + common /a/ x + bind(c) :: /a/ +end -- 2.35.3