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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #3 from anlauf at gcc dot gnu.org ---
I am wondering why we simply warn in check_against_globals, instead of emitting
an error:

5832      buf[0] = 0;
5833      gfc_compare_interfaces (sym, def_sym, sym->name, 0, 1, buf,
sizeof(buf),
5834                              NULL, NULL, NULL);
5835      if (buf[0] != 0)
5836        {
5837          gfc_warning (0, "%s between %L and %L", buf,
&def_sym->declared_at,
5838                       &sym->declared_at);
5839          sym->error = 1;
5840          def_sym->error = 1;
5841        }

There is also the question why we handle interface checks differently for
bind(c) the way we do now.  If I e.g. revert commit r0-127463, which
added one line in resolve_global_procedure:

2612      if ((sym->attr.if_source == IFSRC_UNKNOWN
2613           || sym->attr.if_source == IFSRC_IFBODY)
2614          && gsym->type != GSYM_UNKNOWN
2615          && !gsym->binding_label       <=== this one here!
2616          && gsym->ns
2617          && gsym->ns->proc_name
2618          && not_in_recursive (sym, gsym->ns)
2619          && not_entry_self_reference (sym, gsym->ns))
2620        {

to disable the global interface check for bind(c), the ICE goes away.
(However, we then regress on gfortran.dg/bind_c_procs_2.f90).

Hackish fix (not regtested):

diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 612c12d233d..41adfe5b715 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5834,8 +5834,12 @@ check_against_globals (gfc_symbol *sym)
                          NULL, NULL, NULL);
   if (buf[0] != 0)
     {
-      gfc_warning (0, "%s between %L and %L", buf, &def_sym->declared_at,
+      if (sym->binding_label)
+       gfc_error ("%s between %L and %L", buf, &def_sym->declared_at,
                   &sym->declared_at);
+      else
+       gfc_warning (0, "%s between %L and %L", buf, &def_sym->declared_at,
+                    &sym->declared_at);
       sym->error = 1;
       def_sym->error = 1;
     }

There is another issue in that we do not detect that

function f() result(n) bind(c)
   class(*), allocatable :: n
end

is likely illegal, i.e. not interoperable.  Intel says:

pr95375.f90(1): error #8522: A result variable of a BIND(C) procedure cannot
have either the ALLOCATABLE or the POINTER attribute.   [F]
function f() result(n) bind(c)
---------^
pr95375.f90(1): error #8624: The result variable of an interoperable function
must itself be interoperable; derived type must be declared with BIND(C).   [F]
function f() result(n) bind(c)
---------^
compilation aborted for pr95375.f90 (code 1)

This should be tracked elsewhere.

Reply via email to