This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed, fortran] PR 60341 invalid union access on string comparison optimization
- From: Mikael Morin <mikael dot morin at sfr dot fr>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>, gfortran <fortran at gcc dot gnu dot org>
- Date: Sat, 01 Mar 2014 22:20:38 +0100
- Subject: [Committed, fortran] PR 60341 invalid union access on string comparison optimization
- Authentication-results: sourceware.org; auth=none
Hello,
I have just regression tested and committed a patch fixing PR 60341 by
adding two expression type checks before union accesses (it's the same
as the one of the PR).
I plan to backport tomorrow (4.8 and 4.7).
Mikael
Index: gcc/testsuite/gfortran.dg/str_comp_optimize_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/str_comp_optimize_1.f90 (révision 0)
+++ gcc/testsuite/gfortran.dg/str_comp_optimize_1.f90 (révision 208249)
@@ -0,0 +1,22 @@
+! { dg-do compile }
+! { dg-options "-ffrontend-optimize" }
+!
+! PR fortran/60341
+! An unguarded union access was wrongly enabling a frontend optimization on a
+! string comparison, leading to an ICE.
+!
+! Original testcase from Steve Chapel <steve.chapel@a2pg.com>.
+! Reduced by Steven G. Kargl <kargl@gcc.gnu.org>.
+!
+
+ subroutine modelg(ncm)
+ implicit none
+ integer, parameter :: pc = 30, pm = pc - 1
+ integer i
+ character*4 catt(pm,2)
+ integer ncm,iatt(pm,pc)
+ do i=1,ncm
+ if (catt(i,1)//catt(i,2).eq.'central') exit
+ end do
+ iatt(i,4)=1
+ end
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog (révision 208248)
+++ gcc/testsuite/ChangeLog (révision 208249)
@@ -1,3 +1,8 @@
+2014-03-01 Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/60341
+ * gfortran.dg/str_comp_optimize_1.f90: New test.
+
2014-03-01 Oleg Endo <olegendo@gcc.gnu.org>
PR target/60071
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog (révision 208248)
+++ gcc/fortran/ChangeLog (révision 208249)
@@ -1,3 +1,9 @@
+2014-03-01 Mikael Morin <mikael@gcc.gnu.org>
+
+ PR fortran/60341
+ * frontend-passes.c (optimize_comparison): Guard two union accesses
+ with the corresponding tag checks.
+
2014-02-28 Janus Weil <janus@gcc.gnu.org>
PR fortran/60359
Index: gcc/fortran/frontend-passes.c
===================================================================
--- gcc/fortran/frontend-passes.c (révision 208248)
+++ gcc/fortran/frontend-passes.c (révision 208249)
@@ -1391,7 +1391,9 @@ optimize_comparison (gfc_expr *e, gfc_intrinsic_op
/* Replace A // B < A // C with B < C, and A // B < C // B
with A < C. */
if (op1->ts.type == BT_CHARACTER && op2->ts.type == BT_CHARACTER
+ && op1->expr_type == EXPR_OP
&& op1->value.op.op == INTRINSIC_CONCAT
+ && op2->expr_type == EXPR_OP
&& op2->value.op.op == INTRINSIC_CONCAT)
{
gfc_expr *op1_left = op1->value.op.op1;