From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2071) id BE3BE3858D32; Fri, 10 Mar 2023 17:56:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE3BE3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678471001; bh=NSgIUIu2ckYd00LYYXP9kBlPOyZmQ8F1WiZkb6iKYW8=; h=From:To:Subject:Date:From; b=cNwkVQZ8UqJwZFPfXx8wXkSHOkqAZWiPOYpZ/66M19T0hopMSBqEubZmsJ5CBDqj1 9GHoeLioL4q+YwAEEqewUOZrsH0fmBRufghbE+G18hBPJkDA5igiQP9GUthEyG99OT 1UsSL5q4l8AV/SRcd4o+cdD4ykZ9m8MrTjR0HZZs= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Harald Anlauf To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-6592] Fortran: fix ICE with bind(c) in block data [PR104332] X-Act-Checkin: gcc X-Git-Author: Harald Anlauf X-Git-Refname: refs/heads/master X-Git-Oldrev: fcbc5c190c40b51c82f827830ce403c07d628960 X-Git-Newrev: e20e5d9dc11b64e8eabce6803c91cb5768207083 Message-Id: <20230310175641.BE3BE3858D32@sourceware.org> Date: Fri, 10 Mar 2023 17:56:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e20e5d9dc11b64e8eabce6803c91cb5768207083 commit r13-6592-ge20e5d9dc11b64e8eabce6803c91cb5768207083 Author: Harald Anlauf Date: Thu Mar 9 18:59:08 2023 +0100 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. Diff: --- gcc/fortran/resolve.cc | 4 ++-- gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) 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