public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31258]  New: segfault with transpose(reshape(char))
@ 2007-03-18 22:28 tkoenig at gcc dot gnu dot org
  2007-03-21  0:01 ` [Bug fortran/31258] " fxcoudert at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-03-18 22:28 UTC (permalink / raw)
  To: gcc-bugs

In trying to reduce PR 31197, I stumbled across a segfault:

$ cat bar.f90
CHARACTER(LEN=3), DIMENSION(10) :: Z
CHARACTER(LEN=10) :: res
Z(:)="123"
write(*,'(10A1)') TRANSPOSE(RESHAPE(Z(:)(2:2),(/5,2/)))
END
...
(gdb) r bar.f90
Starting program: /home/ig25/libexec/gcc/i686-pc-linux-gnu/4.3.0/f951 bar.f90
Failed to read a valid object file image from memory.
 MAIN__
Program received signal SIGSEGV, Segmentation fault.
0x080ccca3 in gfc_conv_function_call (se=0xbf8680e0, sym=0x880f9e8,
    arg=0x8849650, append_args=0x0)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-expr.c:2032
2032      need_interface_mapping = ((sym->ts.type == BT_CHARACTER
(gdb) bt
#0  0x080ccca3 in gfc_conv_function_call (se=0xbf8680e0, sym=0x880f9e8,
    arg=0x8849650, append_args=0x0)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-expr.c:2032
#1  0x080d7edb in gfc_conv_intrinsic_funcall (se=0xbf8680e0, expr=0x8849c78)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-intrinsic.c:1514
#2  0x080cd407 in gfc_conv_function_expr (se=0xbf8680e0, expr=0x880f9e8)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-expr.c:2657
#3  0x080cdb89 in gfc_conv_expr (se=0xbf8680e0, expr=0x8849c78)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-expr.c:3097
#4  0x080b9ebd in gfc_add_loop_ss_code (loop=0xbf8681ec, ss=0x880f900,
    subscript=0 '\0') at /home/ig25/gcc/trunk/gcc/fortran/trans-array.c:1803
#5  0x080ba766 in gfc_conv_loop_setup (loop=0xbf8681ec)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-array.c:3232
#6  0x080db6fc in gfc_trans_transfer (code=0x884a2f0)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-io.c:1850
#7  0x080b17a9 in gfc_trans_code (code=0x884a2f0)
    at /home/ig25/gcc/trunk/gcc/fortran/trans.c:605
#8  0x080ddc04 in build_dt (function=0xb7bba310, code=0x884a3b0)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-io.c:1507
#9  0x080b17cb in gfc_trans_code (code=0x884a3b0)
    at /home/ig25/gcc/trunk/gcc/fortran/trans.c:581
#10 0x080c75e3 in gfc_generate_function_code (ns=0x8848d50)
    at /home/ig25/gcc/trunk/gcc/fortran/trans-decl.c:3217

...


-- 
           Summary: segfault with transpose(reshape(char))
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
@ 2007-03-21  0:01 ` fxcoudert at gcc dot gnu dot org
  2007-04-08  8:40 ` pault at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-21  0:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-03-21 00:01 -------
(In reply to comment #0)
> CHARACTER(LEN=3), DIMENSION(10) :: Z
> CHARACTER(LEN=10) :: res
> Z(:)="123"
> write(*,'(10A1)') TRANSPOSE(RESHAPE(Z(:)(2:2),(/5,2/)))
> END

Same thing happens with
  write(*,'(10A1)') RESHAPE(Z(:)(2:2),(/5,2/))

The segfault is due to the reshape symbol not having a charlen, and this is in
turn due to the source argument of RESHAPE (that is Z(:)(2:)) not having a
charlen itself: gfc_resolve_reshape simply copies the typespec of the source
arg into the result.


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-21 00:01:01
               date|                            |


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
  2007-03-21  0:01 ` [Bug fortran/31258] " fxcoudert at gcc dot gnu dot org
@ 2007-04-08  8:40 ` pault at gcc dot gnu dot org
  2007-05-27  9:04 ` tkoenig at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-04-08  8:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pault at gcc dot gnu dot org  2007-04-08 09:40 -------
This fixes this PR and PR31197.  It needs some work because it still fails with
variable expressions in the string length and I need to figure out which other
intrinsics, if any, need the same treatment.

Paul

Index: /svn/trunk/gcc/fortran/iresolve.c
===================================================================
*** /svn/trunk/gcc/fortran/iresolve.c   (revision 123646)
--- /svn/trunk/gcc/fortran/iresolve.c   (working copy)
*************** gfc_resolve_reshape (gfc_expr *f, gfc_ex
*** 1722,1727 ****
--- 1722,1755 ----
        break;
      }

