Bug 69860 - ICE on missing end apostrophe with character(kind=4)
Summary: ICE on missing end apostrophe with character(kind=4)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 7.0
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-invalid-code
Depends on:
Blocks:
 
Reported: 2016-02-17 19:29 UTC by Gerhard Steinmetz
Modified: 2016-12-08 18:06 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-02-18 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-02-17 19:29:26 UTC
With a missing end apostrophe :

$ cat z1.f90
program p
   character(len=2, kind=4) :: a = 'aa', b = 'bb
end


$ gfortran-6 -g z1.f90
z1.f90:2:46:

    character(len=2, kind=4) :: a = 'aa', b = 'bb
                                              1
Error: Unterminated character constant beginning at (1)
f951: internal compiler error: gfc_is_constant_expr(): Unknown expression type


For some other compile options, error message may depend on $LANG etc.
Comment 1 Gerhard Steinmetz 2016-02-17 19:29:59 UTC
No ICE if "kind=4" is changed to "kind=1" :

$ cat z2.f90
program p
   character(len=2, kind=1) :: a = 'aa', b = 'bb
end


$ gfortran-6 -g z2.f90
z2.f90:2:46:

    character(len=2, kind=1) :: a = 'aa', b = 'bb
                                              1
Error: Unterminated character constant beginning at (1)
Comment 2 Dominique d'Humieres 2016-02-18 18:28:23 UTC
Confirmed from 4.4 up to trunk (6.0), except 4.8.5 and 4.8.4 (r217778).

Note that I don't see any ICE for

   character(len=2, kind=4) :: a = 'aa
Comment 3 kargls 2016-07-03 06:44:24 UTC
Index: expr.c
===================================================================
--- expr.c	(revision 237945)
+++ expr.c	(working copy)
@@ -970,8 +970,14 @@ gfc_is_constant_expr (gfc_expr *e)
 
 
     default:
-      gfc_internal_error ("gfc_is_constant_expr(): Unknown expression type");
-      return 0;
+      {
+	int e, w;
+	gfc_get_errors (&w, &e);
+	if (e < 1)
+	  gfc_internal_error ("gfc_is_constant_expr(): Unknown "
+				"expression type");
+	return 0;
+      }
     }
 }
Comment 4 Thomas Koenig 2016-08-09 20:46:34 UTC
Fixed with r238822.
Comment 5 Gerhard Steinmetz 2016-08-22 17:56:07 UTC
The ICE is gone for several constellations, but not for all.


$ gfortran-7-20160821 -mavx z1.f90
z1.f90:2:46:

    character(len=2, kind=4) :: a = 'aa', b = 'bb
                                              1
Error: Unterminated character constant beginning at (1)
f951: internal compiler error: Segmentation fault
0xc1b63f crash_signal
        ../../gcc/toplev.c:335
0x688b02 gfc_is_constant_expr(gfc_expr*)
        ../../gcc/fortran/expr.c:899
0x688c1b gfc_is_constant_expr(gfc_expr*)
        ../../gcc/fortran/expr.c:902
0x6f13ba resolve_fl_procedure
        ../../gcc/fortran/resolve.c:11618
0x6f13ba resolve_symbol
        ../../gcc/fortran/resolve.c:14257
0x7098ab do_traverse_symtree
        ../../gcc/fortran/symbol.c:3930
0x6f319a resolve_types
        ../../gcc/fortran/resolve.c:15482
0x6eee5c gfc_resolve(gfc_namespace*)
        ../../gcc/fortran/resolve.c:15593
0x6da18a resolve_all_program_units
        ../../gcc/fortran/parse.c:5855
0x6da18a gfc_parse_file()
        ../../gcc/fortran/parse.c:6107
0x71c602 gfc_be_parse_file
        ../../gcc/fortran/f95-lang.c:198
