aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-uninit.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2021-07-28 16:25:40 -0600
committerMartin Sebor <msebor@redhat.com>2021-07-28 16:25:40 -0600
commit1121e495b70105deeb82295f8210e30f2080bc37 (patch)
tree2848e49b3eef7021e3e034f6a7f31f68a946350d /gcc/tree-ssa-uninit.c
parentb9cbf8c9e0bc72f59b643165247fae646560aadd (diff)
downloadgcc-1121e495b70105deeb82295f8210e30f2080bc37.zip
gcc-1121e495b70105deeb82295f8210e30f2080bc37.tar.gz
gcc-1121e495b70105deeb82295f8210e30f2080bc37.tar.bz2
Correct uninitialized object offset and size computation [PR101494].
Resolves: PR middle-end/101494 - -Wuninitialized false alarm with memrchr of size 0 gcc/ChangeLog: PR middle-end/101494 * tree-ssa-uninit.c (maybe_warn_operand): Correct object offset and size computation. gcc/testsuite/ChangeLog: PR middle-end/101494 * gcc.dg/uninit-pr101494.c: New test.
Diffstat (limited to 'gcc/tree-ssa-uninit.c')
-rw-r--r--gcc/tree-ssa-uninit.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index ab64a68..5d7bc80 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -371,16 +371,20 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs,
|| get_no_uninit_warning (base))
return NULL_TREE;
- /* Do not warn if the access is fully outside of the variable. */
+ /* Do not warn if the access is zero size or if it's fully outside
+ the object. */
poly_int64 decl_size;
+ if (known_size_p (ref.size)
+ && known_eq (ref.max_size, ref.size)
+ && (known_eq (ref.size, 0)
+ || known_le (ref.offset + ref.size, 0)))
+ return NULL_TREE;
+
if (DECL_P (base)
- && ((known_size_p (ref.size)
- && known_eq (ref.max_size, ref.size)
- && known_le (ref.offset + ref.size, 0))
- || (known_ge (ref.offset, 0)
- && DECL_SIZE (base)
- && poly_int_tree_p (DECL_SIZE (base), &decl_size)
- && known_le (decl_size, ref.offset))))
+ && known_ge (ref.offset, 0)
+ && DECL_SIZE (base)
+ && poly_int_tree_p (DECL_SIZE (base), &decl_size)
+ && known_le (decl_size, ref.offset))
return NULL_TREE;
/* Do not warn if the result of the access is then used for