Bug 85780 - ICE in resolve_fl_procedure, at fortran/resolve.c:12504
Summary: ICE in resolve_fl_procedure, at fortran/resolve.c:12504
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 9.0
: P4 normal
Target Milestone: 6.5
Assignee: kargls
URL:
Keywords:
: 88139 (view as bug list)
Depends on:
Blocks:
 
Reported: 2018-05-14 19:09 UTC by G. Steinmetz
Modified: 2019-06-15 04:22 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-05-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description G. Steinmetz 2018-05-14 19:09:07 UTC
Affects versions down to at least 4.8 :

$ cat z1.f90
subroutine s(*) bind(c)
end


$ gfortran-9-20180513 -c z1.f90
f951: internal compiler error: Segmentation fault
0xb9f4bf crash_signal
        ../../gcc/toplev.c:325
0x71bbfd resolve_fl_procedure
        ../../gcc/fortran/resolve.c:12504
0x71bbfd resolve_symbol
        ../../gcc/fortran/resolve.c:15157
0x73639b do_traverse_symtree
        ../../gcc/fortran/symbol.c:4149
0x71cb1a resolve_types
        ../../gcc/fortran/resolve.c:16456
0x71839c gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.c:16570
0x701b6a resolve_all_program_units
        ../../gcc/fortran/parse.c:6060
0x701b6a gfc_parse_file()
        ../../gcc/fortran/parse.c:6310
0x748adf gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:204
Comment 1 kargls 2018-05-14 20:18:15 UTC
Paul,

The ICE can be fixed by checking for a NULL pointer.

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 260235)
+++ gcc/fortran/resolve.c       (working copy)
@@ -12501,7 +12501,7 @@ resolve_fl_procedure (gfc_symbol *sym, int mp_flag)
       while (curr_arg != NULL)
         {
           /* Skip implicitly typed dummy args here.  */
-         if (curr_arg->sym->attr.implicit_type == 0)
+         if (curr_arg->sym && curr_arg->sym->attr.implicit_type == 0)
            if (!gfc_verify_c_interop_param (curr_arg->sym))
              /* If something is found to fail, record the fact so we
                 can mark the symbol for the procedure as not being

HOwever, I think we then have an accepts invalid as an alternate
return takes a label.  If I look at gfc_match_formal_arglist in 
decl.c, it looks like your PDT work may have touched the area
that should issue an error.
 81764   dnovillo       if (gfc_match_char ('*') == MATCH_YES)
197389      janus       {
197389      janus         sym = NULL;
255311      pault         if (!typeparam && !gfc_notify_std (GFC_STD_F95_OBS,
255311      pault                            "Alternate-return argument at %C"))
197389      janus           {
197389      janus             m = MATCH_ERROR;
197389      janus             goto cleanup;
197389      janus           }
255311      pault         else if (typeparam)
255311      pault           gfc_error_now ("A parameter name is required at %C");
197389      janus       }

Do you have any insights?
Comment 2 kargls 2018-05-14 20:25:22 UTC
(In reply to kargl from comment #1)

> HOwever, I think we then have an accepts invalid as an alternate
> return takes a label.  

Whoops, I may have misread the standard.  The label applies to
the actual argument.  A dummy argument of '*' alone signifies
an alternate return, the patch in #1 indeed fixes the issue.
Comment 3 kargls 2018-05-24 23:29:07 UTC
Author: kargl
Date: Thu May 24 23:28:35 2018
New Revision: 260698

URL: https://gcc.gnu.org/viewcvs?rev=260698&root=gcc&view=rev
Log:
2018-05-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	* resolve.c (resolve_fl_procedure): Avoid NULL dereference.

2018-05-24  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	* gfortran.dg/pr85780.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/pr85780.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 kargls 2018-05-25 18:29:23 UTC
Author: kargl
Date: Fri May 25 18:28:51 2018
New Revision: 260768

URL: https://gcc.gnu.org/viewcvs?rev=260768&root=gcc&view=rev
Log:
2018-05-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	Backport from trunk
	* resolve.c (resolve_fl_procedure): Avoid NULL dereference.

2018-05-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	Backport from trunk
	* gfortran.dg/pr85780.f90: New test.

Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr85780.f90
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/resolve.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 5 kargls 2018-05-25 19:06:23 UTC
Author: kargl
Date: Fri May 25 19:05:52 2018
New Revision: 260771

URL: https://gcc.gnu.org/viewcvs?rev=260771&root=gcc&view=rev
Log:
2018-05-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	Backport from trunk
	* resolve.c (resolve_fl_procedure): Avoid NULL dereference.

2018-05-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	Backport from trunk
	* gfortran.dg/pr85780.f90: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr85780.f90
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/resolve.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 6 kargls 2018-05-25 19:55:24 UTC
Author: kargl
Date: Fri May 25 19:54:51 2018
New Revision: 260777

URL: https://gcc.gnu.org/viewcvs?rev=260777&root=gcc&view=rev
Log:
2018-05-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	Backport from trunk
	* resolve.c (resolve_fl_procedure): Avoid NULL dereference.

2018-05-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	Backport from trunk
	* gfortran.dg/pr85780.f90: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gfortran.dg/pr85780.f90
Modified:
    branches/gcc-6-branch/gcc/fortran/ChangeLog
    branches/gcc-6-branch/gcc/fortran/resolve.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 7 kargls 2018-05-25 19:56:54 UTC
Fixed.
Comment 8 kargls 2019-01-25 01:39:35 UTC
My original patch simply fixed the ICE, which then
allowed the code to compile.  In reality, an alternate
return is not ISO C interoperable, so an error message
is a more appropriate response.  I have a patch.  So,
re-open.
Comment 9 kargls 2019-01-25 02:30:00 UTC
Patch submitted.

https://gcc.gnu.org/ml/fortran/2019-01/msg00236.html
Comment 10 kargls 2019-01-25 17:55:57 UTC
Author: kargl
Date: Fri Jan 25 17:55:25 2019
New Revision: 268277

URL: https://gcc.gnu.org/viewcvs?rev=268277&root=gcc&view=rev
Log:
2019-01-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	* decl.c (gfc_match_subroutine): Check for conflict between BIND(C)
	and alternative return.

2019-01-25  Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/85780
	* gfortran.dg/pr85780.f90: Update testcase for error message.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/pr85780.f90
Comment 11 kargls 2019-01-25 17:56:49 UTC
Fixed on trunk. Closing.
Comment 12 kargls 2019-06-15 04:22:33 UTC
*** Bug 88139 has been marked as a duplicate of this bug. ***