public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/43990]  New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
@ 2010-05-05  9:27 janus at gcc dot gnu dot org
  2010-05-05 12:41 ` [Bug fortran/43990] " burnus at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-05  9:27 UTC (permalink / raw)
  To: gcc-bugs

module m

  type :: t
     logical :: l = .true.
     class(t),pointer :: cp => null()
  end type

  type(t),save :: default_t

end module


Compiling this currently results in:

f951: internal compiler error: in output_constructor_regular_field, at
varasm.c:4995


Reported by Hans-Werner Boschmann.


-- 
           Summary: [OOP] ICE in output_constructor_regular_field, at
                    varasm.c:4995
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
@ 2010-05-05 12:41 ` burnus at gcc dot gnu dot org
  2010-05-05 14:13 ` burnus at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-05-05 12:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2010-05-05 12:41 -------
  if ((local->field != NULL_TREE || local->index != NULL_TREE)
      && fieldpos != local->total_bytes)
    {
      gcc_assert (fieldpos >= local->total_bytes);

Debugging shows:
  field != NULL_TREE, index == NULL_TREE
  fieldpos = 0 >= 4 = local->total_bytes


If one sets a break point at 5327, one gets 7 times:
  #0  output_constructor (exp=0x2aaaaac16200, size=32, align=256, outer=0x0) at
gcc/gcc/varasm.c:5327
but then one gets
  Breakpoint 1, output_constructor (exp=0x2aaaaac16160, size=24, align=128,
outer=0x0) at gcc/gcc/varasm.c:5327
which is the case with the ICE; only in the latter case there is field !=
NULL_TREE. The variable has then the following value - and in particular offset
== 0 and thus also fieldpos == 0.

 <field_decl 0x2aaaaac2c098 l
    type <boolean_type 0x2aaaaab58b28 logical(kind=4) public unsigned SI
        size <integer_cst 0x2aaaaab36960 constant 32>
        unit size <integer_cst 0x2aaaaab36668 constant 4>
        align 32 symtab 0 alias set -1 canonical type 0x2aaaaab58b28 precision
1 min <integer_cst 0x2aaaaab553c0 0> max <integer_cst 0x2aaaaab55410 1>>
    unsigned SI file test.f90 line 4 col 0 size <integer_cst 0x2aaaaab36960 32>
unit size <integer_cst 0x2aaaaab36668 4>
    align 32 offset_align 128
    offset <integer_cst 0x2aaaaab36690 type <integer_type 0x2aaaaab45000>
constant 0>
    bit offset <integer_cst 0x2aaaaab36d98 type <integer_type 0x2aaaaab450a8
bit_size_type> constant 0> context <record_type 0x2aaaaac28498 t> chain
<field_decl 0x2aaaaac2c130 cp>>

(gdb) call debug_tree(exp)
 <constructor 0x2aaaaac16160
    type <record_type 0x2aaaaac28498 t BLK
        size <integer_cst 0x2aaaaab55190 constant 192>
        unit size <integer_cst 0x2aaaaab55140 constant 24>
        align 64 symtab 0 alias set -1 canonical type 0x2aaaaac28498
        fields <field_decl 0x2aaaaac2c098 l type <boolean_type 0x2aaaaab58b28
logical(kind=4)>
            unsigned SI file test.f90 line 4 col 0
            size <integer_cst 0x2aaaaab36960 constant 32>
            unit size <integer_cst 0x2aaaaab36668 constant 4>
            align 32 offset_align 128
            offset <integer_cst 0x2aaaaab36690 constant 0>
            bit offset <integer_cst 0x2aaaaab36d98 constant 0> context
<record_type 0x2aaaaac28498 t> chain <field_decl 0x2aaaaac2c130 cp>>
        pointer_to_this <pointer_type 0x2aaaaac28738> chain <type_decl
0x2aaaaab5f730 D.1544>>
    constant lngt 2 idx <field_decl 0x2aaaaac2c098 l>
    val <integer_cst 0x2aaaaab55410 type <boolean_type 0x2aaaaab58b28
logical(kind=4)> constant 1>
    idx <field_decl 0x2aaaaac24ed8 $data
        type <pointer_type 0x2aaaaac28738 type <record_type 0x2aaaaac28498 t>
            public unsigned DI
            size <integer_cst 0x2aaaaab36a28 constant 64>
            unit size <integer_cst 0x2aaaaab36a50 constant 8>
            align 64 symtab 0 alias set -1 canonical type 0x2aaaaac28738>
        unsigned DI file test.f90 line 5 col 0 size <integer_cst 0x2aaaaab36a28
64> unit size <integer_cst 0x2aaaaab36a50 8>
        align 64 offset_align 128 offset <integer_cst 0x2aaaaab36690 0> bit
offset <integer_cst 0x2aaaaab36d98 0> context <record_type 0x2aaaaac28540
.class.t.p>
        chain <field_decl 0x2aaaaac2c000 $vptr type <pointer_type
0x2aaaaac28690>
            unsigned DI file test.f90 line 5 col 0 size <integer_cst
0x2aaaaab36a28 64> unit size <integer_cst 0x2aaaaab36a50 8>
            align 64 offset_align 128 offset <integer_cst 0x2aaaaab36690 0> bit
offset <integer_cst 0x2aaaaab36a28 64> context <record_type 0x2aaaaac28540
.class.t.p>>>
    val <integer_cst 0x2aaaaac27910 type <pointer_type 0x2aaaaac28738> constant
0>>


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
  2010-05-05 12:41 ` [Bug fortran/43990] " burnus at gcc dot gnu dot org
