public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* FINAL subroutines
@ 2022-01-24 13:50 Salvatore Filippone
  2022-01-24 14:49 ` Salvatore Filippone
  0 siblings, 1 reply; 10+ messages in thread
From: Salvatore Filippone @ 2022-01-24 13:50 UTC (permalink / raw)
  To: Fortran List

[-- Attachment #1: Type: text/plain, Size: 2162 bytes --]

Hi all
The attached code compiles and runs fine under both GNU and Intel, but it
produces different results, in particular the FINAL subroutine is invoked
just once with GNU, three times with Intel.

It seems to me that they cannot both be right; I am not sure what the
standard is mandating in this case.
Any ideas?
Salvatore
---------------  Intel
[pr1eio03@login1: newstuff]$ ifort -v
ifort version 19.1.1.217
[pr1eio03@login1: newstuff]$ ifort -o testfinal testfinal.f90
[pr1eio03@login1: newstuff]$ ./testfinal
 Allocating wrapper
 Calling new_outer_type
 Assigning outer%test_item
 Called delete_test_type
 Called delete_test_type
 End of new_outer_type
 DeAllocating wrapper
 Called delete_test_type
----------------------------- GNU
sfilippo@lagrange newstuff]$ gfortran -v
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=
http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix
--enable-checking=release --enable-multilib --with-system-zlib
--enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin
--enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-11.2.1-20210728/obj-x86_64-redhat-linux/isl-install
--enable-offload-targets=nvptx-none --without-cuda-driver
--enable-gnu-indirect-function --enable-cet --with-tune=generic
--with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)
[sfilippo@lagrange newstuff]$ gfortran -o testfinal testfinal.f90
[sfilippo@lagrange newstuff]$ ./testfinal
 Allocating wrapper
 Calling new_outer_type
 Assigning outer%test_item
 End of new_outer_type
 DeAllocating wrapper
 Called delete_test_type
---------------------

[-- Attachment #2: testfinal.f90 --]
[-- Type: text/x-fortran, Size: 1460 bytes --]

module test_type_mod

  type :: my_test_type
    integer, allocatable :: i
  contains
    final :: delete_test_type
  end type my_test_type

  interface my_test_type
    module procedure  new_test_type_object
  end interface my_test_type

contains

  subroutine delete_test_type(this)
    type(my_test_type) :: this

    write(*,*) 'Called delete_test_type'
    if (allocated(this%i)) deallocate(this%i)

  end subroutine delete_test_type
    
  
  function new_test_type_object(item) result(res)
    type(my_test_type)  :: res
    integer, intent(in) :: item
    !Allocation on assignment
    res%i=item
  end function new_test_type_object


end module test_type_mod

module target_mod
  use test_type_mod
  type :: outer_type
    type(my_test_type), allocatable  :: test_item
  end type outer_type
  
contains

  subroutine new_outer_type(outer,item)
    type(outer_type), intent(out) :: outer
    integer :: item
    
    allocate(outer%test_item)
    write(*,*) 'Assigning outer%test_item'
    outer%test_item = my_test_type(itemi)
    write(*,*) 'End of new_outer_type'
  end subroutine new_outer_type

end module target_mod

program testfinal
  use target_mod

  implicit none

  integer :: i=10
  type(outer_type), allocatable  :: wrapper

  write(*,*) 'Allocating wrapper '
  allocate(wrapper)
  write(*,*) 'Calling new_outer_type '  
  call new_outer_type(wrapper,i)
  write(*,*) 'DeAllocating wrapper '
  deallocate(wrapper)
  
end program testfinal

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-01-28  9:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 13:50 FINAL subroutines Salvatore Filippone
2022-01-24 14:49 ` Salvatore Filippone
2022-01-24 15:45   ` Andrew Benson
2022-01-24 16:11     ` Salvatore Filippone
2022-01-26 21:29       ` Jerry D
2022-01-26 22:59         ` Paul Richard Thomas
2022-01-27  7:17           ` Salvatore Filippone
2022-01-27 22:10             ` Paul Richard Thomas
2022-01-28  8:05               ` Salvatore Filippone
2022-01-28  9:01                 ` Paul Richard Thomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).