This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Patch, fortran] PR31620 - [4.3 regression] Zeroing one component of array of derived types zeros the whole structure.
- From: "Paul Richard Thomas" <paul dot richard dot thomas at gmail dot com>
- To: "fortran at gcc dot gnu dot org List" <fortran at gcc dot gnu dot org>, "gcc-patches List" <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 22 Apr 2007 23:03:59 +0200
- Subject: [Patch, fortran] PR31620 - [4.3 regression] Zeroing one component of array of derived types zeros the whole structure.
:ADDPATCH fortran:
This rather bad regression is due to all the components of an array of
derived types being part of the array in an assignment of zero to one
component. The patch is self-explanatory and the testcase is the
reporter's.
Regtested on x86_ia64 - OK for trunk?
Paul
2007-04-22 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31620
* trans-expr.c (gfc_trans_assignment): Make the call to
gfc_trans_zero_assign conditional on the lhs array ref being
the only reference.
2007-04-22 Paul Thomas <pault@gcc.gnu.org>
PR fortran/31620
* gfortran.dg/zero_array_components_1.f90: New test.
--
"Success is the ability to go from one failure to another with no loss
of enthusiasm." - Winston Churchill
Index: gcc/fortran/trans-expr.c
===================================================================
*** gcc/fortran/trans-expr.c (revision 124025)
--- gcc/fortran/trans-expr.c (working copy)
*************** gfc_trans_assignment (gfc_expr * expr1,
*** 3943,3948 ****
--- 3943,3949 ----
if (expr1->expr_type == EXPR_VARIABLE
&& expr1->rank > 0
&& expr1->ref
+ && expr1->ref->next == NULL
&& gfc_full_array_ref_p (expr1->ref)
&& is_zero_initializer_p (expr2))
{
Index: /svn/trunk/gcc/testsuite/gfortran.dg/zero_array_components_1.f90
===================================================================
*** /svn/trunk/gcc/testsuite/gfortran.dg/zero_array_components_1.f90 (revision 0)
--- /svn/trunk/gcc/testsuite/gfortran.dg/zero_array_components_1.f90 (revision 0)
***************
*** 0 ****
--- 1,17 ----
+ ! { dg do-run }
+ ! Tests the fix for PR31620, in which zeroing the component a for the array,
+ ! would zero all the components of the array.
+ !
+ ! David Ham <David@ham.dropbear.id.au>
+ !
+ program test_assign
+ type my_type
+ integer :: a
+ integer :: b
+ end type my_type
+ type(my_type), dimension(1) :: mine ! note that MINE is an array
+ mine%b=4
+ mine%a=1
+ mine%a=0
+ if (any (mine%b .ne. 4)) call abort ()
+ end program test_assign