[Bug fortran/78990] New: ICE when assigning polymorphic array function result

2017-01-04 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78990

Bug ID: 78990
   Summary: ICE when assigning polymorphic array function result
   Product: gcc
   Version: 6.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cmacmackin at gmail dot com
  Target Milestone: ---

Created attachment 40459
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40459&action=edit
Minimal reproducer

When a function returns a polymorphic array which is to be assigned to a local
array (via defined assignment), gfortran experiences a segfault. I've attached
a minimal example, which produces an ICE in gfortran 6.2.0 and 5.4.1 (both from
the Ubuntu 16.04 repos, the former from the ubuntu-toolchain-r/test PPA). The
error message is as follows:

minimal.f90:36:0:

   v3 = return_t1(v1)

internal compiler error: Segmentation fault
0xa71b9f crash_signal
../../src/gcc/toplev.c:333
0x696d84 gfc_conv_array_stride(tree_node*, int)
../../src/gcc/fortran/trans-array.c:2776
0x696d84 gfc_trans_preloop_setup
../../src/gcc/fortran/trans-array.c:3528
0x69793a gfc_start_scalarized_body(gfc_loopinfo*, stmtblock_t*)
../../src/gcc/fortran/trans-array.c:3586
0x6ed5cf gfc_trans_call(gfc_code*, bool, tree_node*, tree_node*, bool)
../../src/gcc/fortran/trans-stmt.c:476
0x68ef73 trans_code
../../src/gcc/fortran/trans.c:1768
0x6b25dc gfc_generate_function_code(gfc_namespace*)
../../src/gcc/fortran/trans-decl.c:6167
0x64a800 translate_all_program_units
../../src/gcc/fortran/parse.c:5915
0x64a800 gfc_parse_file()
../../src/gcc/fortran/parse.c:6121
0x68c1c2 gfc_be_parse_file
../../src/gcc/fortran/f95-lang.c:201
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

Note that I'm not 100% certain that this is legal code (I don't have access to
any other compilers to check).

[Bug fortran/60913] [OOP] Memory leak with allocatable polymorphic function result (in type-bound operator)

2017-01-24 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60913

Chris  changed:

   What|Removed |Added

 CC||cmacmackin at gmail dot com

--- Comment #4 from Chris  ---
Has there been any progress on this bug? It is making a large piece of
scientific software I have written unusable for decent resolution simulations.

[Bug fortran/60913] [OOP] Memory leak with allocatable polymorphic function result (in type-bound operator)

2017-01-24 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60913

--- Comment #5 from Chris  ---
Has there been any progress on this bug? It is making a large piece of
scientific software I have written unusable for decent resolution simulations.
I'm running gfortran 6.1.0, compiled with OpenCoarrays support.

Also, I've reduced the size of the reproducer:


Module Groups

  Type, abstract :: Group
   CONTAINS
 Generic, Public :: Operator   (*) => prod
 Generic, Public :: Assignment (=) => equal

 Procedure (gpr), deferred :: prod
 Procedure (geq), deferred :: equal
  End type Group

  Type, extends (Group), abstract :: GaugeGroup
  End type GaugeGroup

  Abstract Interface
 Function gpr(a, b)
   Import :: Group

   Class (Group), Intent (in) :: a, b
   Class (Group), Allocatable :: gpr
 End Function gpr
  End Interface

  Abstract Interface
 Subroutine geq(a, b)
   Import :: Group

   Class (Group), Intent (in)  :: b
   Class (Group), Intent (out) :: a
 End Subroutine geq
  End Interface

End Module Groups


MODULE Group_SU2

  USE Groups

  IMPLICIT NONE

  ! Represent SU(2) element through quaternions
  ! (a_0, a_1, a_2, a_3)
  Type, Extends (GaugeGroup) :: SU2
 Real (kind=8) :: Comp(0:3)
   CONTAINS
 Procedure :: prod=> prodsu2
 Procedure :: equal   => equalSU2
  End Type SU2

CONTAINS