Comment 6 kargls 2016-08-22 18:39:17 UTC
(In reply to Gerhard Steinmetz from comment #5)
> The ICE is gone for several constellations, but not for all.
> 
> 
> $ gfortran-7-20160821 -mavx z1.f90
> z1.f90:2:46:
> 
>     character(len=2, kind=4) :: a = 'aa', b = 'bb
>                                               1
> Error: Unterminated character constant beginning at (1)
> f951: internal compiler error: Segmentation fault
> 0xc1b63f crash_signal
>         ../../gcc/toplev.c:335
> 0x688b02 gfc_is_constant_expr(gfc_expr*)
>         ../../gcc/fortran/expr.c:899

Works for me. 

% gfc7 -o z a.f90
a.f90:2:46:

    character(len=2, kind=1) :: a = 'aa', b = 'bb
                                              1
Error: Unterminated character constant beginning at (1)

% gfc7 -v |& grep version
gcc version 7.0.0 20160822 (experimental) (GCC)
Comment 7 Dominique d'Humieres 2016-08-22 18:41:08 UTC
> Works for me. 

You need -mavx.
Comment 8 kargls 2016-08-22 19:08:18 UTC
(In reply to Dominique d'Humieres from comment #7)
> > Works for me. 
> 
> You need -mavx.

Like I said.  Works for me.

gfc7 -c -mavx a.f90
a.f90:2:46:

    character(len=2, kind=1) :: a = 'aa', b = 'bb
                                              1
Error: Unterminated character constant beginning at (1)

There is no ICE.
Comment 9 Dominique d'Humieres 2016-08-22 21:46:51 UTC
> Like I said.  Works for me.

How many times did you try? It worked for me the first time, but then I tried -mavx -m32 and got an ICE, then I got the same ICE with -mavx only. Another instance of non-deterministic error recovery?
Comment 10 kargls 2016-08-22 22:57:45 UTC
(In reply to Dominique d'Humieres from comment #9)
> > Like I said.  Works for me.
> 
> How many times did you try? It worked for me the first time, but then I
> tried -mavx -m32 and got an ICE, then I got the same ICE with -mavx only.
> Another instance of non-deterministic error recovery?

Is this enough times?

#! /bin/csh
foreach i (0 1 2 3 4 5 6 7 8 9)
   foreach j (0 1 2 3 4 5 6 7 8 9)
      gfc7 -c a.f90          |& tee sgk.log
      gfc7 -c -mavx a.f90    |& tee sgk.log
      gfc7 -c -m32 a.f90     |& tee sgk.log
      gfc7 -c -O a.f90       |& tee sgk.log
      gfc7 -c -O -mavx a.f90 |& tee sgk.log
      gfc7 -c -O -m32 a.f90  |& tee sgk.log
   end
end
grep -i internal sgk.log

No ICE.
Comment 11 Gerhard Steinmetz 2016-08-23 17:18:52 UTC
And with "kind=4" instead of "kind=1", i.e. with testfile z1.f90 ?


for n in `seq 1 1000`
do
   gfortran-7-20160821 -O2 -mavx -c z1.f90
done > list 2>&1

grep 'internal compiler' list | wc
    946    5676   47300


I can also confirm that ICEs are gone for z2.f90 ("kind=1").
Comment 12 kargls 2016-08-23 20:41:04 UTC
(In reply to Gerhard Steinmetz from comment #11)
> And with "kind=4" instead of "kind=1", i.e. with testfile z1.f90 ?
> 
> 
> for n in `seq 1 1000`
> do
>    gfortran-7-20160821 -O2 -mavx -c z1.f90
> done > list 2>&1
> 
> grep 'internal compiler' list | wc
>     946    5676   47300
> 
> 
> I can also confirm that ICEs are gone for z2.f90 ("kind=1").

Ugh.  I was testing apparently a kind=1 version.  The problem
is that gfortran is inserting __convert_s1_s4 to convert to
the same kind, which of course fails.  This un-regression-tested
patch covers up the ICE, but it is perhaps not the correct fix.
Fortunately, I don't use kind=4 character types, so I don't have
a dog in this fight.

Index: primary.c
===================================================================
--- primary.c   (revision 239661)
+++ primary.c   (working copy)
@@ -1105,8 +1105,8 @@ got_delim:
       if (ret == -2)
        {
          gfc_current_locus = start_locus;
-         gfc_error ("Unterminated character constant beginning at %C");
-         return MATCH_ERROR;
+         gfc_error_now ("Unterminated character constant beginning at %C");
+         return MATCH_NO;
        }
 
       length++;
Comment 13 kargls 2016-12-08 04:45:31 UTC
(In reply to kargl from comment #12)
> (In reply to Gerhard Steinmetz from comment #11)
> > And with "kind=4" instead of "kind=1", i.e. with testfile z1.f90 ?
> > 
> > 
> > for n in `seq 1 1000`
> > do
> >    gfortran-7-20160821 -O2 -mavx -c z1.f90
> > done > list 2>&1
> > 
> > grep 'internal compiler' list | wc
> >     946    5676   47300
> > 
> > 
> > I can also confirm that ICEs are gone for z2.f90 ("kind=1").
> 
> Ugh.  I was testing apparently a kind=1 version.  The problem
> is that gfortran is inserting __convert_s1_s4 to convert to
> the same kind, which of course fails.  This un-regression-tested
> patch covers up the ICE, but it is perhaps not the correct fix.
> Fortunately, I don't use kind=4 character types, so I don't have
> a dog in this fight.
> 

This might have been fixed by Janus patch:

2016-12-04  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/78618
        * intrinsic.c (gfc_convert_type_warn): Do not set the full typespec for
        the conversion symbol, but only type and kind. Set the full typespec
        for the expression.
        (gfc_convert_chartype): Ditto.

Gerhard can re-do your testing.  I seem to have good luck with FreeBSD
in testing this.
Comment 14 janus 2016-12-08 09:30:45 UTC
(In reply to kargl from comment #13)
> Gerhard can re-do your testing.  I seem to have good luck with FreeBSD
> in testing this.

On Ubuntu 16.10, I don't see any ICE with current trunk either, using the method from comment #11.

But then, I don't even see ICEs with 5.4.1 or 6.2.0. I only see some with 4.9.

From my side, this can be closed.
Comment 15 Gerhard Steinmetz 2016-12-08 17:47:38 UTC
Confirmed, this ICE is now completely gone on my environment.
Comment 16 janus 2016-12-08 18:06:56 UTC
(In reply to Gerhard Steinmetz from comment #15)
> Confirmed, this ICE is now completely gone on my environment.

Great! Closing.