Bug 77583 - ICE in pp_quoted_string, at pretty-print.c:966
Summary: ICE in pp_quoted_string, at pretty-print.c:966
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 7.5
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic, ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2016-09-13 18:56 UTC by Gerhard Steinmetz
Modified: 2019-03-03 20:42 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-09-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerhard Steinmetz 2016-09-13 18:56:08 UTC
A naming conflict between dummy-arg and internal subroutine/function.
Invalid code, and gcc configured with --enable-checking=yes.


$ cat z1.f90
pure subroutine sub(s)
contains
   pure subroutine s
   end
end


$ gfortran-7-20160911 z1.f90
z1.f90:3:20:

    pure subroutine s
                    1
Error: internal procedure 's' at (1) conflicts with DUMMY argument
'
in pp_quoted_string, at pretty-print.c:966
0x13a5ee0 pp_quoted_string
        ../../gcc/pretty-print.c:966
0x13a695b pp_format(pretty_printer*, text_info*)
        ../../gcc/pretty-print.c:595
0x139a6a0 diagnostic_report_diagnostic(diagnostic_context*, diagnostic_info*)
        ../../gcc/diagnostic.c:941
0x689248 gfc_error_now(char const*, ...)
        ../../gcc/fortran/error.c:1177
0x70af46 check_conflict
        ../../gcc/fortran/symbol.c:479
0x5dce0c copy_prefix
        ../../gcc/fortran/decl.c:4994
0x67e6de gfc_match_subroutine()
        ../../gcc/fortran/decl.c:6411
0x6d6781 decode_statement
        ../../gcc/fortran/parse.c:379
0x6d8444 next_free
        ../../gcc/fortran/parse.c:1143
0x6d8444 next_statement
        ../../gcc/fortran/parse.c:1376
0x6dbba4 parse_contained
        ../../gcc/fortran/parse.c:5337
0x6dbad6 parse_progunit
        ../../gcc/fortran/parse.c:5560
0x6dd134 gfc_parse_file()
        ../../gcc/fortran/parse.c:6005
0x71f5f2 gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:198
Comment 1 Gerhard Steinmetz 2016-09-13 18:56:50 UTC
With official releases (configured with --enable-checking=release) :


$ gfortran-6 z1.f90
z1.f90:3:20:

    pure subroutine s
                    1
Error: internal procedure 's' at (1) conflicts with DUMMY argument
'
(null):0: confused by earlier errors, bailing out


$ gfortran-5 z1.f90
z1.f90:3:20:

    pure subroutine s
                    1
Error: internal procedure 's' at (1) conflicts with DUMMY argument
z1.f90:3:20: Error: internal procedure '' at (1) conflicts with DUMMY argument
# no ICE


$ gfortran-4.9 z1.f90
z1.f90: In function 's':
z1.f90:1:0: internal compiler error: in make_decl_rtl, at varasm.c:1221
 pure subroutine sub(s)
 ^
Please submit a full bug report,
with preprocessed source if appropriate.

---


More variants :


$ cat z2.f90
recursive subroutine sub(s)
contains
   recursive subroutine s
   end
end


$ cat z3.f90
elemental subroutine sub(s)
contains
   elemental subroutine s
   end
end


$ cat z4.f90
pure elemental subroutine sub(s)
contains
   pure elemental subroutine s
   end
end


$ cat z5.f90
pure subroutine sub(s)
contains
   elemental subroutine s
   end
end


$ cat z6.f90
elemental function f(s)
   real, intent(in) :: s
contains
   pure subroutine s
   end
end


# ...
Comment 2 Manuel López-Ibáñez 2016-09-13 20:15:57 UTC
check_conflict is sometimes called with name = NULL and that is passed to %qs causing a crash.
Comment 3 Dominique d'Humieres 2016-09-14 14:26:52 UTC
> check_conflict is sometimes called with name = NULL and that is passed
> to %qs causing a crash.

Indeed, but this is not the case for the tests giving the error

Error: internal procedure '*' at (1) conflicts ...

but the where seems wrong.
Comment 4 kargl 2016-09-14 22:08:23 UTC
(In reply to Manuel López-Ibáñez from comment #2)
> check_conflict is sometimes called with name = NULL and that is passed to
> %qs causing a crash.

Index: symbol.c
===================================================================
--- symbol.c	(revision 240140)
+++ symbol.c	(working copy)
@@ -473,8 +473,8 @@ check_conflict (symbol_attribute *attr, 
 	}
     }
 