! ***
! *
  Subroutine EqualSU2(a, b)
! *
! ***
! * Equals g1 to g2
! ***

Class (SU2), Intent (out) :: a
Class (Group), Intent (in) :: b

select type (b)
class is (SU2)
   a%Comp(0:3) = b%Comp(0:3)
class default
   error stop
End select

Return
  End Subroutine EqualSU2

! ***
! *
  Function Prodsu2(a,b) Result(g3)
! *
! ***
! * Multiplies g1 by g2
! ***

Class (SU2),   Intent (in) :: a
Class (Group), Intent (in) :: b
Class (Group), allocatable :: g3

Allocate(SU2::g3)
select type (b)
class is (SU2)
   select type (g3)
   class is (SU2)
  g3%Comp(0) = a%Comp(0)*b%Comp(0) - &
   &   Dot_Product(a%Comp(1:3),b%Comp(1:3))

  g3%Comp(1) = a%Comp(0)*b%Comp(1) + a%Comp(1)*b%Comp(0) &
   & + a%Comp(2)*b%Comp(3) - a%Comp(3)*b%Comp(2)

  g3%Comp(2) = a%Comp(0)*b%Comp(2) - a%Comp(1)*b%Comp(3) &
   & + a%Comp(2)*b%Comp(0) + a%Comp(3)*b%Comp(1)

  g3%Comp(3) = a%Comp(0)*b%Comp(3) + a%Comp(1)*b%Comp(2) &
   & - a%Comp(2)*b%Comp(1) + a%Comp(3)*b%Comp(0)
   end select
class default
   error stop
end select

Return
  End Function Prodsu2

End MODULE GROUP_SU2


Program Testoo

  USE Groups
  USE Group_SU2

  type(SU2) :: g1, g2, g3

  ForAll (I=0:3) g1%comp(I) = 0.23_8*(I+1)
  ForAll (I=0:3) g2%comp(I) = 0.32_8*(I+1)

  Do I = 1, 2000
 g3=g1*g2
  End Do

  Stop
End Program Testoo

[Bug fortran/60913] [OOP] Memory leak with allocatable polymorphic function result (in type-bound operator)

2017-01-25 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60913

--- Comment #7 from Chris  ---
Damian, can you tell me where in the standard allocatable polymorphic results
are prohibited with pure functions? I've been using them that way in my code,
which compiles without issue using gfortran. I haven't tested it with another
compiler although coincidentally I was planning to do that later today.

I am aware of forall being declared deprecated. The example I posted was just a
shortened version of that used at the start of this report. I don't use forall
in my own code.

[Bug fortran/60913] [OOP] Memory leak with allocatable polymorphic function result (in type-bound operator)

2017-01-25 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60913

--- Comment #9 from Chris  ---
Last I heard, gfortran still doesn't invoke finalisation in this situation. In
any case, while (in my main code) I could certainly reduce the volume of leaked
memory via finalisation (by deallocating arrays contained in the derived type
variable), it wouldn't work to deallocate the variable itself.

[Bug fortran/78395] New: [OOP] ICE for operations with polymorphic variables

2016-11-17 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78395

Bug ID: 78395
   Summary: [OOP] ICE for operations with polymorphic variables
   Product: gcc
   Version: 6.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cmacmackin at gmail dot com
  Target Milestone: ---

Created attachment 40066
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40066&action=edit
Minimal code producing ICE.

While trying to produce a minimal example for an issue I've been having with
gfortran seeming to misidentify return types when I chain togethor certain
type-bound operators, I came across this ICE. I've attached the code which
produces the ICE. gfortran seems to run into trouble when parsing return types
for line 132. When I perform the same operations using non-polymorphic
variabels (as in line 131) there is no issue.

