Bug 30284 - [4.1 only] ICE in gfc_add_modify with internal reads
Summary: [4.1 only] ICE in gfc_add_modify with internal reads
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks: 30626
  Show dependency treegraph
 
Reported: 2006-12-23 21:22 UTC by Harald Anlauf
Modified: 2009-07-02 03:07 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-02-01 10:19:09


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Harald Anlauf 2006-12-23 21:22:16 UTC
Hi,

here's another one:

% cat gfcbug51.f90
program gfcbug51
  implicit none

  type date_t
     character(len=12) :: date = '200612231200' ! yyyymmddhhmm
  end type date_t
  type year_t
    integer :: year = 0
  end type year_t

  type(date_t) :: file(1)
  type(year_t) :: time(1)

  read (file% date(1:4),'(i4)')  time% year
  print *, time% year
end program gfcbug51
% gfc gfcbug51.f90
gfcbug51.f90: In function 'MAIN__':
gfcbug51.f90:1: internal compiler error: in gfc_add_modify, at fortran/trans.c:1
59

Cheers,
-ha
Comment 1 Andrew Pinski 2006-12-24 05:25:12 UTC
Reduced testcase:
program gfcbug51
  type date_t
     character(len=12) :: date
  end type date_t
  type(date_t) :: file(1)
  read (file%date(1:4),'(i4)') a
