]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Fix ICE caused by missing error for untyped symbol [PR103258]
authorSandra Loosemore <sandra@codesourcery.com>
Wed, 5 Jan 2022 02:18:13 +0000 (18:18 -0800)
committerSandra Loosemore <sandra@codesourcery.com>
Wed, 5 Jan 2022 17:02:22 +0000 (09:02 -0800)
The bit on a symbol to mark that it had already been diagnosed as
lacking a type was getting set even when the error was suppressed or
discarded, specifically when doing early resolution on a character
length expression to see if it can be constant-folded.  Explicitly
suppress errors before doing that, then check whether they are
suppressed before setting the bit.

2022-01-04  Sandra Loosemore  <sandra@codesourcery.com>

PR fortran/103258

gcc/fortran/
* decl.c (gfc_match_char_spec): Suppress errors around call
to gfc_reduce_init_expr.
* error.c (gfc_query_suppress_errors): New.
* gfortran.h (gfc_query_suppress_errors): Declare.
* symbol.c (gfc_set_default_type): Check gfc_query_suppress_errors.

gcc/testsuite/
* gfortran.dg/pr103258.f90: New.

gcc/fortran/decl.c
gcc/fortran/error.c
gcc/fortran/gfortran.h
gcc/fortran/symbol.c
gcc/testsuite/gfortran.dg/pr103258.f90 [new file with mode: 0644]

index 4e510cc72ef5edfbe10daf034e32aa72d41c40ee..c846923ca8c3719e394dd63b8ae292c9cb0c003e 100644 (file)
@@ -3609,7 +3609,9 @@ done:
          gfc_current_ns = gfc_get_namespace (NULL, 0);
 
          e = gfc_copy_expr (len);
+         gfc_push_suppress_errors ();
          gfc_reduce_init_expr (e);
+         gfc_pop_suppress_errors ();
          if (e->expr_type == EXPR_CONSTANT)
            {
              gfc_replace_expr (len, e);
index be2eb935443042b599db267f7907c96469152ac7..e95c083d1bfbefffc880afd4cca524cf533d5fc5 100644 (file)
@@ -83,6 +83,15 @@ gfc_pop_suppress_errors (void)
 }
 
 
+/* Query whether errors are suppressed.  */
+
+bool
+gfc_query_suppress_errors (void)
+{
+  return suppress_errors > 0;
+}
+
+
 /* Determine terminal width (for trimming source lines in output).  */
 
 static int
index d01a9dc952fba70fc1c068a400d34deef21ee0e7..3b791a4f6beae86b7e8710b5cdf33791eff31d2b 100644 (file)
@@ -1083,6 +1083,7 @@ typedef struct
 
 void gfc_push_suppress_errors (void);
 void gfc_pop_suppress_errors (void);
+bool gfc_query_suppress_errors (void);
 
 
 /* Character length structures hold the expression that gives the
index 03855955ce435cc7cfcbda2021bad7c8d09a6691..1a4b0228597736dc749353cdeccad635ada8dcd0 100644 (file)
@@ -299,7 +299,7 @@ gfc_set_default_type (gfc_symbol *sym, int error_flag, gfc_namespace *ns)
 
   if (ts->type == BT_UNKNOWN)
     {
-      if (error_flag && !sym->attr.untyped)
+      if (error_flag && !sym->attr.untyped && !gfc_query_suppress_errors ())
        {
          const char *guessed = lookup_symbol_fuzzy (sym->name, sym);
          if (guessed)
diff --git a/gcc/testsuite/gfortran.dg/pr103258.f90 b/gcc/testsuite/gfortran.dg/pr103258.f90
new file mode 100644 (file)
index 0000000..4521fcd
--- /dev/null
@@ -0,0 +1,14 @@
+! { dg-do compile}
+! { dg-additional-options "-Wno-pedantic" }
+!
+! Test from PR103258.  This used to ICE due to incorrectly marking the
+! no-implicit-type error for n and m in the character length expression
+! as already diagnosed during early resolution, when in fact errors are
+! ignored in that parsing context.  We now expect the errors to be diagnosed
+! at the point of the first use of each symbol.
+
+subroutine s(n) ! { dg-error "Symbol 'n' .*has no IMPLICIT type" }
+implicit none
+character(n+m) :: c ! { dg-error "Symbol 'm' .*has no IMPLICIT type" }
+entry e(m)
+end