On Mon, Apr 13, 2020 at 10:20 AM Thomas Koenig via Fortran
<fort...@gcc.gnu.org> wrote:
>
> Hello world,
>
> the attached patch fixes an ICE on invalid: When the return type of
> a function was misdeclared with a wrong rank, we issued a warning,
> but not an error (unless with -pedantic); later on, an ICE ensued.
>
> Nothing good can come from wrongly declaring a function type
> (considering the ABI), so I changed that into a hard error.
>
> OK for trunk?
>
> Regards
>
>         Thomas
>
> 2020-04-13  Thomas Koenig  <tkoe...@gcc.gnu.org>
>
>          PR fortran/94090
>          * gfortran.dg (gfc_compare_interfaces): Add
>          optional argument bad_result_characteristics.
>          * interface.c (gfc_check_result_characteristics): Fix
>          whitespace.
>          (gfc_compare_interfaces): Handle new argument; return
>          true if function return values are wrong.
>          * resolve.c (resolve_global_procedure): Hard error if
>          the return value of a function is wrong.
>
> 2020-04-13  Thomas Koenig  <tkoe...@gcc.gnu.org>
>
>          PR fortran/94090
>          * gfortran.dg/interface_46.f90: New test.

Thomas,

I agree with your assessment and the spirit of the patch.

I wonder: could you simply replace the gfc_error_opt(0, ...) call with
gfc_error? From what I can tell, gfc_error() is simply a short-cut for
gfc_error_opt(0, ...). This has the nice side-effects of reducing the
annoying 81-character line, and using only one copy of the error call:

@@ -2605,11 +2605,19 @@ resolve_global_procedure (gfc_symbol *sym,
locus *where, int sub)
        /* Turn erros into warnings with -std=gnu and -std=legacy.  */
        gfc_errors_to_warnings (true);

+      /* If a function returns a wrong type, this can lead to
+        all kinds of ICEs and wrong code; issue a hard error
+        in this case.  */
+
+      bool bad_result_characteristics;
       if (!gfc_compare_interfaces (sym, def_sym, sym->name, 0, 1,
-                                  reason, sizeof(reason), NULL, NULL))
+                                  reason, sizeof(reason), NULL, NULL,
+                                  &bad_result_characteristics))
        {
-         gfc_error_opt (0, "Interface mismatch in global procedure %qs at %L:"
-                        " %s", sym->name, &sym->declared_at, reason);
+         if (bad_result_characteristics)
+           gfc_errors_to_warnings (false);
+         gfc_error ("Interface mismatch in global procedure %qs at %L:"
+                    " %s", sym->name, &sym->declared_at, reason);
          goto done;
        }
     }

Otherwise LGTM, thanks for the fix.

---
Fritz Reese

Reply via email to