This is an issue of folding looking at SSA def stmts when SSA form is not up-to-date. That's not safe unless the SSA name we are looking at is not marked for update (see GIMPLE_COND folding in cfgcleaup for another example).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2012-08-20 Richard Guenther <rguent...@suse.de> PR tree-optimization/54327 * gimple-fold.c (get_maxval_strlen): Do not walk use-def chains if the use is registered for SSA update. * gcc.dg/torture/pr54327.c: New testcase. Index: gcc/gimple-fold.c =================================================================== *** gcc/gimple-fold.c (revision 190523) --- gcc/gimple-fold.c (working copy) *************** get_maxval_strlen (tree arg, tree *lengt *** 736,741 **** --- 736,746 ---- return true; } + /* If ARG is registered for SSA update we cannot look at its defining + statement. */ + if (name_registered_for_update_p (arg)) + return false; + /* If we were already here, break the infinite cycle. */ if (!bitmap_set_bit (visited, SSA_NAME_VERSION (arg))) return true; Index: gcc/testsuite/gcc.dg/torture/pr54327.c =================================================================== *** gcc/testsuite/gcc.dg/torture/pr54327.c (revision 0) --- gcc/testsuite/gcc.dg/torture/pr54327.c (working copy) *************** *** 0 **** --- 1,15 ---- + /* { dg-do compile } */ + + #include <string.h> + #include <stdlib.h> + void treathead () + { + char *a = ';' == '\0' ? : 0; + if (*a == '=') + { + while (*a == (*a == 0) || *a == '\'') + a++; + if (strlen (a) < 2) + abort (); + } + }