Bug 51082 - [F03] Wrong result for a pointer to a proc-pointer component
Summary: [F03] Wrong result for a pointer to a proc-pointer component
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-11-10 14:56 UTC by Tobias Burnus
Modified: 2012-04-15 11:52 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-11-10 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-11-10 14:56:59 UTC
The following program reported at #gfortran shall print twice "1.0" but with gfortran, it just prints:

   1.00000000
At line 23 of file pp.f90 (unit = 6, file = 'stdout')
Internal Error: bad real kind


If one looks at the dump, one sees:

  p_list.process = ala1;
  p = &p_list;

with the call being:
      D.1841 = p_list.process (&C.1840);
      _gfortran_transfer_real_write (&dt_parm.0, &D.1841, 4);

      D.1844 = p->process (&C.1843);
      _gfortran_transfer_real_write (&dt_parm.1, D.1844, 4);

Notice in particular that for the second case, one has "D.1844" instead of "&D.1844".


program ala
   implicit none

   type process_list
      procedure(process_interface), pointer, nopass :: process
      type(process_list), pointer :: next => null()
   end type process_list

   abstract interface
      real function process_interface(x)
         real, intent(in) :: x
      end function process_interface
   end interface

   type(process_list), target  :: p_list
   type(process_list), pointer :: p


   p_list%process => ala1
   p => p_list

   write(*,*) p_list%process(1.0)
   write(*,*) p%process(1.0)     !!!! fails with gfortran

   contains
      real function ala1(x)
         implicit none
         real, intent(in) :: x
         ala1 = x
      end function ala1
end program ala
Comment 1 janus 2011-11-10 20:04:55 UTC
Note: The following variant works.



program ala
  implicit none

  type process_list
    procedure(ala1), pointer, nopass :: process
  end type

  type(process_list), target  :: p_list
  type(process_list), pointer :: p
  real :: r

  p_list%process => ala1
  p => p_list

  r = p%process(1.0)
  write(*,*) r

contains

  real function ala1(x)
    real, intent(in) :: x
    ala1 = x
  end function ala1

end program ala
Comment 2 janus 2011-11-10 21:02:34 UTC
Fix:


Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(revision 181240)
+++ gcc/fortran/trans-expr.c	(working copy)
@@ -5019,7 +5019,7 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * e
       && ((expr->value.function.esym
 	   && expr->value.function.esym->result->attr.pointer
 	   && !expr->value.function.esym->result->attr.dimension)
-	  || (!expr->value.function.esym
+	  || (!expr->value.function.esym && !expr->ref
 	      && expr->symtree->n.sym->attr.pointer
 	      && !expr->symtree->n.sym->attr.dimension)))
     {
Comment 3 janus 2012-04-13 14:23:25 UTC
Note: The patch in comment #2 regtests cleanly.
Comment 4 janus 2012-04-15 11:47:55 UTC
Author: janus
Date: Sun Apr 15 11:47:49 2012
New Revision: 186465

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186465
Log:
2012-04-15  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/51082
	* trans-expr.c (gfc_conv_expr_reference): Check if the expression is a
	simple function call (or a more involved PPC reference).


2012-04-15  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/51082
	* gfortran.dg/proc_ptr_comp_34.f90: New test case.

Added:
    trunk/gcc/testsuite/gfortran.dg/proc_ptr_comp_34.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 janus 2012-04-15 11:52:41 UTC
Fixed with r186465. Closing.