https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79955
Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2017-03-08 Ever confirmed|0 |1 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Confirmed (testcase works on x86_64 with -m32). We warn about an out-of-bound access to wint_t str; for which there is (obviously) no initialization. The theory is that the code is dead and never reached at runtime but of course the function is gigantic and GCC wasn't able to prove this. For similar cases we have path isolation which also (fortunately) runs after the first VRP pass where we'd warn about out-of-bound array accesses. So sth like the following fixes this warning (and it replaces the out-of-bound access with a trap). Note this is esp. tailored to the cases handled by -Wuninitialized. Index: gcc/gimple-ssa-isolate-paths.c =================================================================== --- gcc/gimple-ssa-isolate-paths.c (revision 245968) +++ gcc/gimple-ssa-isolate-paths.c (working copy) @@ -502,6 +502,35 @@ find_explicit_erroneous_behavior (void) break; } + /* Memory loads that are fully outside of an automatic + variable are prone to cause -Wuninitialized warnings, + prune them here by replacing them with a trap. */ + if (gimple_assign_load_p (stmt)) + { + ao_ref ref; + ao_ref_init (&ref, gimple_assign_rhs1 (stmt)); + tree base = ao_ref_base (&ref); + if (DECL_P (base) + && auto_var_in_fn_p (base, cfun->decl) + && ref.size != -1 + && ref.max_size == ref.size + && (ref.offset + ref.size <= 0 + || (ref.offset >= 0 + && TREE_CODE (DECL_SIZE (base)) == INTEGER_CST + && compare_tree_int (DECL_SIZE (base), + ref.offset) <= 0))) + { + insert_trap (&si, null_pointer_node); + bb = gimple_bb (gsi_stmt (si)); + + /* Ignore any more operands on this statement and + continue the statement iterator (which should + terminate its loop immediately. */ + cfg_altered = true; + break; + } + } + /* Detect returning the address of a local variable. This only becomes undefined behavior if the result is used, so we do not insert a trap and only return NULL instead. */