public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/31193]  New: ICE on count(transfer(...)...), with non-constant transfer arguments.
@ 2007-03-16  4:38 brooks at gcc dot gnu dot org
  2007-03-16  6:54 ` [Bug fortran/31193] ICE on non-constant character tranfert fxcoudert at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: brooks at gcc dot gnu dot org @ 2007-03-16  4:38 UTC (permalink / raw)
  To: gcc-bugs

There are known problems with attempts at folding TRANSFER in constant
expressions.  However, the following code doesn't involve this, and should work
properly even if folding of TRANSFER simply bails out without attempting to
fold anything.  Instead, it gives an ICE (in the middle-end, not in the Fortran
front-end).

debian-gfortran:~/test> more awgrey2.f90
function NumOccurances(string,chr) result(n)
  character(*),intent(in) :: string
  character(1),intent(in) :: chr
!
! return number of occurances of character in given string
!
    n=count(transfer(string,char(1),len(string))==chr)
  return
end

debian-gfortran:~/test> ~/bin-trunk/bin/gfortran awgrey2.f90
awgrey2.f90: In function 'numoccurances':
awgrey2.f90:1: internal compiler error: in fold_binary, at fold-const.c:8999
Please submit a full bug report,

debian-gfortran:~/test> ~/bin-trunk/bin/gfortran --version
GNU Fortran (GCC) 4.3.0 20070307 (experimental)


-- 
           Summary: ICE on count(transfer(...)...), with non-constant
                    transfer arguments.
           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: brooks at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu


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


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

* [Bug fortran/31193] ICE on non-constant character tranfert
  2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
@ 2007-03-16  6:54 ` fxcoudert at gcc dot gnu dot org
  2007-03-21 15:22 ` pault at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-16  6:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from fxcoudert at gcc dot gnu dot org  2007-03-16 06:54 -------
Further reduced testcase:
  character(5) :: string
  print *, transfer(string,"a",5)
  end

The ICE happens because the front-end generates a MULT_EXPR with a NULL second
argument, in trans-array.c:

  if (size && !callee_alloc)
    {
      /* If or_expr is true, then the extent in at least one
         dimension is zero and the size is set to zero.  */
      size = fold_build3 (COND_EXPR, gfc_array_index_type,
                          or_expr, gfc_index_zero_node, size);

      nelem = size;
      size = fold_build2 (MULT_EXPR, gfc_array_index_type, size,
                          TYPE_SIZE_UNIT (gfc_get_element_type (type)));
    }

For some reason, TYPE_SIZE_UNIT (gfc_get_element_type (type)) is NULL, while
type is:

 <record_type 0xb7c4ce38 array1_unknown type_1 BLK
    size <integer_cst 0xb7be1708 type <integer_type 0xb7bf0068 bit_size_type>
constant invariant 192>
    unit size <integer_cst 0xb7be1720 type <integer_type 0xb7bf0000> constant
invariant 24>
    align 32 symtab 0 alias set -1 canonical type 0xb7c4cb60
    fields <field_decl 0xb7c4905c data
        type <pointer_type 0xb7bf0958 type <void_type 0xb7bf08f0 void>
            public unsigned SI
            size <integer_cst 0xb7be1330 constant invariant 32>
            unit size <integer_cst 0xb7be1168 constant invariant 4>
            align 32 symtab 0 alias set -1 canonical type 0xb7bf0958
            pointer_to_this <pointer_type 0xb7bf8bc8>>
        unsigned SI file u.f90 line 1 size <integer_cst 0xb7be1330 32> unit
size <integer_cst 0xb7be1168 4>
        align 32 offset_align 128
        offset <integer_cst 0xb7be1180 constant invariant 0>
        bit offset <integer_cst 0xb7be1540 constant invariant 0> context
<record_type 0xb7c4cb60 array_descriptor1>
        chain <field_decl 0xb7c490b8 offset type <integer_type 0xb7bf02d8 int4>
            SI file u.f90 line 1 size <integer_cst 0xb7be1330 32> unit size
<integer_cst 0xb7be1168 4>
            align 32 offset_align 128 offset <integer_cst 0xb7be1180 0> bit
offset <integer_cst 0xb7be1330 32> context <record_type 0xb7c4cb60
array_descriptor1> chain <field_decl 0xb7c49114 dtype>>>>


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
  GCC build triplet|i686-pc-linux-gnu           |
      Known to fail|                            |4.3.0 4.2.0
   Last reconfirmed|0000-00-00 00:00:00         |2007-03-16 06:54:45
               date|                            |
            Summary|ICE on                      |ICE on non-constant
                   |count(transfer(...)...),    |character tranfert
                   |with non-constant transfer  |
                   |arguments.                  |


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


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

* [Bug fortran/31193] ICE on non-constant character tranfert
  2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
  2007-03-16  6:54 ` [Bug fortran/31193] ICE on non-constant character tranfert fxcoudert at gcc dot gnu dot org
