[Bug fortran/90506] rejects-valid: function with polymorphic return type

2019-05-18 Thread fortranfan at outlook dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90506

Vipul Parekh  changed:

   What|Removed |Added

 CC||fortranfan at outlook dot com

--- Comment #2 from Vipul Parekh  ---
Here is a variant of the submitted case that also might be of interest here on
account of the internal compiler error (ICE) that occurs; an ICE makes it very
difficult for users. 

--- begin console output --- 
C:\Temp>type m.f90 
module m 
   type :: t 
   end type 
   abstract interface 
  function Ifun() result(r) 
 import :: t 
 class(t), allocatable :: r 
  end function 
   end interface 
   procedure(Ifun), pointer :: pfun => null() 
contains 
   function my_fun() result(r) 
  class(t), allocatable :: r 
  r = t() 
   end function 
   subroutine sub() 
  pfun => my_fun 
   end subroutine 
end 

C:\Temp>gfortran -c -Wall m.f90 
m.f90:17:0: 

   17 |   pfun => my_fun 
  | 
internal compiler error: Segmentation fault 
libbacktrace could not find executable to open 
Please submit a full bug report, 
with preprocessed source if appropriate. 
See <https://gcc.gnu.org/bugs/> for instructions. 

C:\Temp> 
--- end console output ---

[Bug fortran/84387] New: Defined output does not work for a derived type that has no components

2018-02-14 Thread fortranfan at outlook dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84387

Bug ID: 84387
   Summary: Defined output does not work for a derived type that
has no components
   Product: gcc
   Version: 8.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fortranfan at outlook dot com
  Target Milestone: ---

Consider the following:

--- begin console output ---
C:\Temp>type p.f90
module m

   type :: t
  private
  !integer :: m_i = 0  !<-- ***
   contains
  private
  procedure, pass(this) :: write_t
  generic, public :: write(formatted) => write_t
   end type

contains

   subroutine write_t(this, lun, iotype, vlist, istat, imsg)

  ! argument definitions
  class(t), intent(in):: this
  integer, intent(in) :: lun
  character(len=*), intent(in):: iotype
  integer, intent(in) :: vlist(:)
  integer, intent(out):: istat
  character(len=*), intent(inout) :: imsg

  write(lun, fmt=*, iostat=istat, iomsg=imsg) "Hello World!"

  return

   end subroutine write_t

end module

program p

   use m, only : t

   type(t) :: foo

   print "(dt)", foo !<-- or list-directed: print *, foo

end program

C:\Temp>gfortran p.f90 -o p.exe

C:\Temp>p.exe


C:\Temp>
--- end console output ---

Program run-time behavior suggests the defined output with the object foo with
type(t) is not executed. Is this intended?  I didn't notice anything in the
Fortran standard (10-007r1 document toward Fortran 2008) that suggests such a
behavior.  Program built with another compiler printed "Hello World!" as I
expected.

Fyi in case it is of any relevance: if the line marked *** above corresponding
to a component of type(t) is uncommented and the program is then rebuilt using
gfortran, the output is:

C:\Temp>p.exe
 Hello World!

Thanks for your time and attention,
Vipul Parekh

[Bug fortran/84389] New: Defined output: unexpected compiler error with the use of ":" edit descriptor

2018-02-14 Thread fortranfan at outlook dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84389

Bug ID: 84389
   Summary: Defined output: unexpected compiler error with the use
of ":" edit descriptor
   Product: gcc
   Version: 8.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fortranfan at outlook dot com
  Target Milestone: ---

Consider the following:

--- begin console output ---
C:\Temp>type p.f90
module m

   type :: t
  private
   contains
  private
  procedure, pass(this) :: write_t
  generic, public :: write(formatted) => write_t
   end type

contains

   subroutine write_t(this, lun, iotype, vlist, istat, imsg)

  ! argument definitions
  class(t), intent(in):: this
  integer, intent(in) :: lun
  character(len=*), intent(in):: iotype
  integer, intent(in) :: vlist(:)
  integer, intent(out):: istat
  character(len=*), intent(inout) :: imsg

  write(lun, fmt=*, iostat=istat, iomsg=imsg) "Hello World!"

  return

   end subroutine write_t

