View previous topic :: View next topic |
Author |
Message |
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Thu Nov 07, 2013 11:20 am Post subject: DEALLOCATE |
|
|
The following program allocates memory to two arrays ia and ib. It then attempts to deallocate the memory in ib, but after (admittedly confusingly) renaming it ia in the USE statement. However, it is actually ia that gets deallocated. That seems to me to be a bug.
Code: | ! This program appears to deallocate the wrong array.
MODULE m1
INTEGER, DIMENSION(:), ALLOCATABLE :: ia
INTEGER, DIMENSION(:), ALLOCATABLE :: ib
END MODULE m1
MODULE m2
CONTAINS
SUBROUTINE s1 ()
USE m1, ONLY: ia
ALLOCATE (ia(2))
END SUBROUTINE s1
SUBROUTINE s2 ()
USE m1, ONLY: ib
ALLOCATE (ib(2))
END SUBROUTINE s2
SUBROUTINE s3 ()
USE m1, ONLY: ia=>ib
DEALLOCATE (ia)
END SUBROUTINE s3
END MODULE m2
PROGRAM p
USE m1
USE m2
CALL s1 ()
CALL s2 ()
CALL s3 ()
PRINT *, ALLOCATED(ia),ALLOCATED(ib)
END PROGRAM p
|
Last edited by simon on Mon Nov 11, 2013 8:34 pm; edited 1 time in total |
|
Back to top |
|
|
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Nov 07, 2013 6:36 pm Post subject: |
|
|
This looks like a bug to me too. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7929 Location: Salford, UK
|
Posted: Mon Nov 11, 2013 11:18 am Post subject: |
|
|
I agree. I have logged it for investigation. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7929 Location: Salford, UK
|
Posted: Thu Apr 03, 2014 11:48 am Post subject: |
|
|
This bug has now been fixed for the next release. |
|
Back to top |
|
|
simon
Joined: 05 Jul 2006 Posts: 268
|
Posted: Sat Feb 11, 2017 1:16 am Post subject: |
|
|
My notes indicate that this problem was fixed in version 7.10, but it seems to have resurfaced: I'm using version 8.05. I don't know whether the problem occurred in 7.20 or 8.00. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7929 Location: Salford, UK
|
Posted: Sat Feb 11, 2017 9:43 am Post subject: |
|
|
I will take another look at this as soon as I can. |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7929 Location: Salford, UK
|
Posted: Sat Feb 18, 2017 10:17 am Post subject: |
|
|
It turns out that this is a known regression.
The original fix has been removed because it caused a more serious problem elsewhere.
For now at least, I suggest that you avoid using a name for a local variable (ia in this case) when this name has already been used in a parent module.
Code: | SUBROUTINE s3 ()
USE m1, ONLY: iaa=>ib
DEALLOCATE (iaa)
END SUBROUTINE s3 |
|
|
Back to top |
|
|
|