re PR middle-end/81782 (Yet another -Wmaybe-uninitialized false positive with empty...
authorRichard Biener <rguenther@suse.de>
Fri, 8 Dec 2017 14:45:30 +0000 (14:45 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 8 Dec 2017 14:45:30 +0000 (14:45 +0000)
2017-12-08  Richard Biener  <rguenther@suse.de>

PR middle-end/81782
* tree-ssa-uninit.c (warn_uninitialized_vars): Properly
handle accesses outside of zero-sized vars.

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

From-SVN: r255512

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/uninit-pr81782.c [new file with mode: 0644]
gcc/tree-ssa-uninit.c

index 8184c66e8c8db31808124060660c5b05735da69f..bf4dc0049945d95a520173f2d8b4f500cda5cfb1 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-08  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/81782
+       * tree-ssa-uninit.c (warn_uninitialized_vars): Properly
+       handle accesses outside of zero-sized vars.
+
 2017-12-08  Martin Jambor  <mjambor@suse.cz>
 
        PR tree-optimization/83141
index d9ce35fb233055d1e778eccc52584308d1731a05..6a68ea6e965c6054a96c15de937d10b8a3637e33 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-08  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/81782
+       * gcc.dg/uninit-pr81782.c: New testcase.
+
 2017-12-08  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
 
        * g++.dg/opt/pr83252.C: Add -mclear-hwcap on *-*-solaris*.
diff --git a/gcc/testsuite/gcc.dg/uninit-pr81782.c b/gcc/testsuite/gcc.dg/uninit-pr81782.c
new file mode 100644 (file)
index 0000000..7d1e902
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-Wmaybe-uninitialized" } */
+
+int
+foo (void)
+{
+  char empty_array[] = { };
+  int i, ret = 0;
+
+  for (i = 0; i < (int) (sizeof (empty_array) / sizeof (empty_array[0])); i++)
+    ret = empty_array[i]; /* { dg-bogus "uninitialized" } */
+
+  return ret;
+}
index 4096ded7ea2ed038a48ed6118e5a5d786759bb5e..b17b2b10e524cbc5ec1204c6a7e27527476cdd2a 100644 (file)
@@ -296,8 +296,8 @@ warn_uninitialized_vars (bool warn_possibly_uninitialized)
                 variable.  */
              if (DECL_P (base)
                  && ref.size != -1
-                 && ref.max_size == ref.size
-                 && (ref.offset + ref.size <= 0
+                 && ((ref.max_size == ref.size
+                      && ref.offset + ref.size <= 0)
                      || (ref.offset >= 0
                          && DECL_SIZE (base)
                          && TREE_CODE (DECL_SIZE (base)) == INTEGER_CST