end module

program p

   use m, only : t

   type(t) :: foo(2)

   print "(*(dt:,','))", foo

end program

C:\Temp>gfortran p.f90 -o p.exe
p.f90:37:14:

print "(*(dt:,','))", foo
  1
Error: Unexpected element ':' in format string at (1)

C:\Temp>
--- end output ---

Program compiled and built using another toolset gives my expected output:
Hello World!,Hello World!


Cheers,

[Bug fortran/84389] Defined output: unexpected compiler error with the use of ":" edit descriptor

2018-02-15 Thread fortranfan at outlook dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84389

--- Comment #2 from Vipul Parekh  ---
Thank for your response.

Per section 1.4.1 in 10-007r1 toward Fortran 2008 on syntax rules toward the
BNF convention in the document, line 16 says [] encloses an optional item.

R1303 format-items  is format-item [ [ , ] format-item ]

then suggests the comma in the format item is optional and the format in the
first post should work as shown.

[Bug fortran/84472] New: Missing finalization and memory leak

2018-02-19 Thread fortranfan at outlook dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84472

Bug ID: 84472
   Summary: Missing finalization and memory leak
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fortranfan at outlook dot com
  Target Milestone: ---

Consider the following:

--- begin console output ---
C:\Temp>type m.f90
module m

   use, intrinsic :: iso_fortran_env, only : output_unit

   implicit none

   private

   type :: t
  private
  character(len=:), pointer :: m_s => null()
   contains
  private
  final :: final_t
  procedure, pass(this), public :: clean => clean_t
  procedure, pass(this), public :: init => init_t
   end type

   interface t
  module procedure :: construct_t
   end interface

   public :: t

contains

   function construct_t( name ) result(new_t)

  ! argument list
  character(len=*), intent(in), optional :: name
  ! function result
  type(t) :: new_t

  if ( present(name) ) then
 call new_t%init( name )
  end if

   end function

   subroutine final_t( this )

  ! argument list
  type(t), intent(inout) :: this

  write( output_unit, fmt="(g0)", advance="no" ) "finalizer invoked"
  if ( associated(this%m_s) ) then
 write( output_unit, fmt=* ) "for object ", trim(this%m_s)
  else
 write( output_unit, fmt=* )
  end if
  call clean_t( this )

   end subroutine

   subroutine clean_t( this )

  ! argument list
  class(t), intent(inout) :: this

  if ( associated(this%m_s) ) then
 deallocate( this%m_s )
  end if
  this%m_s => null()

   end subroutine

   subroutine init_t( this, name )

  ! argument list
  class(t), intent(inout)  :: this
  character(len=*), intent(in) :: name

  call this%clean()
  allocate( this%m_s, source=name )

   end subroutine

end module

C:\Temp>gfortran -c -Wall -std=f2008ts m.f90

C:\Temp>type p.f90
program p

   use m, only : t

   implicit none

   type(t) :: foo

   call foo%init( name="123" )

   foo = t( name="foo" )

   call foo%clean()

   stop

end program

C:\Temp>gfortran -c -Wall -std=f2008ts p.f90

C:\Temp>gfortran m.o p.o -o p.exe

C:\Temp>p.exe

C:\Temp>"C:\Program Files (x86)\Dr. Memory\bin\drmemory.exe" -- p.exe
-show_reachable
~~Dr.M~~ Dr. Memory version 1.11.0
~~Dr.M~~ (Uninitialized read checking is not yet supported for 64-bit)
~~Dr.M~~ Running "p.exe -show_reachable"
~~Dr.M~~
~~Dr.M~~ Error #1: LEAK 3 direct bytes 0x03101da0-0x03101da3 +
0
 indirect bytes