@ 2010-05-05 14:13 ` burnus at gcc dot gnu dot org
  2010-05-06 16:28 ` burnus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-05-05 14:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from burnus at gcc dot gnu dot org  2010-05-05 14:12 -------
The problem seems to be the initialization at gfc_conv_structure (init = 1) in
trans-expr.c:

We have:
     logical :: l = .true.
     class(t),pointer :: cp => null()
and thus:

(gdb) p expr->ts.u.derived->components->name
$12 = 0x2aaaaab41ea8 "l"
(gdb) p expr->ts.u.derived->components->next->name
$13 = 0x2aaaaab41eb8 "cp"
(gdb) p expr->ts.u.derived->components->next->ts.type
$14 = BT_CLASS
(gdb) p expr->ts.u.derived->components->next->attr.pointer
$15 = 0

The later is simply not true: We have a pointer.

      if (cm->ts.type == BT_CLASS && !cm->attr.proc_pointer)
        {
          gfc_component *data;
          data = gfc_find_component (cm->ts.u.derived, "$data", true, true);

Somehow this gives the wrong result in terms of the offset, i.e. one tries to
initialize:

t.l at position (&t + (0 byte)) and then one tries to initialize t.$data (!) at
(&t + 0)  but it should be (&t + 4) - or (&(t.class) + 0).

The following patch fixes the problem, though I have the feeling it papers over
some logic problem (cf. below):

--- a/gcc/fortran/trans-expr.c
+++ b/gcc/fortran/trans-expr.c
@@ -4328,10 +4328,9 @@ gfc_conv_structure (gfc_se * se, gfc_expr * expr, int
init)
        c; c = gfc_constructor_next (c), cm = cm->next)
     {
       /* Skip absent members in default initializers and allocatable
-        components.  Although the latter have a default initializer
-        of EXPR_NULL,... by default, the static nullify is not needed
-        since this is done every time we come into scope.  */
-      if (!c->expr || cm->attr.allocatable)
+        components, and NULL initialization of pointers, which are
+        automatically handled through zero initialization.  */
+      if (!c->expr || cm->attr.allocatable || c->expr->expr_type == EXPR_NULL)
         continue;

       if (cm->ts.type == BT_CLASS && !cm->attr.proc_pointer)

(By the way, the comment above looked bogus: "since this is done every time we
come in scope" is only true if the variable is STATIC just due to
-fmax-stack-var-size. Otherwise, it will be ("only") zero initialized through
"= {}".)

 * * *

The "fix" above is likely to break if one uses
  <type>, pointer :: ptr => nonNULLtarget
(allowed since Fortran 2008) where the RHS can be something different than
EXPR_NULL. The problem seems to be that already the class struct is a pointer
and not only its content, i.e. "t.class.$data = NULL" vs. "t.class == NULL". Or
maybe only the reference goes wrong; cf. t.class.$data (OK) vs. t.$data
(wrong).


F2008 has:

R442 component-initialization is = constant-expr
                              or => null-init
                              or => initial-data-target
R443 initial-data-target is designator
C461 (R443) The designator shall designate a nonallocatable variable that has
the TARGET and SAVE attributes and does not have a vector subscript. Every
subscript, section subscript, substring starting point, and substring ending
point in designator shall be a constant expression."

 * * *

Failing dump (for PROGRAM - not shown for MODULE):
  static struct t default_t = {.l=1, .$data=0B};
working with the patch above:
  static struct t default_t = {.l=1};


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu dot org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-05-05 14:12:54
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
  2010-05-05 12:41 ` [Bug fortran/43990] " burnus at gcc dot gnu dot org
  2010-05-05 14:13 ` burnus at gcc dot gnu dot org
@ 2010-05-06 16:28 ` burnus at gcc dot gnu dot org
  2010-05-06 16:37 ` burnus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-05-06 16:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2010-05-06 16:27 -------
See also PR 43895 - the issue seems to be similar though one does not have an
except that there one has no static-memory initialization. [I might also be
completely off.]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-05-06 16:28 ` burnus at gcc dot gnu dot org
@ 2010-05-06 16:37 ` burnus at gcc dot gnu dot org
  2010-05-16 22:11 ` janus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-05-06 16:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from burnus at gcc dot gnu dot org  2010-05-06 16:37 -------
(In reply to comment #3)
> See also PR 43895

As I feared there: There seems to be an inconsistency with CLASS with POINTER
or ALLOCATABLE attribute: Is "class.$DATA" or "class" the pointer variable. If
one adds "b = ALLOCATED(x)" one finds:

  x.a.$data = 0B;   ! Default initialization sets class.$data to NULL
  D.1577 = &x->a;   ! ALLOCATED check looks at "(class != NULL)"
  b = D.1577 != 0B;

Which does not make sense.  [This might be unrelated to the ICE.]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-05-06 16:37 ` burnus at gcc dot gnu dot org
@ 2010-05-16 22:11 ` janus at gcc dot gnu dot org
  2010-05-17 17:09 ` dominiq at lps dot ens dot fr
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-16 22:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from janus at gcc dot gnu dot org  2010-05-16 22:11 -------
The ICE is fixed by removing this unneeded (and buggy) piece of code:

Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c    (revision 159444)
+++ gcc/fortran/trans-expr.c    (working copy)
@@ -4337,21 +4337,8 @@ gfc_conv_structure (gfc_se * se, gfc_expr * expr,
       if (!c->expr || cm->attr.allocatable)
         continue;

-      if (cm->ts.type == BT_CLASS && !cm->attr.proc_pointer)
+      if (strcmp (cm->name, "$size") == 0)
        {
-         gfc_component *data;
-         data = gfc_find_component (cm->ts.u.derived, "$data", true, true);
-         if (!data->backend_decl)
-           gfc_get_derived_type (cm->ts.u.derived);
-         val = gfc_conv_initializer (c->expr, &cm->ts,
-                                     TREE_TYPE (data->backend_decl),
-                                     data->attr.dimension,
-                                     data->attr.pointer);
-
-         CONSTRUCTOR_APPEND_ELT (v, data->backend_decl, val);
-       }
-      else if (strcmp (cm->name, "$size") == 0)
-       {
          val = TYPE_SIZE_UNIT (gfc_get_derived_type (cm->ts.u.derived));
          CONSTRUCTOR_APPEND_ELT (v, cm->backend_decl, val);
        }


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |janus at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2010-05-05 14:12:54         |2010-05-16 22:11:03
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-05-16 22:11 ` janus at gcc dot gnu dot org
@ 2010-05-17 17:09 ` dominiq at lps dot ens dot fr
  2010-05-17 17:41 ` janus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: dominiq at lps dot ens dot fr @ 2010-05-17 17:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dominiq at lps dot ens dot fr  2010-05-17 17:09 -------
The patch in comment #5 fixes the ICE without side effects (AFAICT!-), but it
does not fix PR43895 (see comments #3 and #4).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-05-17 17:09 ` dominiq at lps dot ens dot fr
@ 2010-05-17 17:41 ` janus at gcc dot gnu dot org
  2010-05-17 19:59 ` janus at gcc dot gnu dot org
  2010-05-17 20:05 ` janus at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-17 17:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from janus at gcc dot gnu dot org  2010-05-17 17:41 -------
(In reply to comment #6)
> but it does not fix PR43895 (see comments #3 and #4).

... which I take as an indication that the two are indeed not so much related.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2010-05-17 17:41 ` janus at gcc dot gnu dot org
@ 2010-05-17 19:59 ` janus at gcc dot gnu dot org
  2010-05-17 20:05 ` janus at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-17 19:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from janus at gcc dot gnu dot org  2010-05-17 19:59 -------
Subject: Bug 43990

Author: janus
Date: Mon May 17 19:58:48 2010
New Revision: 159511

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159511
Log:
2010-05-17  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/43990
        * trans-expr.c (gfc_conv_structure): Remove unneeded and buggy code.
        This is now handled via 'gfc_class_null_initializer'.


2010-05-17  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/43990
        * gfortran.dg/class_21.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_21.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

* [Bug fortran/43990] [OOP] ICE in output_constructor_regular_field, at varasm.c:4995
  2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2010-05-17 19:59 ` janus at gcc dot gnu dot org
@ 2010-05-17 20:05 ` janus at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-05-17 20:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from janus at gcc dot gnu dot org  2010-05-17 20:05 -------
Fixed with r159511. Closing.


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43990


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

end of thread, other threads:[~2010-05-17 20:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-05  9:27 [Bug fortran/43990] New: [OOP] ICE in output_constructor_regular_field, at varasm.c:4995 janus at gcc dot gnu dot org
2010-05-05 12:41 ` [Bug fortran/43990] " burnus at gcc dot gnu dot org
2010-05-05 14:13 ` burnus at gcc dot gnu dot org
2010-05-06 16:28 ` burnus at gcc dot gnu dot org
2010-05-06 16:37 ` burnus at gcc dot gnu dot org
2010-05-16 22:11 ` janus at gcc dot gnu dot org
2010-05-17 17:09 ` dominiq at lps dot ens dot fr
2010-05-17 17:41 ` janus at gcc dot gnu dot org
2010-05-17 19:59 ` janus at gcc dot gnu dot org
2010-05-17 20:05 ` janus at gcc dot gnu dot org

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).