[Bug tree-optimization/79955] GLIBC build fails after r245840

2017-03-08 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79955

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |FIXED

--- Comment #4 from Richard Biener  ---
Fixed.

[Bug tree-optimization/79955] GLIBC build fails after r245840

2017-03-08 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79955

--- Comment #3 from Richard Biener  ---
Author: rguenth
Date: Wed Mar  8 14:10:47 2017
New Revision: 245976

URL: https://gcc.gnu.org/viewcvs?rev=245976&root=gcc&view=rev
Log:
2017-03-08  Richard Biener  

PR tree-optimization/79955
* tree-ssa-uninit.c (warn_uninitialized_vars): Do not warn
for accesses that are completely outside of the variable.

* gcc.dg/uninit-24.c: New testcase.

Added:
trunk/gcc/testsuite/gcc.dg/uninit-24.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-uninit.c

[Bug tree-optimization/79955] GLIBC build fails after r245840

2017-03-08 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79955

--- Comment #2 from Richard Biener  ---
Testcase that is fixed (at -O2, at -O1 we do not run isolate-paths...)

/* { dg-do compile } */
/* { dg-options "-O2 -Wmaybe-uninitialized" } */

int foo (int x)
{
  int y;
  if (x)
return *(&y + 1);  /* { dg-bogus "may be used uninitialized" } */
  return 0;
}

[Bug tree-optimization/79955] GLIBC build fails after r245840

2017-03-08 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79955

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2017-03-08
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
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.  */