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.cha...@a2pg.com>. +! Reduced by Steven G. Kargl <ka...@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 <mik...@gcc.gnu.org> + + PR fortran/60341 + * gfortran.dg/str_comp_optimize_1.f90: New test. + 2014-03-01 Oleg Endo <olege...@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 <mik...@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 <ja...@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;