diff options
author | Martin Sebor <msebor@redhat.com> | 2019-08-28 16:43:56 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-08-28 10:43:56 -0600 |
commit | 464969eb9b47eb2f24403c74c16769a58dbaa638 (patch) | |
tree | 821481a2cfc3a3c99c5d25b19c08cd56afef8e58 /gcc/tree-ssa-strlen.c | |
parent | e2eee239811d4335f28ccdf7c2d9c490fcf6612d (diff) | |
download | gcc-464969eb9b47eb2f24403c74c16769a58dbaa638.zip gcc-464969eb9b47eb2f24403c74c16769a58dbaa638.tar.gz gcc-464969eb9b47eb2f24403c74c16769a58dbaa638.tar.bz2 |
PR tree-optimization/91457 - inconsistent warning for writing past the end of an array member
gcc/ChangeLog:
PR tree-optimization/91457
* builtins.c (component_size): New function.
(compute_objsize): Add argument. Handle ARRAY_REF and COMPONENT_REF.
* builtins.h (compute_objsize): Add argument.
* tree-ssa-strlen.c (handle_store): Handle no-warning bit.
* tree-vrp.c (vrp_prop::check_array_ref): Return warning result.
(vrp_prop::check_mem_ref): Same.
(vrp_prop::search_for_addr_array): Set no-warning bit.
(check_array_bounds): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/91457
* c-c++-common/Wstringop-overflow-2.c: New test.
* g++.dg/warn/Warray-bounds-8.C: New test.
* g++.dg/warn/Wstringop-overflow-3.C: New test.
* gcc.dg/Wstringop-overflow-15.c: New test.
From-SVN: r274997
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r-- | gcc/tree-ssa-strlen.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index d38352a..7bb5f52 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -4026,16 +4026,30 @@ handle_store (gimple_stmt_iterator *gsi) rhs_minlen = lenrange[0]; storing_nonzero_p = lenrange[1] > 0; - if (tree dstsize = compute_objsize (lhs, 1)) - if (compare_tree_int (dstsize, lenrange[2]) < 0) - { - location_t loc = gimple_nonartificial_location (stmt); - warning_n (loc, OPT_Wstringop_overflow_, - lenrange[2], - "%Gwriting %u byte into a region of size %E", - "%Gwriting %u bytes into a region of size %E", - stmt, lenrange[2], dstsize); - } + /* Avoid issuing multiple warnings for the same LHS or statement. + For example, -Warray-bounds may have already been issued for + an out-of-bounds subscript. */ + if (!TREE_NO_WARNING (lhs) && !gimple_no_warning_p (stmt)) + { + /* Set to the declaration referenced by LHS (if known). */ + tree decl = NULL_TREE; + if (tree dstsize = compute_objsize (lhs, 1, &decl)) + if (compare_tree_int (dstsize, lenrange[2]) < 0) + { + location_t loc = gimple_nonartificial_location (stmt); + if (warning_n (loc, OPT_Wstringop_overflow_, + lenrange[2], + "%Gwriting %u byte into a region of size %E", + "%Gwriting %u bytes into a region of size %E", + stmt, lenrange[2], dstsize)) + { + if (decl) + inform (DECL_SOURCE_LOCATION (decl), + "destination object declared here"); + gimple_set_no_warning (stmt, true); + } + } + } } else { |