https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104332

--- Comment #4 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Tue, Feb 01, 2022 at 08:04:45PM +0000, kargl at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104332
> 
> kargl at gcc dot gnu.org changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>      Ever confirmed|0                           |1
>              Status|UNCONFIRMED                 |NEW
>    Last reconfirmed|                            |2022-02-01
> 
> --- Comment #3 from kargl at gcc dot gnu.org ---
> (In reply to G. Steinmetz from comment #0)
> > Affects versions down to r8 (ifort/ifx rejects it) :
> > 
> > 
> > $ cat z1.f90
> > block data
> >    bind(c) a
> > end
> > 
> 
> This fixes the ICE by avoiding a NULL pointer dereference.
> 
> diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
> index 835a4783718..0ea68c707a0 100644
> --- a/gcc/fortran/resolve.cc
> +++ b/gcc/fortran/resolve.cc 
> @@ -15812,8 +15815,9 @@ 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 == 0)
>         {
>           gfc_error ("Variable %qs at %L cannot be BIND(C) because it "
>                      "is neither a COMMON block nor declared at the "

OK. So, the above stops the ICE, but allows the code to compile,
which is bad.  The code is invalid by C819.  From C1415, the 
BIND statement would apply to a common block.  Thus, the following
is valid code

block data
   common /a/x
   bind(c) :: /a/
end block data

Reply via email to