~~Dr.M~~ # 0 replace_malloc
[d:\drmemory_package\common\allo
c_replace.c:2576]
~~Dr.M~~ # 1 insert
[../../../gcc-8-20180204-mingw/l
ibgfortran/io/unit.c:206]
~~Dr.M~~ # 2 _gfortrani_fbuf_init  
[../../../gcc-8-20180204-mingw/l
ibgfortran/io/fbuf.c:42]
~~Dr.M~~ # 3 __m_MOD_init_t
~~Dr.M~~ # 4 MAIN__
~~Dr.M~~ # 5 main
~~Dr.M~~
~~Dr.M~~ ERRORS FOUND:
~~Dr.M~~   0 unique, 0 total unaddressable access(es)
~~Dr.M~~   0 unique, 0 total invalid heap argument(s)
~~Dr.M~~   0 unique, 0 total GDI usage error(s)
~~Dr.M~~   0 unique, 0 total handle leak(s)
~~Dr.M~~   0 unique, 0 total warning(s)
~~Dr.M~~   1 unique, 1 total,  3 byte(s) of leak(s)
~~Dr.M~~   0 unique, 0 total,  0 byte(s) of possible leak(s)
~~Dr.M~~ ERRORS IGNORED:
~~Dr.M~~   2 potential error(s) (suspected false positives)
~~Dr.M~~  (details: C:\Users\parekhv\AppData\Roaming\Dr.
Memory\DrMemory
-p.exe.14260.000\potential_errors.txt)
~~Dr.M~~   3 unique, 4 total,246 byte(s) of still-reachable
allocati
on(s)
~~Dr.M~~  (re-run with "-show_reachable" for details)
~~Dr.M~~ Details: C:\Users\parekhv\AppData\Roaming\Dr.
Memory\DrMemory-p.exe.142
60.000\results.txt

C:\Temp>
--- end console output ---


Per section '4.5.6.3 When finalization occurs' of document 10-007r1 toward
Fortran 2008 standard, for an instruction such as 'foo = t( name="foo" )' in
the program shown above, one can expect finalization to occur for object foo
before it gets redefined and also for the entity created by the function with
generic interface t.  Thus the expected program output is:
finalizer invoked for object 123
finalizer invoked for object foo

In addition, I would expect the program to not leak any memory, but as shown
above there is a leak of 3 bytes which may correspond to the above-mentioned
missing finalization for the initial object foo.

Thank you for your time and attention.

Best Regards,

[Bug fortran/104520] New: Unexpected behavior with STORAGE_SIZE intrinsic with a dummy argument that is unlimited polymorphic

2022-02-13 Thread fortranfan at outlook dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104520

Bug ID: 104520
   Summary: Unexpected behavior with STORAGE_SIZE intrinsic with a
dummy argument that is unlimited polymorphic
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: fortranfan at outlook dot com
  Target Milestone: ---

Consider the following:

--- begin code ---
module m
   use, intrinsic :: iso_fortran_env, only : character_storage_size
contains
   subroutine sub( a )
  class(*), intent(in) :: a
  print *, "storage_size(s) = ", storage_size(a)
  select type ( a )
 type is ( character(len=*) )
print *, "expected is ", len(a)*character_storage_size
  end select
   end subroutine 
end module
   use m 
   character(len=2) :: s
   call sub( s )
end
--- end code ---

And the program behavior using gfortran:
--- begin console output ---
C:\temp>gfortran -Wall y.f90 -o y.exe

C:\temp>y.exe
 storage_size(s) =8
 expected is   16

C:\temp>
--- end output ---

On the other hand, consider the following:

--- begin code ---
   character(len=2) :: s
   print *, storage_size(s)
end
--- end code ---

The program behavior is

--- begin output ---
C:\temp>gfortran -Wall y.f90 -o y.exe

C:\temp>y.exe
  16

C:\temp>
--- end output ---

I failed to find anything in the Fortran standard that supports the above shown
program behavior.  Can the first case with the unlimited polymorphic dummy be
expected to the same as the second, meaning the storage size of the object get
determined as 16 bits?

Thank you,
Vipul Parekh