Bug 36671 - [4.4 Regression]: gfortran.dg/associated_1.f90
Summary: [4.4 Regression]: gfortran.dg/associated_1.f90
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.4.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Richard Biener
URL:
Keywords: alias, wrong-code
: 36682 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-06-29 21:05 UTC by H.J. Lu
Modified: 2008-07-01 01:54 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-06-30 09:51:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2008-06-29 21:05:43 UTC
Revision 137252:

http://gcc.gnu.org/ml/gcc-patches/2008-06/msg01883.html

caused

FAIL: gfortran.dg/associated_1.f90  -O1  execution test
Comment 1 Dominique d'Humieres 2008-06-29 22:12:54 UTC
Confirmed on i686-apple-darwin9. The following modified code

! { dg-do run }
! PR 25292: Check that the intrinsic associated works with functions returning
! pointers as arguments
program test
   real, pointer :: a, b

   nullify(a,b)
   if(associated(a,b).or.associated(a,a)) call abort()
   allocate(a)
   if(associated(b,a)) call abort()
   print *, associated(x(a)), associated(a, x(a))
!   if (.not.associated(x(a))) call abort ()
!   if (.not.associated(a, x(a))) call abort ()

   nullify(b)
   print *, associated(x(b))
!   if (associated(x(b))) call abort ()
   allocate(b)
   if (associated(x(b), x(a))) call abort ()

contains

  function x(a) RESULT(b)
    real, pointer :: a,b
    b => a
  end function x

end program test

gives at -O1

[ibook-dhum] f90/bug% a.out
 F F
 T

Comment 2 Richard Biener 2008-06-30 09:51:50 UTC
The problem is that the function x has the MALLOC flag.  Why is this so?  This
causes the use of the argument memory to be missed.

I see in generic trans-decl.c code

/* Get a basic decl for an external function.  */

tree
gfc_get_extern_function_decl (gfc_symbol * sym)
{
...

  /* If the return type is a pointer, avoid alias issues by setting
     DECL_IS_MALLOC to nonzero. This means that the function should be
     treated as if it were a malloc, meaning it returns a pointer that
     is not an alias.  */
  if (POINTER_TYPE_P (type))
    DECL_IS_MALLOC (fndecl) = 1;



static void
build_function_decl (gfc_symbol * sym)
{
...

  /* If the return type is a pointer, avoid alias issues by setting
     DECL_IS_MALLOC to nonzero. This means that the function should be
     treated as if it were a malloc, meaning it returns a pointer that
     is not an alias.  */
  if (POINTER_TYPE_P (type))
    DECL_IS_MALLOC (fndecl) = 1;


I guess I'll have to re-organize the code to not ignore arguments to
malloc functions.

Anyway, the patch only uncovered this latent problem :(
Comment 3 Richard Biener 2008-06-30 11:40:29 UTC
Fixed.
Comment 4 Richard Biener 2008-06-30 11:40:41 UTC
Subject: Bug 36671

Author: rguenth
Date: Mon Jun 30 11:39:53 2008
New Revision: 137271

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=137271
Log:
2008-06-30  Richard Guenther  <rguenther@suse.de>

	PR middle-end/36671
	* tree-ssa-structalias.c (handle_lhs_call): Add flags argument,
	handle calls from ECF_MALLOC functions.
	(handle_pure_call): ECF_MALLOC functions do not return
	call-used memory.
	(find_func_aliases): Handle all calls, adjust calls to handle_lhs_call.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-ssa-structalias.c

Comment 5 Andrew Pinski 2008-07-01 01:54:41 UTC
*** Bug 36682 has been marked as a duplicate of this bug. ***