Bug 55887 - [OOP][F08] ICE with CLASS and data-target pointer association in (default) initialization
Summary: [OOP][F08] ICE with CLASS and data-target pointer association in (default) in...
Status: RESOLVED DUPLICATE of bug 55207
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code, patch
Depends on:
Blocks: 51076 45290
  Show dependency treegraph
 
Reported: 2013-01-06 14:52 UTC by Tobias Burnus
Modified: 2014-03-15 11:12 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-26 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2013-01-06 14:52:53 UTC
Follow up to PR 55763 comment 14/15.

For CLASS(t) and CLASS(*), gfortran ICEs for pointer default initializers/ initializers which point to a data target instead of NULL.

Example:

    type t
    end type t
    type(t), target :: x
    class(*), pointer :: ptr2 => x
    if (same_type_as (ptr2, x) .neqv. .TRUE.) call abort()
  end


That's a Fortran 2008 feature. (Cf. also PR51076, PR45290 and PR50410 comment 9.)
Comment 1 Tilo Schwarz 2013-01-24 19:16:25 UTC
I don't know how much help this actually is, but on my machine this commit

commit a90fe8299d2e635e53ab006c934154289d06ffa1
Author: pault <pault@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Thu Dec 20 00:15:00 2012 +0000

    2012-12-19  Paul Thomas  <pault@gcc.gnu.org>
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194622 138bc75d-0d04-0410-961f-82ee72b054a4


gives an ICE, but one commit earlier


commit 873f242d97571e98acad8ea1912f81682bd7a448
Author: burnus <burnus@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Wed Dec 19 23:05:49 2012 +0000

    2012-12-19  Tobias Burnus  <burnus@net-b.de>
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@194621 138bc75d-0d04-0410-961f-82ee72b054a4


does not.


Regards,
Tilo
Comment 2 janus 2013-01-26 21:10:15 UTC
The type(t) version ...

  type t
  end type t
  type(t), target :: x
  type(t), pointer :: ptr2 => x
  if (.not. same_type_as (ptr2, x)) call abort()
end

... is rejected by 4.7 with (note the wrong locus):

  type t
        1
Error: Pointer initialization target at (1) must have the SAVE attribute


but trunk gives yet another ICE:

internal compiler error: in symtab_get_node, at symtab.c:277


I think the error message of 4.7 is not triggered on trunk, because 'x' gets the SAVE_IMPLICIT attribute. The ICE goes away when giving 'x' the SAVE attribute explicitly.
Comment 3 janus 2013-01-26 21:21:38 UTC
This patch fixes the ICE in comment 0:


Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 195486)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -1484,6 +1484,12 @@ gfc_get_symbol_decl (gfc_symbol * sym)
       && (gfc_option.coarray != GFC_FCOARRAY_LIB
 	  || !sym->attr.codimension || sym->attr.allocatable))
     {
+      bool pointer;
+      if (sym->ts.type == BT_CLASS)
+	pointer = CLASS_DATA (sym)->attr.class_pointer
+		  || CLASS_DATA (sym)->attr.allocatable;
+      else
+	pointer = sym->attr.pointer || sym->attr.allocatable;
       /* Add static initializer. For procedures, it is only needed if
 	 SAVE is specified otherwise they need to be reinitialized
 	 every time the procedure is entered. The TREE_STATIC is
@@ -1493,8 +1499,7 @@ gfc_get_symbol_decl (gfc_symbol * sym)
 						  sym->attr.dimension
 						  || (sym->attr.codimension
 						      && sym->attr.allocatable),
-						  sym->attr.pointer
-						  || sym->attr.allocatable,
+						  pointer,
 						  sym->attr.proc_pointer);
     }
Comment 4 janus 2013-07-31 13:09:21 UTC
PR 57036 is very much related to this one ...
Comment 5 janus 2013-07-31 13:10:04 UTC
(In reply to janus from comment #4)
> PR 57036 is very much related to this one ...

Sorry, that should have been: PR 57306
Comment 6 janus 2013-08-09 08:34:14 UTC
After fixing PR 57306, the original ICE here is gone and both test cases work if one explicitly gives the target the SAVE attribute (otherwise there is another ICE).

In fact the target should implicitly get the SAVE attribute, which is what PR 55207 is about. Once that is fixed, also the remaining ICE here should be gone.
Comment 7 Dominique d'Humieres 2014-03-15 11:12:13 UTC
> In fact the target should implicitly get the SAVE attribute, which is 
> what PR 55207 is about. Once that is fixed, also the remaining ICE here 
> should be gone.

It is. Closing as duplicate.

*** This bug has been marked as a duplicate of bug 55207 ***