public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch] PR fortran/100218 - target of pointer from evaluation of function-reference
@ 2021-04-22 20:25 Harald Anlauf
  2021-04-24 16:37 ` Paul Richard Thomas
  0 siblings, 1 reply; 3+ messages in thread
From: Harald Anlauf @ 2021-04-22 20:25 UTC (permalink / raw)
  To: fortran, gcc-patches

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

Dear Fortranners,

while analyzing a different PR (PR100154), Tobias pointed out that the
target of a pointer from the evaluation of function-reference is allowed
to be used in a variable definition context and thus as an actual
argument to a function or subroutine.

This seems to be a more general issue that seems to have been overlooked.
The attached simple patch allows to compile and run the attached example,
which is by the way already yet rejected with -std=f2003.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?
Shall we backport this to (at least) 11?

Thanks,
Harald


Fortran - allow target of pointer from evaluation of function-reference

Fortran allows the target of a pointer from the evaluation of a
function-reference in a variable definition context (e.g. F2018:R902).

gcc/fortran/ChangeLog:

	PR fortran/100218
	* expr.c (gfc_check_vardef_context): Extend check to allow pointer
	from a function reference.

gcc/testsuite/ChangeLog:

	PR fortran/100218
	* gfortran.dg/pr100218.f90: New test.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr100218.patch --]
[-- Type: text/x-patch, Size: 1334 bytes --]

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index 92a6700568d..696b9f1daac 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -6121,7 +6132,9 @@ gfc_check_vardef_context (gfc_expr* e, bool pointer, bool alloc_obj,
     }
   if (!pointer && sym->attr.flavor != FL_VARIABLE
       && !(sym->attr.flavor == FL_PROCEDURE && sym == sym->result)
-      && !(sym->attr.flavor == FL_PROCEDURE && sym->attr.proc_pointer))
+      && !(sym->attr.flavor == FL_PROCEDURE && sym->attr.proc_pointer)
+      && !(sym->attr.flavor == FL_PROCEDURE
+	   && sym->attr.function && sym->attr.pointer))
     {
       if (context)
 	gfc_error ("%qs in variable definition context (%s) at %L is not"
diff --git a/gcc/testsuite/gfortran.dg/pr100218.f90 b/gcc/testsuite/gfortran.dg/pr100218.f90
new file mode 100644
index 00000000000..62b18f6a935
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr100218.f90
@@ -0,0 +1,19 @@
+! { dg-do run }
+! { dg-options "-O2 -std=f2008" }
+! PR fortran/100218 - target of pointer from evaluation of function-reference
+
+program p
+  implicit none
+  integer, target :: z = 0
+  call g (f ())
+  if (z /= 1) stop 1
+contains
+  function f () result (r)
+    integer, pointer :: r
+    r => z
+  end function f
+  subroutine g (x)
+    integer, intent(out) :: x
+    x = 1
+  end subroutine g
+end program p

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

* Re: [Patch] PR fortran/100218 - target of pointer from evaluation of function-reference
  2021-04-22 20:25 [Patch] PR fortran/100218 - target of pointer from evaluation of function-reference Harald Anlauf
@ 2021-04-24 16:37 ` Paul Richard Thomas
  2021-04-24 18:12   ` Harald Anlauf
  0 siblings, 1 reply; 3+ messages in thread
From: Paul Richard Thomas @ 2021-04-24 16:37 UTC (permalink / raw)
  To: Harald Anlauf; +Cc: fortran, gcc-patches

Hi Harald,

Another good one - OK for master but wait a while for 11-branch.

I am a bit hesitant about 10-branch because this is not a regression. That
said, this is harmless because it is permissive, so I will leave it to you
to decide.

Is there a test for an error with -std=f2003? If not, you should, perhaps,
include one.

Thanks

Paul


On Thu, 22 Apr 2021 at 23:37, Harald Anlauf via Fortran <fortran@gcc.gnu.org>
wrote:

> Dear Fortranners,
>
> while analyzing a different PR (PR100154), Tobias pointed out that the
> target of a pointer from the evaluation of function-reference is allowed
> to be used in a variable definition context and thus as an actual
> argument to a function or subroutine.
>
> This seems to be a more general issue that seems to have been overlooked.
> The attached simple patch allows to compile and run the attached example,
> which is by the way already yet rejected with -std=f2003.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?
> Shall we backport this to (at least) 11?
>
> Thanks,
> Harald
>
>
> Fortran - allow target of pointer from evaluation of function-reference
>
> Fortran allows the target of a pointer from the evaluation of a
> function-reference in a variable definition context (e.g. F2018:R902).
>
> gcc/fortran/ChangeLog:
>
>         PR fortran/100218
>         * expr.c (gfc_check_vardef_context): Extend check to allow pointer
>         from a function reference.
>
> gcc/testsuite/ChangeLog:
>
>         PR fortran/100218
>         * gfortran.dg/pr100218.f90: New test.
>
>

-- 
"If you can't explain it simply, you don't understand it well enough" -
Albert Einstein

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

* Re: [Patch] PR fortran/100218 - target of pointer from evaluation of function-reference
  2021-04-24 16:37 ` Paul Richard Thomas
@ 2021-04-24 18:12   ` Harald Anlauf
  0 siblings, 0 replies; 3+ messages in thread
From: Harald Anlauf @ 2021-04-24 18:12 UTC (permalink / raw)
  To: Paul Richard Thomas; +Cc: fortran, gcc-patches

Hi Paul,

> Is there a test for an error with -std=f2003? If not, you should, perhaps, include one.

after checking for the corresponding error message, I found that
ptr-func-2.f90 already covers this case.  Considering this, I'll
rename the current testcase from pr100218.f90 to ptr-func-4.f90.

Thanks for the review!

Harald


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

end of thread, other threads:[~2021-04-24 18:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22 20:25 [Patch] PR fortran/100218 - target of pointer from evaluation of function-reference Harald Anlauf
2021-04-24 16:37 ` Paul Richard Thomas
2021-04-24 18:12   ` Harald Anlauf

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).