From: Harald Anlauf Date: Thu, 9 Mar 2023 17:59:08 +0000 (+0100) Subject: Fortran: fix ICE with bind(c) in block data [PR104332] X-Git-Tag: releases/gcc-10.5.0~237 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5cb9d8819eb9551d23f77e63cb3399115f0aab8;p=thirdparty%2Fgcc.git Fortran: fix ICE with bind(c) in block data [PR104332] gcc/fortran/ChangeLog: PR fortran/104332 * resolve.c (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. (cherry picked from commit e20e5d9dc11b64e8eabce6803c91cb5768207083) --- diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 288970deca08..98e94044e020 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -15666,8 +15666,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 000000000000..40c8e9363cff --- /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