+   if (source->ts.type == BT_CHARACTER
+       && source->ref != NULL)
+     {
+       gfc_ref *ref;
+       for (ref = source->ref; ref; ref = ref->next)
+       if (ref->next == NULL && ref->type == REF_SUBSTRING)
+         break;
+       if (ref != NULL)
+       {
+         f->ts.type = BT_CHARACTER;
+         f->ts.kind = gfc_default_character_kind;
+         f->ts.cl = gfc_get_charlen ();
+         f->ts.cl->next = gfc_current_ns->cl_list;
+         gfc_current_ns->cl_list = f->ts.cl;
+         f->ts.cl->length = gfc_get_expr ();
+         f->ts.cl->length->expr_type = EXPR_OP;
+         f->ts.cl->length->value.op.operator = INTRINSIC_PLUS;
+         f->ts.cl->length->value.op.op1 = gfc_get_expr ();
+         f->ts.cl->length->value.op.op1->expr_type = EXPR_OP;
+         f->ts.cl->length->value.op.op1->value.op.operator = INTRINSIC_MINUS;
+         f->ts.cl->length->value.op.op1->value.op.op1 = gfc_copy_expr
(ref->u.ss.end);
+         f->ts.cl->length->value.op.op1->value.op.op2 = gfc_copy_expr
(ref->u.ss.start);
+
+         f->ts.cl->length->value.op.op2 =  gfc_int_expr (1);
+         gfc_simplify_expr (f->ts.cl->length, 0);
+       }
+     }
+
    /* TODO: Make this work with a constant ORDER parameter.  */
    if (shape->expr_type == EXPR_ARRAY
        && gfc_is_constant_expr (shape)


-- 


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
  2007-03-21  0:01 ` [Bug fortran/31258] " fxcoudert at gcc dot gnu dot org
  2007-04-08  8:40 ` pault at gcc dot gnu dot org
@ 2007-05-27  9:04 ` tkoenig at gcc dot gnu dot org
  2007-05-27  9:06 ` tkoenig at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-05-27  9:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from tkoenig at gcc dot gnu dot org  2007-05-27 09:04 -------
The problem seems to extend to pretty much all array intrinsics:

$ gfortran cshift.f90
cshift.f90: In function 'MAIN__':
cshift.f90:3: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


$ cat eoshift.f90
CHARACTER(LEN=3), DIMENSION(10) :: Z
CHARACTER(LEN=10) :: res
Z(:)="123"
write(*,'(10A1)') EOSHIFT(Z(:)(2:2),2)
END
$ gfortran eoshift.f90
eoshift.f90: In function 'MAIN__':
eoshift.f90:3: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


$ cat spread.f90
CHARACTER(LEN=3), DIMENSION(10) :: Z
CHARACTER(LEN=10) :: res
Z(:)="123"
write(*,'(10A1)') SPREAD(Z(:)(2:2),dim=1,ncopies=2)
END
$ gfortran spread.f90
spread.f90: In function 'MAIN__':
spread.f90:3: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


$ cat transpose.f90
CHARACTER(LEN=3), DIMENSION(10,10) :: Z
CHARACTER(LEN=10) :: res
Z(:,:)="123"
write(*,'(10A1)') TRANSPOSE(Z(:,:)(2:2))
END
$ gfortran transpose.f90
transpose.f90: In function 'MAIN__':
transpose.f90:3: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


-- 

tkoenig at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu dot org


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-05-27  9:04 ` tkoenig at gcc dot gnu dot org
@ 2007-05-27  9:06 ` tkoenig at gcc dot gnu dot org
  2007-05-27 10:28 ` tkoenig at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-05-27  9:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from tkoenig at gcc dot gnu dot org  2007-05-27 09:06 -------
I forgot the source code for the cshift case:

$ cat cshift.f90
CHARACTER(LEN=3), DIMENSION(10) :: Z
CHARACTER(LEN=10) :: res
Z(:)="123"
write(*,'(10A1)') CSHIFT(Z(:)(2:2),2)
END
$ gfortran cshift.f90
cshift.f90: In function 'MAIN__':
cshift.f90:3: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


-- 


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-05-27  9:06 ` tkoenig at gcc dot gnu dot org
@ 2007-05-27 10:28 ` tkoenig at gcc dot gnu dot org
  2007-06-11 12:54 ` pault at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2007-05-27 10:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from tkoenig at gcc dot gnu dot org  2007-05-27 10:28 -------
pack and unpack are also affected:

$ cat pack.f90
CHARACTER(LEN=3), DIMENSION(10,10) :: Z
CHARACTER(LEN=10) :: res
Z="123"
write(*,'(10A1)') pack(Z(:,:)(2:2),mask=.true.)
END
$ gfortran pack.f90
pack.f90: In function 'MAIN__':
pack.f90:3: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

$ cat unpack.f90
CHARACTER(LEN=3), DIMENSION(10) :: Z
logical, dimension(5,2) :: mask
CHARACTER(LEN=10) :: res
Z(:)="123"
mask = .true.
write(*,'(10A1)') unpack(Z(:)(2:2),mask,' ')
END
$ gfortran unpack.f90
unpack.f90: In function 'MAIN__':
unpack.f90:5: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.


-- 


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-05-27 10:28 ` tkoenig at gcc dot gnu dot org
@ 2007-06-11 12:54 ` pault at gcc dot gnu dot org
  2007-08-30 22:11 ` pault at gcc dot gnu dot org
  2007-08-30 22:14 ` pault at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-06-11 12:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pault at gcc dot gnu dot org  2007-06-11 12:54 -------
A fix is coming for this tonight or tomorrow.

Paul


-- 

pault at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |pault at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-03-21 00:01:01         |2007-06-11 12:54:18
               date|                            |


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2007-06-11 12:54 ` pault at gcc dot gnu dot org
@ 2007-08-30 22:11 ` pault at gcc dot gnu dot org
  2007-08-30 22:14 ` pault at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-08-30 22:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pault at gcc dot gnu dot org  2007-08-30 22:11 -------
Subject: Bug 31258

Author: pault
Date: Thu Aug 30 22:10:55 2007
New Revision: 127939

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127939
Log:
2007-08-31  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/31879
        PR fortran/31197
        PR fortran/31258
        PR fortran/32703
        * gfortran.h : Add prototype for gfc_resolve_substring_charlen.
        * resolve.c (gfc_resolve_substring_charlen): New function.
        (resolve_ref): Call gfc_resolve_substring_charlen.
        (gfc_resolve_character_operator): New function.
        (gfc_resolve_expr): Call the new functions in cases where the
        character length is missing.
        * iresolve.c (cshift, eoshift, merge, pack, reshape, spread,
        transpose, unpack): Call gfc_resolve_substring_charlen for
        source expressions that are character and have a reference.
        * trans.h (gfc_trans_init_string_length) Change name to
        gfc_conv_string_length; modify references in trans-expr.c,
        trans-array.c and trans-decl.c.
        * trans-expr.c (gfc_trans_string_length): Handle case of no
        backend_decl.
        (gfc_conv_aliased_arg): Remove code for treating substrings
        and replace with call to gfc_trans_string_length.
        * trans-array.c (gfc_conv_expr_descriptor): Remove code for
        treating strings and call gfc_trans_string_length instead.

2007-08-31  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/31879
        * gfortran.dg/char_length_7.f90: New test.
        * gfortran.dg/char_length_9.f90: New test.
        * gfortran.dg/char_assign_1.f90: Add extra warning.

        PR fortran/31197
        PR fortran/31258
        * gfortran.dg/char_length_8.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/char_length_7.f90
    trunk/gcc/testsuite/gfortran.dg/char_length_8.f90
    trunk/gcc/testsuite/gfortran.dg/char_length_9.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/gfortran.h
    trunk/gcc/fortran/iresolve.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/char_assign_1.f90


-- 


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


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

* [Bug fortran/31258] segfault with transpose(reshape(char))
  2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2007-08-30 22:11 ` pault at gcc dot gnu dot org
@ 2007-08-30 22:14 ` pault at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-08-30 22:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pault at gcc dot gnu dot org  2007-08-30 22:13 -------
Fixed on trunk.

Thanks for the report!

Paul


-- 

pault at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2007-08-30 22:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-18 22:28 [Bug fortran/31258] New: segfault with transpose(reshape(char)) tkoenig at gcc dot gnu dot org
2007-03-21  0:01 ` [Bug fortran/31258] " fxcoudert at gcc dot gnu dot org
2007-04-08  8:40 ` pault at gcc dot gnu dot org
2007-05-27  9:04 ` tkoenig at gcc dot gnu dot org
2007-05-27  9:06 ` tkoenig at gcc dot gnu dot org
2007-05-27 10:28 ` tkoenig at gcc dot gnu dot org
2007-06-11 12:54 ` pault at gcc dot gnu dot org
2007-08-30 22:11 ` pault at gcc dot gnu dot org
2007-08-30 22:14 ` pault 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).