This fixes PR53849 - we were calling add_referenced_var on a global which is not permitted. The following fixes that and also simplifies the code, making it faster (cfun push/pop can be quite expensive).
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied. Richard. 2012-07-04 Richard Guenther <rguent...@suse.de> PR tree-optimization/53849 * tree-cfg.c (move_stmt_op): Only call add_referenced_var for duplicated locals. Use add_referenced_var_1 to avoid pushing/popping cfun. * gcc.dg/pr53849.c: New testcase. Index: gcc/tree-cfg.c =================================================================== *** gcc/tree-cfg.c (revision 189248) --- gcc/tree-cfg.c (working copy) *************** move_stmt_op (tree *tp, int *walk_subtre *** 6023,6036 **** if ((TREE_CODE (t) == VAR_DECL && !is_global_var (t)) || TREE_CODE (t) == CONST_DECL) - replace_by_duplicate_decl (tp, p->vars_map, p->to_context); - - if (SSA_VAR_P (t) - && gimple_in_ssa_p (cfun)) { ! push_cfun (DECL_STRUCT_FUNCTION (p->to_context)); ! add_referenced_var (*tp); ! pop_cfun (); } } *walk_subtrees = 0; --- 6122,6132 ---- if ((TREE_CODE (t) == VAR_DECL && !is_global_var (t)) || TREE_CODE (t) == CONST_DECL) { ! struct function *to_fn = DECL_STRUCT_FUNCTION (p->to_context); ! replace_by_duplicate_decl (tp, p->vars_map, p->to_context); ! if (gimple_referenced_vars (to_fn)) ! add_referenced_var_1 (*tp, to_fn); } } *walk_subtrees = 0; Index: gcc/testsuite/gcc.dg/pr53849.c =================================================================== *** gcc/testsuite/gcc.dg/pr53849.c (revision 0) --- gcc/testsuite/gcc.dg/pr53849.c (working copy) *************** *** 0 **** --- 1,13 ---- + /* { dg-do compile } */ + /* { dg-options "-O2 -ftree-parallelize-loops=2 -fno-tree-loop-im" } */ + + extern int *b, *e[8], d; + + void + foo (void) + { + int i; + for (i = 0; i < 8; ++i) + while (--d) + e[i] = 0; + }