end program gfcbug51
------------------------------
Here is a patch which fixes the issue too:
Index: trans-io.c
===================================================================
--- trans-io.c  (revision 120165)
+++ trans-io.c  (working copy)
@@ -635,7 +635,7 @@ set_internal_unit (stmtblock_t * block,
   /* The cast is needed for character substrings and the descriptor
      data.  */
   gfc_add_modify_expr (&se.pre, io, fold_convert (TREE_TYPE (io), tmp));
-  gfc_add_modify_expr (&se.pre, len, se.string_length);
+  gfc_add_modify_expr (&se.pre, len, fold_convert (TREE_TYPE (len), se.string_length));
   gfc_add_modify_expr (&se.pre, desc, se.expr);

   gfc_add_block_to_block (block, &se.pre);
Comment 2 kargls 2006-12-24 17:52:38 UTC
(In reply to comment #1)
>
> Here is a patch which fixes the issue too:
> Index: trans-io.c
> 

The patch moves the ICE to eimt-rtl.c.

laptop:kargl[218] gfc4x -o z -fdump-tree-original -O internal_io.f90
internal_io.f90: In function 'MAIN__':
internal_io.f90:8: internal compiler error: in operand_subword_force, at emit-rtl.c:1352

The dump suggest that a temporary array has not been properly sized.

Comment 3 Andrew Pinski 2006-12-27 02:32:56 UTC
(In reply to comment #2)
> The dump suggest that a temporary array has not been properly sized.

We get:
  char[0:][1:12] * D.972;


{
      int4 S.3;

      S.3 = 0;
      while (1)
        {
          if (S.3 > 0) goto L.1;
          (*(char[0:][1:12] *) atmp.1.data)[NON_LVALUE_EXPR <S.3>] = file[NON_LVALUE_EXPR <S.3>].date[1]{lb: 1 sz: 1};
          S.3 = S.3 + 1;
        }
      L.1:;
    }


So yes we have the incorrect type for the temp array, we have char[1:12] instead of just char.

So my patch fixes one problem and we run into the next issue.
Comment 4 Paul Thomas 2007-02-01 10:19:09 UTC
A fix is on its way, this weekend.

Paul
Comment 5 patchapp@dberlin.org 2007-02-01 22:45:44 UTC
Subject: Bug number PR30284

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-02/msg00112.html
Comment 6 Paul Thomas 2007-02-02 12:36:13 UTC
Subject: Bug 30284

Author: pault
Date: Fri Feb  2 12:35:57 2007
New Revision: 121500

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

	PR fortran/30284
	PR fortran/30626
	* trans-expr.c (gfc_conv_aliased_arg): Remove static attribute
	from function and make sure that substring lengths are
	translated.
	(is_aliased_array): Remove static attribute.
	* trans.c : Add prototypes for gfc_conv_aliased_arg and
	is_aliased_array.
	* trans-io.c (set_internal_unit): Add the post block to the
	arguments of the function.  Use is_aliased_array to check if
	temporary is needed; if so call gfc_conv_aliased_arg.
	(build_dt): Pass the post block to set_internal_unit and
	add to the block after all io activiy is done.

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

	PR fortran/30284
	PR fortran/30626
	* io/transfer.c (init_loop_spec, next_array_record): Change to
	lbound rather than unity base.

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

	PR fortran/30284
	* gfortran.dg/arrayio_11.f90.f90: New test.

	PR fortran/30626
	* gfortran.dg/arrayio_12.f90.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/arrayio_11.f90
    trunk/gcc/testsuite/gfortran.dg/arrayio_12.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-io.c
    trunk/gcc/fortran/trans.h
    trunk/gcc/testsuite/ChangeLog
    trunk/libgfortran/ChangeLog
    trunk/libgfortran/io/transfer.c

Comment 7 Paul Thomas 2007-02-12 07:35:10 UTC
Subject: Bug 30284

Author: pault
Date: Mon Feb 12 07:34:51 2007
New Revision: 121841

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

	BACKPORTS FROM TRUNK

	PR fortran/30284
	PR fortran/30626
	* trans-expr.c (gfc_conv_aliased_arg): Remove static attribute
	from function and make sure that substring lengths are
	translated.
	(is_aliased_array): Remove static attribute.
	* trans.c : Add prototypes for gfc_conv_aliased_arg and
	is_aliased_array.
	* trans-io.c (set_internal_unit): Add the post block to the
	arguments of the function.  Use is_aliased_array to check if
	temporary is needed; if so call gfc_conv_aliased_arg.
	(build_dt): Pass the post block to set_internal_unit and
	add to the block after all io activiy is done.

	PR fortran/30407
	* trans-expr.c (gfc_conv_operator_assign): New function.
	* trans.h : Add prototype for gfc_conv_operator_assign.
	* trans-stmt.c (gfc_trans_where_assign): Add a gfc_symbol for
	a potential operator assignment subroutine.  If it is non-NULL
	call gfc_conv_operator_assign instead of the first assignment.
	( gfc_trans_where_2): In the case of an operator assignment,
	extract the argument expressions from the code for the
	subroutine call and pass the symbol to gfc_trans_where_assign.
	resolve.c (resolve_where, gfc_resolve_where_code_in_forall,
	gfc_resolve_forall_body): Resolve the subroutine call for
	operator assignments.

	PR fortran/30514
	* array.c (match_array_element_spec): If the length of an array is
	negative, adjust the upper limit to make it zero length.

2007-02-12  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	* gfortran.dg/arrayio_11.f90: New test.

	PR fortran/30626
	* gfortran.dg/arrayio_12.f90: New test.

	PR fortran/30407
	* gfortran.dg/where_operator_assign_1.f90: New test.
	* gfortran.dg/where_operator_assign_2.f90: New test.
	* gfortran.dg/where_operator_assign_3.f90: New test.

	PR fortran/30514
	* gfortran.dg/zero_sized_2.f90: New test.

2007-02-12  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	PR fortran/30626
	* io/transfer.c (init_loop_spec, next_array_record): Change to
	lbound rather than unity base.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/arrayio_11.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/arrayio_12.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/where_operator_assign_1.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/where_operator_assign_2.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/where_operator_assign_3.f90
    branches/gcc-4_2-branch/gcc/testsuite/gfortran.dg/zero_sized_2.f90
Modified:
    branches/gcc-4_2-branch/gcc/fortran/ChangeLog
    branches/gcc-4_2-branch/gcc/fortran/array.c
    branches/gcc-4_2-branch/gcc/fortran/resolve.c
    branches/gcc-4_2-branch/gcc/fortran/trans-expr.c
    branches/gcc-4_2-branch/gcc/fortran/trans-io.c
    branches/gcc-4_2-branch/gcc/fortran/trans-stmt.c
    branches/gcc-4_2-branch/gcc/fortran/trans.h
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_2-branch/libgfortran/ChangeLog
    branches/gcc-4_2-branch/libgfortran/io/transfer.c

Comment 8 Paul Thomas 2007-02-12 07:36:03 UTC
Fixed on trunk and 4.2.

Paul
Comment 9 Paul Thomas 2007-06-30 13:08:32 UTC
Subject: Bug 30284

Author: pault
Date: Sat Jun 30 13:08:19 2007
New Revision: 126147

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

	PR fortran/32472
	* simplify.c (gfc_simplify_repeat): Add handling of character
	literal for first argument.

2007-06-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	* gfortran.dg/repeat_f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/repeat_5.f90
Modified:
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog

Comment 10 Paul Thomas 2007-06-30 13:09:27 UTC
Subject: Bug 30284

Author: pault
Date: Sat Jun 30 13:09:14 2007
New Revision: 126148

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

	PR fortran/32472
	* simplify.c (gfc_simplify_repeat): Add handling of character
	literal for first argument.

2007-06-30  Paul Thomas  <pault@gcc.gnu.org>

	PR fortran/30284
	* gfortran.dg/repeat_f90: New test.

Modified:
    trunk/gcc/fortran/ChangeLog