GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 41599 - [OOP] SELECT TYPE with associate-name => exp: Use (sometimes) a restricted pointer
Summary: [OOP] SELECT TYPE with associate-name => exp: Use (sometimes) a restricted po...
Status: WAITING
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2009-10-06 07:58 UTC by Tobias Burnus
Modified: 2013-06-16 22:14 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-06-16 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2009-10-06 07:58:24 UTC
Currently, an unrestricted pointer is generated. It should be an restricted pointer if the expression is not a POINTER or TARGET.

One has to be careful, however:

class(t),allocatable :: bar
allocate(t::a%bar)
select type (foo => bar)
  is type(t)
    foo%item = 8
    bar%item = 9
Here, both items alias - I do not know whether this code is valid or not, however.

Ditto for

type t2
  class(t) :: bar
end type t2
type(t2) :: a
allocate(t::a%bar)
select type (foo => a%bar)
  is type(t)
    foo%item = 8
    a%bar%item = 9

Similarly for:

type t2
  class(t),allocatable :: bar
end type t2
type(t2), pointer :: a
allocate(a)
allocate(t::a%bar)
select type (foo => a%bar)
  is type(t)
    foo%item = 8
    a%bar%item = 9

Thus before fixing this, one needs to read the standard carefully.
Comment 1 Tobias Burnus 2009-10-06 07:59:49 UTC
Cross reference: "SELECT TYPE (name => expr)" was initially implemented with the patch at http://gcc.gnu.org/ml/fortran/2009-10/msg00049.html
Comment 2 Tobias Burnus 2009-12-14 10:34:57 UTC
See also PR 41600
Comment 3 Dominique d'Humieres 2013-06-16 22:14:49 UTC
Both

type t
  integer :: item
end type
!type(t),allocatable :: a
class(t),allocatable :: bar
allocate(t::bar)
!allocate(t::a%bar)
select type (foo => bar)
    type is (t)
    foo%item = 8
    bar%item = 9
    print *, foo%item, bar%item
end select
end

and

type t
  integer :: item
  integer, allocatable :: bar
end type
type t2
  class(t),allocatable :: bar
end type t2
type(t2), pointer :: a
allocate(a)
allocate(t::a%bar)
select type (foo => a%bar)
  type is (t)
    foo%item = 8
    a%bar%item = 9
    print *, foo%item, a%bar%item
end select
end

prints

           9           9

It is what I'ld expect, but I don't know if the codes are valid.
Compiling

type t
  integer :: item
  integer, allocatable :: bar
end type
type t2
  class(t) :: bar
end type t2
type(t2) :: a
allocate(t::a%bar)
select type (foo => a%bar)
  type is (t)
    foo%item = 8
    a%bar%item = 9
end select
end

gives an ICE

Program received signal SIGSEGV, Segmentation fault.
0x00000001000b9cc2 in gfc_type_compatible (ts1=<value optimized out>, ts2=<value optimized out>) at ../../work/gcc/fortran/symbol.c:4483
4483	      && ts1->u.derived->components->ts.u.derived->attr.unlimited_polymorphic)
(gdb) bt
#0  0x00000001000b9cc2 in gfc_type_compatible (ts1=<value optimized out>, ts2=<value optimized out>) at ../../work/gcc/fortran/symbol.c:4483
#1  0x000000010006b413 in gfc_match_allocate () at ../../work/gcc/fortran/match.c:3552
#2  0x000000010007f61a in match_word (subr=<value optimized out>, old_locus=0x7fff5fbfd330, str=<value optimized out>)
    at ../../work/gcc/fortran/parse.c:65
#3  0x0000000100081ff5 in decode_statement () at ../../work/gcc/fortran/parse.c:383
#4  0x000000010008253a in next_statement () at ../../work/gcc/fortran/parse.c:784
#5  0x000000010008335d in parse_spec (st=<value optimized out>) at ../../work/gcc/fortran/parse.c:2741
#6  0x0000000100085599 in parse_progunit (st=<value optimized out>) at ../../work/gcc/fortran/parse.c:4121
#7  0x00000001000866cc in gfc_parse_file () at ../../work/gcc/fortran/parse.c:4637
#8  0x00000001000c6ea6 in gfc_be_parse_file () at ../../work/gcc/fortran/f95-lang.c:189
#9  0x000000010078dd54 in compile_file () at ../../work/gcc/toplev.c:544
#10 0x000000010078fe49 in toplev_main (argc=2, argv=0x7fff5fbfd718) at ../../work/gcc/toplev.c:1872
#11 0x000000010000a804 in start (pc=<value optimized out>, bases=0x0) at ../../../work/libgcc/config/unwind-dw2-fde-darwin.c:272