public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6592] Fortran: fix ICE with bind(c) in block data [PR104332]
@ 2023-03-10 17:56 Harald Anlauf
0 siblings, 0 replies; only message in thread
From: Harald Anlauf @ 2023-03-10 17:56 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e20e5d9dc11b64e8eabce6803c91cb5768207083
commit r13-6592-ge20e5d9dc11b64e8eabce6803c91cb5768207083
Author: Harald Anlauf <anlauf@gmx.de>
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-03-10 17:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-10 17:56 [gcc r13-6592] Fortran: fix ICE with bind(c) in block data [PR104332] Harald Anlauf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).