Dear Fortranners,
I intend to commit the following pretty obvious fix within the next
24 hours unless there are objections.
Regtested on x86_64-pc-linux-gnu.
Thanks,
Harald
Fortran: ICE with automatic character object, save, and various options
gcc/fortran/ChangeLog:
PR fortran/68568
* primary.c (gfc_expr_attr): Variable attribute can only be
inquired when symtree is non-NULL.
gcc/testsuite/ChangeLog:
PR fortran/68568
* gfortran.dg/pr68568.f90: New test.
diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index 9fe8d1ee20c..56a78d6f89f 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -2779,7 +2779,7 @@ gfc_expr_attr (gfc_expr *e)
&& e->value.function.isym->transformational
&& e->ts.type == BT_CLASS)
attr = CLASS_DATA (e)->attr;
- else
+ else if (e->symtree)
attr = gfc_variable_attr (e, NULL);
/* TODO: NULL() returns pointers. May have to take care of this
diff --git a/gcc/testsuite/gfortran.dg/pr68568.f90 b/gcc/testsuite/gfortran.dg/pr68568.f90
new file mode 100644
index 00000000000..eab5744b363
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr68568.f90
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! { dg-options "-finit-character=7 -Wsurprising" }
+! PR fortran/68568 - ICE with automatic character object, save, and options
+
+subroutine s(n) ! { dg-error "non-constant initialization expression" }
+ integer, intent(in) :: n
+ character(len=n) :: x
+ save
+ x = 'a'
+end