-  if (attr->dummy && ((attr->function || attr->subroutine) && 
-			gfc_current_state () == COMP_CONTAINS))
+  if (name && attr->dummy && ((attr->function || attr->subroutine)
+			      && gfc_current_state () == COMP_CONTAINS))
     gfc_error_now ("internal procedure %qs at %L conflicts with "
 		   "DUMMY argument", name, where);
Comment 5 anlauf 2019-03-01 21:58:43 UTC
(In reply to kargl from comment #4)
> (In reply to Manuel López-Ibáñez from comment #2)
> > check_conflict is sometimes called with name = NULL and that is passed to
> > %qs causing a crash.
> 
> Index: symbol.c
> ===================================================================
> --- symbol.c	(revision 240140)
> +++ symbol.c	(working copy)
> @@ -473,8 +473,8 @@ check_conflict (symbol_attribute *attr, 
>  	}
>      }
>  
> -  if (attr->dummy && ((attr->function || attr->subroutine) && 
> -			gfc_current_state () == COMP_CONTAINS))
> +  if (name && attr->dummy && ((attr->function || attr->subroutine)
> +			      && gfc_current_state () == COMP_CONTAINS))
>      gfc_error_now ("internal procedure %qs at %L conflicts with "
>  		   "DUMMY argument", name, where);

The additional check on 'name' basically applies on current trunk and
fixes the ICE.

Are you still pursuing this?
Comment 6 Steve Kargl 2019-03-01 22:03:43 UTC
On Fri, Mar 01, 2019 at 09:58:43PM +0000, anlauf at gcc dot gnu.org wrote:
> (In reply to kargl from comment #4)
> > (In reply to Manuel López-Ibáñez from comment #2)
> > > check_conflict is sometimes called with name = NULL and that is passed to
> > > %qs causing a crash.
> > 
> > Index: symbol.c
> > ===================================================================
> > --- symbol.c	(revision 240140)
> > +++ symbol.c	(working copy)
> > @@ -473,8 +473,8 @@ check_conflict (symbol_attribute *attr, 
> >  	}
> >      }
> >  
> > -  if (attr->dummy && ((attr->function || attr->subroutine) && 
> > -			gfc_current_state () == COMP_CONTAINS))
> > +  if (name && attr->dummy && ((attr->function || attr->subroutine)
> > +			      && gfc_current_state () == COMP_CONTAINS))
> >      gfc_error_now ("internal procedure %qs at %L conflicts with "
> >  		   "DUMMY argument", name, where);
> 
> The additional check on 'name' basically applies on current trunk and
> fixes the ICE.
> 
> Are you still pursuing this?
> 

Given that 2.7 years have past, I'll offer "no".
Feel free to run with the patch.
Comment 7 Dominique d'Humieres 2019-03-03 09:29:05 UTC
Patch at https://gcc.gnu.org/ml/fortran/2019-03/msg00007.html and it has been approved.
Comment 8 anlauf 2019-03-03 20:25:27 UTC
Author: anlauf
Date: Sun Mar  3 20:24:53 2019
New Revision: 269353

URL: https://gcc.gnu.org/viewcvs?rev=269353&root=gcc&view=rev
Log:
2019-03-03  Harald Anlauf  <anlauf@gmx.de>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	PR fortran/77583
	* symbol.c (check_conflict): Check for valid procedure name
	passed to error reporting routine.

	PR fortran/77583
	* gfortran.dg/pr77583.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/pr77583.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 anlauf 2019-03-03 20:31:16 UTC
Author: anlauf
Date: Sun Mar  3 20:30:44 2019
New Revision: 269354

URL: https://gcc.gnu.org/viewcvs?rev=269354&root=gcc&view=rev
Log:
2019-03-03  Harald Anlauf  <anlauf@gmx.de>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	Backport from trunk
	PR fortran/77583
	* symbol.c (check_conflict): Check for valid procedure name
	passed to error reporting routine.

	PR fortran/77583
	* gfortran.dg/pr77583.f90: New test.


Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/pr77583.f90
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/symbol.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Comment 10 anlauf 2019-03-03 20:36:44 UTC
Author: anlauf
Date: Sun Mar  3 20:36:12 2019
New Revision: 269355

URL: https://gcc.gnu.org/viewcvs?rev=269355&root=gcc&view=rev
Log:
2019-03-03  Harald Anlauf  <anlauf@gmx.de>
	    Steven G. Kargl  <kargl@gcc.gnu.org>

	Backport from trunk
	PR fortran/77583
	* symbol.c (check_conflict): Check for valid procedure name
	passed to error reporting routine.

	PR fortran/77583
	* gfortran.dg/pr77583.f90: New test.


Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/pr77583.f90
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/symbol.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 11 anlauf 2019-03-03 20:42:04 UTC
Fixed on trunk, 8- and 7-branches.
Closing.