]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix ICE with bind(c) in block data [PR104332]
authorHarald Anlauf <anlauf@gmx.de>
Thu, 9 Mar 2023 17:59:08 +0000 (18:59 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Fri, 10 Mar 2023 17:56:13 +0000 (18:56 +0100)
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
gcc/testsuite/gfortran.dg/bind_c_usage_34.f90 [new file with mode: 0644]

index 2780c82c7983acce9a5c314ca6fa47e49df684f2..46585879ddcd98037e52f1e5bf0467964b142fb3 100644 (file)
@@ -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 (file)
index 0000000..40c8e93
--- /dev/null
@@ -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