From: Richard Biener Date: Fri, 8 Dec 2017 14:45:30 +0000 (+0000) Subject: re PR middle-end/81782 (Yet another -Wmaybe-uninitialized false positive with empty... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=68e6d5a6bdd07248e78eccbd19eb282a9531fd7c;p=gcc.git re PR middle-end/81782 (Yet another -Wmaybe-uninitialized false positive with empty array) 2017-12-08 Richard Biener 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8184c66e8c8..bf4dc004994 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-12-08 Richard Biener + + PR middle-end/81782 + * tree-ssa-uninit.c (warn_uninitialized_vars): Properly + handle accesses outside of zero-sized vars. + 2017-12-08 Martin Jambor PR tree-optimization/83141 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d9ce35fb233..6a68ea6e965 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-08 Richard Biener + + PR middle-end/81782 + * gcc.dg/uninit-pr81782.c: New testcase. + 2017-12-08 Rainer Orth * 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 index 00000000000..7d1e90203f0 --- /dev/null +++ b/gcc/testsuite/gcc.dg/uninit-pr81782.c @@ -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; +} diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 4096ded7ea2..b17b2b10e52 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -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