@ 2007-03-21 15:22 ` pault at gcc dot gnu dot org
  2007-03-22 13:31 ` patchapp at dberlin dot org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-03-21 15:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pault at gcc dot gnu dot org  2007-03-21 15:22 -------
This fixes it

Index: gcc/fortran/trans-intrinsic.c
===================================================================
*** gcc/fortran/trans-intrinsic.c       (revision 123059)
--- gcc/fortran/trans-intrinsic.c       (working copy)
*************** gfc_conv_intrinsic_array_transfer (gfc_s
*** 2829,2834 ****
--- 2829,2835 ----
    tree extent;
    tree source;
    tree source_bytes;
+   tree mold_type;
    tree dest_word_len;
    tree size_words;
    tree size_bytes;
*************** gfc_conv_intrinsic_array_transfer (gfc_s
*** 2934,2953 ****
    if (ss == gfc_ss_terminator)
      {
        gfc_conv_expr_reference (&argse, arg->expr);
-
-       /* Obtain the source word length.  */
        tmp = gfc_size_in_bytes (&argse, arg->expr);
      }
    else
      {
        gfc_init_se (&argse, NULL);
        argse.want_pointer = 0;
        gfc_conv_expr_descriptor (&argse, arg->expr, ss);
-
-       /* Obtain the source word length.  */
        tmp = gfc_size_in_bytes (&argse, arg->expr);
      }
!
    dest_word_len = gfc_create_var (gfc_array_index_type, NULL);
    gfc_add_modify_expr (&se->pre, dest_word_len, tmp);

--- 2935,2952 ----
    if (ss == gfc_ss_terminator)
      {
        gfc_conv_expr_reference (&argse, arg->expr);
        tmp = gfc_size_in_bytes (&argse, arg->expr);
+       mold_type = TREE_TYPE (build_fold_indirect_ref (argse.expr));
      }
    else
      {
        gfc_init_se (&argse, NULL);
        argse.want_pointer = 0;
        gfc_conv_expr_descriptor (&argse, arg->expr, ss);
        tmp = gfc_size_in_bytes (&argse, arg->expr);
+       mold_type = gfc_get_element_type (TREE_TYPE (argse.expr));
      }
!
    dest_word_len = gfc_create_var (gfc_array_index_type, NULL);
    gfc_add_modify_expr (&se->pre, dest_word_len, tmp);
$
*************** gfc_conv_intrinsic_array_transfer (gfc_s
*** 3016,3025 ****
    /* Build a destination descriptor, using the pointer, source, as the
       data field.  This is already allocated so set callee_alloc.
       FIXME callee_alloc is not set!  */
-
-   tmp = gfc_typenode_for_spec (&expr->ts);
    gfc_trans_create_temp_array (&se->pre, &se->post, se->loop,
!                              info, tmp, false, true, false);

    /* Use memcpy to do the transfer.  */
    tmp = build_call_expr (built_in_decls[BUILT_IN_MEMCPY],
--- 3015,3022 ----
    /* Build a destination descriptor, using the pointer, source, as the
       data field.  This is already allocated so set callee_alloc.
       FIXME callee_alloc is not set!  */
    gfc_trans_create_temp_array (&se->pre, &se->post, se->loop,
!                              info, mold_type, false, true, false);

    /* Use memcpy to do the transfer.  */
    tmp = build_call_expr (built_in_decls[BUILT_IN_MEMCPY],

However, mold being string(1:1) gives the wrong result so I'll fix that first
before submitting the patch.

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-16 06:54:45         |2007-03-21 15:22:38
               date|                            |


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


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

* [Bug fortran/31193] ICE on non-constant character tranfert
  2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
  2007-03-16  6:54 ` [Bug fortran/31193] ICE on non-constant character tranfert fxcoudert at gcc dot gnu dot org
  2007-03-21 15:22 ` pault at gcc dot gnu dot org
@ 2007-03-22 13:31 ` patchapp at dberlin dot org
  2007-03-22 18:37 ` pault at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: patchapp at dberlin dot org @ 2007-03-22 13:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from patchapp at dberlin dot org  2007-03-22 13:30 -------
Subject: Bug number PR31193

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is
http://gcc.gnu.org/ml/gcc-patches/2007-03/msg01465.html


-- 


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


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

* [Bug fortran/31193] ICE on non-constant character tranfert
  2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-03-22 13:31 ` patchapp at dberlin dot org
@ 2007-03-22 18:37 ` pault at gcc dot gnu dot org
  2007-03-27  9:09 ` [Bug fortran/31193] [4.2 only] " pault at gcc dot gnu dot org
  2007-03-29 16:11 ` fxcoudert at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-03-22 18:37 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pault at gcc dot gnu dot org  2007-03-22 18:37 -------
Subject: Bug 31193

Author: pault
Date: Thu Mar 22 18:37:16 2007
New Revision: 123131

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123131
Log:
2006-03-22  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/31193
        * trans-intrinsic.c (gfc_size_in_bytes): Remove function.
        (gfc_conv_intrinsic_array_transfer): Remove calls to previous.
        Explicitly extract TREE_TYPEs for source and mold.  Use these
        to calculate length of source and mold, except for characters,
        where the se string_length is used.  For mold, the TREE_TYPE is
        recalculated using gfc_get_character_type_len so that the
        result is correctly cast for character literals and substrings.
        Do not use gfc_typenode_for_spec for the final cast.

2006-03-22  Paul Thomas  <pault@gcc.gnu.org>

        PR fortran/31193
        * gfortran.dg/transfer_array_intrinsic_3.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/transfer_array_intrinsic_3.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-intrinsic.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug fortran/31193] [4.2 only] ICE on non-constant character tranfert
  2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2007-03-22 18:37 ` pault at gcc dot gnu dot org
@ 2007-03-27  9:09 ` pault at gcc dot gnu dot org
  2007-03-29 16:11 ` fxcoudert at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pault at gcc dot gnu dot org @ 2007-03-27  9:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pault at gcc dot gnu dot org  2007-03-27 10:09 -------
This is not a regression wrt 4.1 so closing.

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=31193


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

* [Bug fortran/31193] [4.2 only] ICE on non-constant character tranfert
  2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2007-03-27  9:09 ` [Bug fortran/31193] [4.2 only] " pault at gcc dot gnu dot org
@ 2007-03-29 16:11 ` fxcoudert at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2007-03-29 16:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fxcoudert at gcc dot gnu dot org  2007-03-29 17:10 -------
*** Bug 31390 has been marked as a duplicate of this bug. ***


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |drewmccormack at mac dot com


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


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

end of thread, other threads:[~2007-03-29 16:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-16  4:38 [Bug fortran/31193] New: ICE on count(transfer(...)...), with non-constant transfer arguments brooks at gcc dot gnu dot org
2007-03-16  6:54 ` [Bug fortran/31193] ICE on non-constant character tranfert fxcoudert at gcc dot gnu dot org
2007-03-21 15:22 ` pault at gcc dot gnu dot org
2007-03-22 13:31 ` patchapp at dberlin dot org
2007-03-22 18:37 ` pault at gcc dot gnu dot org
2007-03-27  9:09 ` [Bug fortran/31193] [4.2 only] " pault at gcc dot gnu dot org
2007-03-29 16:11 ` fxcoudert 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).