public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran, F08] PR 49562: [4.6/4.7 Regression] [OOP] assigning value to type-bound function
@ 2011-06-28 15:53 Janus Weil
  2011-07-01 14:29 ` Janus Weil
  2011-07-02  8:29 ` Paul Richard Thomas
  0 siblings, 2 replies; 4+ messages in thread
From: Janus Weil @ 2011-06-28 15:53 UTC (permalink / raw)
  To: gfortran, gcc-patches

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

Hi all,

here is a patch for a problem which was originally reported as an
ICE-on-invalid regression (assigning to a type-bound function).

In the course of fixing it, I noticed that it becomes valid according
to F08 if the function is pointer-valued, and modified the patch such
that it will accept this variant. I also adapted the original test
case to be a run-time test of this F08 feature (in fact it is just a
very complicated way of performing an increment from 0 to 1, and would
still segfault without the patch).

The patch was regtested on x86_64-unknown-linux-gnu. Ok for trunk and 4.6.2?

Cheers,
Janus



2011-06-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/49562
	* expr.c (gfc_check_vardef_context): Handle type-bound procedures.


2011-06-28  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/49562
	* gfortran.dg/typebound_proc_23.f90: New.

[-- Attachment #2: pr49562.diff --]
[-- Type: text/x-diff, Size: 896 bytes --]

Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c	(revision 175580)
+++ gcc/fortran/expr.c	(working copy)
@@ -4394,8 +4394,8 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe
       sym = e->value.function.esym ? e->value.function.esym : e->symtree->n.sym;
     }
 
-  if (!pointer && e->expr_type == EXPR_FUNCTION
-      && sym->result->attr.pointer)
+  attr = gfc_expr_attr (e);
+  if (!pointer && e->expr_type == EXPR_FUNCTION && attr.pointer)
     {
       if (!(gfc_option.allow_std & GFC_STD_F2008))
 	{
@@ -4432,7 +4432,6 @@ gfc_check_vardef_context (gfc_expr* e, bool pointe
 
   /* Find out whether the expr is a pointer; this also means following
      component references to the last one.  */
-  attr = gfc_expr_attr (e);
   is_pointer = (attr.pointer || attr.proc_pointer);
   if (pointer && !is_pointer)
     {

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

! { dg-do compile }
!
! PR 49562: [4.6/4.7 Regression] [OOP] assigning value to type-bound function
!
! Contributed by Hans-Werner Boschmann <boschmann@tp1.physik.uni-siegen.de>

module ice
  type::ice_type
   contains
     procedure::ice_func
  end type
  integer, target :: it = 0
contains
  function ice_func(this)
    integer, pointer :: ice_func
    class(ice_type)::this
    ice_func => it
  end function ice_func
  subroutine ice_sub(a)
    class(ice_type)::a
    a%ice_func() = 1
  end subroutine ice_sub
end module

use ice
type(ice_type) :: t
if (it/=0) call abort()
call ice_sub(t)
if (it/=1) call abort()
end

! { dg-final { cleanup-modules "ice" } }

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

end of thread, other threads:[~2011-07-02 12:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-28 15:53 [Patch, Fortran, F08] PR 49562: [4.6/4.7 Regression] [OOP] assigning value to type-bound function Janus Weil
2011-07-01 14:29 ` Janus Weil
2011-07-02  8:29 ` Paul Richard Thomas
2011-07-02 12:21   ` Janus Weil

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