public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, fortran] Fix PR 44960, accepts invalid reference on function
@ 2020-01-16 23:00 Thomas Koenig
  2020-01-17  7:03 ` Steve Kargl
  2020-01-17  8:31 ` Tobias Burnus
  0 siblings, 2 replies; 11+ messages in thread
From: Thomas Koenig @ 2020-01-16 23:00 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 659 bytes --]

Hello world,

here is my first patch made from the git world.  It certainly took
enough time to work out how to to this, but I think I have it
figured out now...

Anyway, the fix is rather straightforward. We cannot have a reference
on a function. If this slipped through on parsing, let's issue the
error during resolution.

Regression-tested. OK for trunk?

Regards

	Thomas

2020-01-16  Thomas König  <tkoenig@gcc.gnu.org>

	PR fortran/44960
	* resolve.c (resolve_function): Issue error when a
	function call contains a reference.

2020-01-16  Thomas König  <tkoenig@gcc.gnu.org>

	PR fortran/44960
	* gfortran.dg/function_reference_1.f90: New test.

[-- Attachment #2: p1.diff --]
[-- Type: text/x-patch, Size: 1030 bytes --]

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 6f2a4c4d65a..1525c00ea4c 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -3129,6 +3129,13 @@ resolve_function (gfc_expr *expr)
 	  || sym->intmod_sym_id == GFC_ISYM_CAF_SEND))
     return true;
 
+  if (expr->ref)
+    {
+      gfc_error ("Function call can not contain a reference at %L",
+		 &expr->where);
+      return false;
+    }
+
   if (sym && sym->attr.intrinsic
       && !gfc_resolve_intrinsic (sym, &expr->where))
     return false;
diff --git a/gcc/testsuite/gfortran.dg/function_reference_1.f90 b/gcc/testsuite/gfortran.dg/function_reference_1.f90
new file mode 100644
index 00000000000..78c92a6f20d
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/function_reference_1.f90
@@ -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 "Function call can not contain a reference" }
+end
+

[-- Attachment #3: function_reference_1.f90 --]
[-- Type: text/x-fortran, Size: 233 bytes --]

! { 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 "Function call can not contain a reference" }
end


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-01-18 18:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-16 23:00 [patch, fortran] Fix PR 44960, accepts invalid reference on function Thomas Koenig
2020-01-17  7:03 ` Steve Kargl
2020-01-17  8:43   ` Tobias Burnus
2020-01-17 16:26     ` Steve Kargl
2020-01-17 23:14       ` Thomas Koenig
2020-01-18  0:06         ` Steve Kargl
2020-01-18 12:09         ` Tobias Burnus
2020-01-18 12:55           ` Thomas Koenig
2020-01-19  1:58           ` Thomas Koenig
2020-01-19  2:17             ` Tobias Burnus
2020-01-17  8:31 ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).