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

--- Comment #5 from kargl at gcc dot gnu.org ---
(In reply to kargl from comment #3)
> (In reply to G. Steinmetz from comment #0)
> > This snippet (clearly invalid) gives a second error message
> > with randomly corrupted text :
> > 
> > 
> > $ cat z1.f90
> > program p
> >    real :: a, b(4)
> >    character(len(c)) :: b
> > end
> > 
> > 
> > $ gfortran-8-20171022 -c z1.f90
> > z1.f90:3:25:
> > 
> >     character(len(c)) :: b
> >                          1
> > Error: Symbol 'b' at (1) already has basic type of REAL
> > z1.f90:3:13:
> > 
> >     character(len(c)) :: b
> >              1
> > Error: '\xa8\x8e\x1f\x8e+' at (1) is not a function
> 
> Interesting.  Must be an OS specific issue.
> 
> % gfcx -c r.f90
> r.f90:3:25:
> 
>     character(len(c)) :: b
>                          1
> Error: Symbol 'b' at (1) already has basic type of REAL
> r.f90:3:17:
> 
>     character(len(c)) :: b
>                  1
> Error: 'string' argument of 'len' intrinsic at (1) must be CHARACTER
> 
> % valgrind ~/work/libexec/gcc/x86_64-unknown-freebsd12.0/8.0.0/f951 r.f90
> ==68051== Memcheck, a memory error detector
> ==68051== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
> ==68051== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
> ==68051== Command:
> /mnt/sgk/work/libexec/gcc/x86_64-unknown-freebsd12.0/8.0.0/f951 r.f90
> ==68051== 
> --68051-- WARNING: unhandled syscall: 552
> --68051-- You may be able to write your own handler.
> --68051-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
> --68051-- Nevertheless we consider this a bug.  Please report
> --68051-- it at http://valgrind.org/support/bug_reports.html.
> --68051-- WARNING: unhandled syscall: 551
> --68051-- You may be able to write your own handler.
> --68051-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
> --68051-- Nevertheless we consider this a bug.  Please report
> --68051-- it at http://valgrind.org/support/bug_reports.html.
> Cannot fstat "/usr/local/lib/valgrind/vgpreload_core-amd64-freebsd.so"
> ==68051== 
> ==68051== HEAP SUMMARY:
> ==68051==     in use at exit: 0 bytes in 0 blocks
> ==68051==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
> ==68051==

So, I looked at this on my i586-*-freebsd system.  Internal state seems
to be corrupted.  The problem can be avoided by the following patch

Index: resolve.c
===================================================================
--- resolve.c   (revision 260808)
+++ resolve.c   (working copy)
@@ -2937,16 +2937,23 @@ is_external_proc (gfc_symbol *sym)
 /* Figure out if a function reference is pure or not.  Also set the name
    of the function for a potential error message.  Return nonzero if the
    function is PURE, zero if not.  */
+
 static int
 pure_stmt_function (gfc_expr *, gfc_symbol *);

 static int
 pure_function (gfc_expr *e, const char **name)
 {
-  int pure;
+  int error_count, pure;
   gfc_component *comp;

   *name = NULL;
+
+  /* If gfortran gets here with an issued error and a BT_UNKNOWN type,
+     something has corrupted internal state.  Die instead of an ICE.  */
+  gfc_get_errors (NULL, &error_count);
+  if (error_count > 0 && e->ts.type == BT_UNKNOWN)
+    gfc_fatal_error ("Invalid Fortran detected");

   if (e->symtree != NULL
         && e->symtree->n.sym != NULL

Reply via email to