I am using a self-compiled gfortran-6 binary (compiled against the OpenCoarrays
library, although I'm not using any coarray features). Running "gfortran -v
minimal-abstract.f90" produces

Driving: gfortran -v minimal-abstract.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/home/macmackin/.local/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.1.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with:
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/configure
--prefix=/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/installations/gcc/6.1.0
--enable-languages=c,c++,fortran,lto --disable-multilib --disable-werror
Thread model: posix
gcc version 6.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /home/macmackin/.local/bin/../libexec/gcc/x86_64-pc-linux-gnu/6.1.0/f951
minimal-abstract.f90 -quiet -dumpbase minimal-abstract.f90 -mtune=generic
-march=x86-64 -auxbase minimal-abstract -version -fintrinsic-modules-path
/home/macmackin/.local/bin/../lib/gcc/x86_64-pc-linux-gnu/6.1.0/finclude -o
/tmp/macmackin/ccMxUT4H.s
GNU Fortran (GCC) version 6.1.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 6.1.0, GMP version 4.3.2, MPFR version 2.4.2,
MPC version 0.8.1, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (GCC) version 6.1.0 (x86_64-pc-linux-gnu)
compiled by GNU C version 6.1.0, GMP version 4.3.2, MPFR version 2.4.2,
MPC version 0.8.1, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
f951: internal compiler error: in gfc_add_component_ref, at fortran/class.c:245
0x60aaae gfc_add_component_ref(gfc_expr*, char const*)
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/class.c:245
0x67f528 resolve_typebound_function
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:6008
0x67f528 gfc_resolve_expr(gfc_expr*)
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:6351
0x631e1a gfc_extend_expr(gfc_expr*)
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/interface.c:3836
0x67f147 resolve_operator
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:3844
0x67f147 gfc_resolve_expr(gfc_expr*)
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:6333
0x685933 gfc_resolve_code(gfc_code*, gfc_namespace*)
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:10437
0x6880e2 resolve_codes
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:15554
0x6881d1 gfc_resolve(gfc_namespace*)
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/resolve.c:15588
0x6739da resolve_all_program_units
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/parse.c:5552
0x6739da gfc_parse_file()
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/parse.c:5804
0x6b4d15 gfc_be_parse_file
   
/home/macmackin/Code/OpenCoarrays-1.7.2/prerequisites/downloads/gcc-6.1.0/gcc/fortran/f95-lang.c:201
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <http://gcc.gnu.org/bugs.html> for instructions.


When I try compiling the same file with gfortran-4.8 I get

Driving: gfortran-4.8 -v minimal-abstract.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-4.8
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/con

[Bug fortran/78395] [OOP] ICE for operations with polymorphic variables

2016-11-17 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78395

--- Comment #4 from Chris  ---
I tried compiling (my original example) on a different box, this one with
gfortran 6.2.0 obtained from the ubuntu-toolchain-r/test PPA. I got

Driving: gfortran-6 -v minimal.f90 -l gfortran -l m -shared-libgcc
Using built-in specs.
COLLECT_GCC=gfortran-6
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
6.2.0-3ubuntu11~16.04' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs
--enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-6 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes
--with-default-libstdcxx-abi=new --enable-gnu-unique-object
--disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib
--disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-amd64/jre --enable-java-home
--with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 6.2.0 20160901 (Ubuntu 6.2.0-3ubuntu11~16.04) 
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/6/f951 minimal.f90 -quiet -dumpbase minimal.f90
-mtune=generic -march=x86-64 -auxbase minimal -version -fintrinsic-modules-path
/usr/lib/gcc/x86_64-linux-gnu/6/finclude -o /tmp/chris/ccDLOYCy.s
GNU Fortran (Ubuntu 6.2.0-3ubuntu11~16.04) version 6.2.0 20160901
(x86_64-linux-gnu)
compiled by GNU C version 6.2.0 20160901, GMP version 6.1.0, MPFR
version 3.1.4, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Fortran2008 (Ubuntu 6.2.0-3ubuntu11~16.04) version 6.2.0 20160901
(x86_64-linux-gnu)
compiled by GNU C version 6.2.0 20160901, GMP version 6.1.0, MPFR
version 3.1.4, MPC version 1.0.3, isl version 0.15
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
f951: internal compiler error: in gfc_add_component_ref, at fortran/class.c:241
0x5dede4 gfc_add_component_ref(gfc_expr*, char const*)
../../src/gcc/fortran/class.c:241
0x6564f1 resolve_typebound_function
../../src/gcc/fortran/resolve.c:6014
0x6564f1 gfc_resolve_expr(gfc_expr*)
../../src/gcc/fortran/resolve.c:6357
0x60730a gfc_extend_expr(gfc_expr*)
../../src/gcc/fortran/interface.c:3943
0x656064 resolve_operator
../../src/gcc/fortran/resolve.c:3850
0x656064 gfc_resolve_expr(gfc_expr*)
../../src/gcc/fortran/resolve.c:6339
0x65cab3 gfc_resolve_code(gfc_code*, gfc_namespace*)
../../src/gcc/fortran/resolve.c:10459
0x65f282 resolve_codes
../../src/gcc/fortran/resolve.c:15656
0x65f37e gfc_resolve(gfc_namespace*)
../../src/gcc/fortran/resolve.c:15691
0x64a62a resolve_all_program_units
../../src/gcc/fortran/parse.c:5854
0x64a62a gfc_parse_file()
../../src/gcc/fortran/parse.c:6106
0x68c1c2 gfc_be_parse_file
../../src/gcc/fortran/f95-lang.c:201
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See  for instructions.

Would there be some issue with the build which is causing the ICE for me? The
error message which you reported for gfortran 6.2.0 also doesn't make sense to
me, as I use defined-assignment to allocatable variables frequently in my code
without problem. Indeed, it is used a line or two earlier in the example I
provided.

[Bug fortran/78395] [OOP] ICE for operations with polymorphic variables

2016-11-17 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78395

--- Comment #6 from Chris  ---
> Which one do you mean exactly? Shouldn't they all use the user-defined 
> assignment function?

Yes, that's right--they all should. Sorry, I didn't have the code up in front
of me when I wrote that so I was a bit imprecise in what I was saying.

[Bug fortran/66409] New: Reporting ambiguous interface when overloading assignment with polymorphic array

2015-06-03 Thread cmacmackin at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66409

Bug ID: 66409
   Summary: Reporting ambiguous interface when overloading
assignment with polymorphic array
   Product: gcc
   Version: 4.9.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: fortran
  Assignee: unassigned at gcc dot gnu.org
  Reporter: cmacmackin at gmail dot com
  Target Milestone: ---

I have come across what I believe to be a bug (or possibly a misunderstanding
of the standard on one of our counts) in gfortran. I'm trying to overload the
assignment operator with two custom procedures:

module container_mod

interface assignment(=)
module procedure assign_to_variable
module procedure assign_to_variable_1d
end interface

contains

subroutine assign_to_variable (retval,input)
class(*), intent(inout) ::  retval
real, intent(in)::  input

return
end subroutine assign_to_variable

subroutine assign_to_variable_1d (retval_1d,input)
class(*), dimension(:), intent(inout)   ::  retval_1d
real, intent(in)::  input

return
end subroutine assign_to_variable_1d

end module container_mod

(In the real program where I do this, the input variable is a derived type.)
However, I am getting the compile-time error 

gfortran -Wall -c "dbg.f90"
dbg.f90:5.46:
module procedure assign_to_variable_1d
  1
Error: Ambiguous interfaces 'assign_to_variable_1d' and
'assign_to_variable' in intrinsic assignment operator at (1)

I've found that ifort 12.1.7.367 and pgfortran 8.0-6 both compile this just
fine. I've also found that, if I change the interface from assignment to just a
normal generic interface, it compiles properly. Finally, if I change the
unlimited polymorphic variables to anything else (a built-in variable type, a
derived type, or a non-unlimited polymorphic variable) it compiled without
problems.

It's also worth noting that, if I try to compile this with only the scalar
interface, gfortran complains when I try to use that to assign to an array. So
obviously the interface is not ambiguous when it comes to actually performing
the assignment.

I hope all of that's clear. I'll be happy to answer any questions or
clarifications.