aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven G. Kargl <kargl@gcc.gnu.org>2019-08-17 14:39:51 +0000
committerSteven G. Kargl <kargl@gcc.gnu.org>2019-08-17 14:39:51 +0000
commit716ac0fc6c0ef0f1bf3a295f1338eeb697cddb43 (patch)
tree9b7bb21748305aae9a215666d079242f79bcb1fb
parent1c3925e32aea0046e01f844f2519c47caa7aa63b (diff)
downloadgcc-716ac0fc6c0ef0f1bf3a295f1338eeb697cddb43.zip
gcc-716ac0fc6c0ef0f1bf3a295f1338eeb697cddb43.tar.gz
gcc-716ac0fc6c0ef0f1bf3a295f1338eeb697cddb43.tar.bz2
re PR fortran/78739 (ICE in gfc_get_symbol_decl, at fortran/trans-decl.c:1477)
2019-08-17 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/78739 * match.c (gfc_match_st_function): When matching a statement function, need to check if the statement function name shadows the function name. 2019-08-17 Steven G. Kargl <kargl@gcc.gnu.org> PR fortran/78739 * fortran.dg/pr78739.f90: New test. From-SVN: r274605
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/match.c29
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gfortran.dg/pr78739.f9015
4 files changed, 56 insertions, 0 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 2de3532..21593de 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,12 @@
2019-08-17 Steven G. Kargl <kargl@gcc.gnu.org>
+ PR fortran/78739
+ * match.c (gfc_match_st_function): When matching a statement function,
+ need to check if the statement function name shadows the function
+ name.
+
+2019-08-17 Steven G. Kargl <kargl@gcc.gnu.org>
+
PR fortran/78719
* decl.c (get_proc_name): Check for a CLASS entity when trying to
add attributes to an entity that already has an explicit interface.
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index 5377e93..f148a02 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -5751,7 +5751,29 @@ gfc_match_st_function (void)
gfc_symbol *sym;
gfc_expr *expr;
match m;
+ char name[GFC_MAX_SYMBOL_LEN + 1];
+ locus old_locus;
+ bool fcn;
+ gfc_formal_arglist *ptr;
+
+ /* Read the possible statement function name, and then check to see if
+ a symbol is already present in the namespace. Record if it is a
+ function and whether it has been referenced. */
+ fcn = false;
+ ptr = NULL;
+ old_locus = gfc_current_locus;
+ m = gfc_match_name (name);
+ if (m == MATCH_YES)
+ {
+ gfc_find_symbol (name, NULL, 1, &sym);
+ if (sym && sym->attr.function && !sym->attr.referenced)
+ {
+ fcn = true;
+ ptr = sym->formal;
+ }
+ }
+ gfc_current_locus = old_locus;
m = gfc_match_symbol (&sym, 0);
if (m != MATCH_YES)
return m;
@@ -5779,6 +5801,13 @@ gfc_match_st_function (void)
return MATCH_ERROR;
}
+ if (fcn && ptr != sym->formal)
+ {
+ gfc_error ("Statement function %qs at %L conflicts with function name",
+ sym->name, &expr->where);
+ return MATCH_ERROR;
+ }
+
sym->value = expr;
if ((gfc_current_state () == COMP_FUNCTION
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1ab8b9e..8eecb3b 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,10 @@
2019-08-17 Steven G. Kargl <kargl@gcc.gnu.org>
+ PR fortran/78739
+ * fortran.dg/pr78739.f90: New test.
+
+2019-08-17 Steven G. Kargl <kargl@gcc.gnu.org>
+
PR fortran/78719
* gfortran.dg/pr78719_1.f90: New test.
* gfortran.dg/pr78719_2.f90: Ditto.
diff --git a/gcc/testsuite/gfortran.dg/pr78739.f90 b/gcc/testsuite/gfortran.dg/pr78739.f90
new file mode 100644
index 0000000..4b36b76
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr78739.f90
@@ -0,0 +1,15 @@
+! { dg-do compile }
+! { dg-options "-w" }
+! PR fortran/78739
+! Code contributed Gerhard Steinmetz
+function f(n)
+ f() = n ! { dg-error "conflicts with function name" }
+end
+
+function g()
+ g(x) = x ! { dg-error "conflicts with function name" }
+end
+
+function a() ! This should cause an error, but cannot be easily detected!
+ a() = x
+end