Check for illegal reference in function.
authorThomas König <tkoenig@gcc.gnu.org>
Thu, 16 Jan 2020 21:09:37 +0000 (22:09 +0100)
committerThomas König <tkoenig@gcc.gnu.org>
Sun, 19 Jan 2020 09:23:18 +0000 (10:23 +0100)
gcc/fortran/ChangeLog
gcc/fortran/primary.c
gcc/fortran/resolve.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/function_reference_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/function_reference_2.f90 [new file with mode: 0644]

index 524ebff3e1fff2d4670defe34937586e7feffc0c..3f412fd8c20be8c79802468c47f98b82bbed3e44 100644 (file)
@@ -1,3 +1,10 @@
+2020-01-19  Thomas König  <tkoenig@gcc.gnu.org>
+
+       PR fortran/44960
+       * primary.c (gfc_match_rvalue): Break after setting MATCH_ERROR.
+       * resolve.c (resolve_function): Issue error when a
+       function call contains a reference.
+
 2020-01-17  Mark Eggleston  <mark.eggleston@codethink.com>
 
        PR fortran/93236
index 07b8ac08ba20faf99bf91d3d144f01ea7d712b89..bd50827bb150c12485b04f514e922b2f3e691363 100644 (file)
@@ -3661,6 +3661,7 @@ gfc_match_rvalue (gfc_expr **result)
          gfc_error ("The leftmost part-ref in a data-ref cannot be a "
                     "function reference at %C");
          m = MATCH_ERROR;
+         break;
        }
 
       m = MATCH_YES;
index bddab39d023a406d17e712db531663e87cd18e7a..e840aec62f234864f5a34ccd203dee04744954fa 100644 (file)
@@ -3129,6 +3129,13 @@ resolve_function (gfc_expr *expr)
          || sym->intmod_sym_id == GFC_ISYM_CAF_SEND))
     return true;
 
+  if (expr->ref)
+    {
+      gfc_error ("Unexpected junk after %qs at %L", expr->symtree->n.sym->name,
+                &expr->where);
+      return false;
+    }
+
   if (sym && sym->attr.intrinsic
       && !gfc_resolve_intrinsic (sym, &expr->where))
     return false;
index aa5505ba261a7c9f00ff501333fb61bff49a11d8..9066c173bbdea07101d79792af4af86dd9a02f0f 100644 (file)
@@ -1,3 +1,9 @@
+2020-01-19  Thomas König  <tkoenig@gcc.gnu.org>
+
+       PR fortran/44960
+       * gfortran.dg/function_reference_1.f90: New test.
+       * gfortran.dg/function_reference_2.f90: New test.
+
 2020-01-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/92833
diff --git a/gcc/testsuite/gfortran.dg/function_reference_1.f90 b/gcc/testsuite/gfortran.dg/function_reference_1.f90
new file mode 100644 (file)
index 0000000..be634c9
--- /dev/null
@@ -0,0 +1,11 @@
+! { dg-do compile }
+! PR 44960 - this was erroneusly accepted.
+! Original test case by Daniel Franke.
+
+type t
+  integer :: a
+end type t
+type(t) :: foo
+print *, foo(1)%a ! { dg-error "Unexpected junk" }
+end
+
diff --git a/gcc/testsuite/gfortran.dg/function_reference_2.f90 b/gcc/testsuite/gfortran.dg/function_reference_2.f90
new file mode 100644 (file)
index 0000000..375c58b
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR 44960 - improve the error message
+program main
+  type t
+  integer :: a
+end type t
+type(t) :: foo
+external foo
+i = foo(1)%1 ! { dg-error "leftmost part-ref in a data-ref cannot be a function reference" }
+end