The following avoids warning about completely out-of-bound accesses
as uninitialized.

For GCC8 we likely want to enhance path isolation to catch those
cases (and eventually issue a diagnostic about them).  And we
finally want to fix complete peeling to not introduce those
accesses.

Bootstrap and regtest running on x86_64-unknown-linux-gnu.

Richard.

2017-03-08  Richard Biener  <rguent...@suse.de>

        PR tree-optimization/79955
        PR tree-optimization/79956
        * 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.

Index: gcc/tree-ssa-uninit.c
===================================================================
--- gcc/tree-ssa-uninit.c       (revision 245968)
+++ gcc/tree-ssa-uninit.c       (working copy)
@@ -287,6 +287,17 @@ warn_uninitialized_vars (bool warn_possi
                  || TREE_NO_WARNING (base))
                continue;
 
+             /* Do not warn if the access is fully outside of the
+                variable.  */
+             if (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)))
+               continue;
+
              /* Limit the walking to a constant number of stmts after
                 we overcommit quadratic behavior for small functions
                 and O(n) behavior.  */
Index: gcc/testsuite/gcc.dg/uninit-24.c
===================================================================
--- gcc/testsuite/gcc.dg/uninit-24.c    (nonexistent)
+++ gcc/testsuite/gcc.dg/uninit-24.c    (working copy)
@@ -0,0 +1,10 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wmaybe-uninitialized" } */
+
+int foo (int x)
+{
+  int y;
+  if (x)
+    return *(&y + 1); /* { dg-bogus "may be used uninitialized" } */
+  return 0;
+}

Reply via email to