pointer args. to subroutine (different answer in 5.2)

Hi,
I don’t know if this qualifies as a compiler bug, but the following little program gives different answer in version 5.2 of the compiler than in 5.0 or 5.1:

program test
  real ,dimension(:), pointer :: a
  real, target :: e(2)

  a => e
  a(1) = 1
  a(2) = 3
  print*, 'a=',a
  call sub(a,a)
  print*, 'a=',a
end program test

subroutine sub(x,y)
  real x(2),y(2)
  y = x+1
  return
end subroutine sub

With the new version of the compiler I get:
[ols@dhcp4154 tmp]$ pgf90 -V -g test.f90

pgf90 5.2-2
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2004, STMicroelectronics, Inc. All Rights Reserved.
PGF90/any Linux/x86 5.2-2
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2004, STMicroelectronics, Inc. All Rights Reserved.
PGF90/x86 Linux/x86 5.2-2
Copyright 1989-2000, The Portland Group, Inc. All Rights Reserved.
Copyright 2000-2004, STMicroelectronics, Inc. All Rights Reserved.
[ols@dhcp4154 tmp]$ ./a.out
a= 1.000000 3.000000
a= 1.000000 3.000000

while in the 5.1 release I get the expected result (2.0, 4.0) in the second output line. This only happens when I declare A as a pointer; with A an ordinary array I get the expected result.

So am I using pointers incorrectly or is this a compiler bug?

Oystein

The code works in 5.2-1, but fails with 5.2-2, so we obviously have a bug. The good news is that this has been fixed as part of the upcoming 5.2-4 release. Once available, I would recommend upgrading.

Thanks for the great example!

  • Mat