Quantcast
Viewing all articles
Browse latest Browse all 3270

PURE + ASSOCIATE + DO + ALLOCATE/DEALLOCATE

Hi,


There seems to be a compiler bug caused by the ASSOCIATE statement when used in a PURE procedure, as shown in the following code.

module mod1

    implicit none

    type :: mytype
        real, allocatable :: G(:,:,:)
        real, allocatable :: K(:,:,:)
        real, allocatable :: B(:,:,:)
    contains
        procedure :: myproc
    end type

contains
    !----------------------------------------------------------------------------------------------
    pure subroutine myproc(this, n)
        class(mytype), intent(INOUT) :: this
        integer, intent(IN) :: n

        real, allocatable :: XDATA(:), FDATA1(:), FDATA2(:)
        integer :: i, nz

    continue
        associate (G => this%G, K => this%K, B => this%B)

        do i = 1, n
            allocate (XDATA(nz), FDATA1(nz), FDATA2(nz))

            deallocate (XDATA, FDATA1, FDATA2)
        enddo

        end associate

    end subroutine

end module mod1

The errors shown are:

~$ ll `which ifort`
-rwxr-xr-x 1 root root 3955056 Jan 24 07:03 /opt/intel/composer_xe_2013_sp1.2.144/bin/intel64/ifort*
~$ ifort -c test_pure.f90 
test_pure.f90(26): error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure.   [XDATA]
            allocate (XDATA(nz), FDATA1(nz), FDATA2(nz))
----------------------^
test_pure.f90(26): error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure.   [FDATA1]
            allocate (XDATA(nz), FDATA1(nz), FDATA2(nz))
---------------------------------^
test_pure.f90(26): error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure.   [FDATA2]
            allocate (XDATA(nz), FDATA1(nz), FDATA2(nz))
---------------------------------------------^
test_pure.f90(28): error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure.   [XDATA]
            deallocate (XDATA, FDATA1, FDATA2)
------------------------^
test_pure.f90(28): error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure.   [FDATA1]
            deallocate (XDATA, FDATA1, FDATA2)
-------------------------------^
test_pure.f90(28): error #7146: This object must not be used as an allocate-object in an allocate-stmt or deallocate-stmt in a PURE procedure or an internal procedure contained in a PURE procedure.   [FDATA2]
            deallocate (XDATA, FDATA1, FDATA2)
---------------------------------------^
compilation aborted for test_pure.f90 (code 1)

Removing the PURE attribute, commenting the ASSOCIATE/END ASSOCIATE lines, or even moving the ALLOCATE/DEALLOCATE lines outside the loop, all make the error go away.




 


Viewing all articles
Browse latest Browse all 3270


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>