diff options
author | Martin Sebor <msebor@redhat.com> | 2019-01-17 16:33:55 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-01-17 09:33:55 -0700 |
commit | 213694e56e6265044bc85dbf43bda9028f05dba7 (patch) | |
tree | 6e55de74c41ab1ba9949e3447f390dbb4c09b935 /gcc/gimple-fold.c | |
parent | 16d46c7bfda76b5b3e88a2d9a809aacdc3ed8e1a (diff) | |
download | gcc-213694e56e6265044bc85dbf43bda9028f05dba7.zip gcc-213694e56e6265044bc85dbf43bda9028f05dba7.tar.gz gcc-213694e56e6265044bc85dbf43bda9028f05dba7.tar.bz2 |
PR tree-optimization/88800 - Spurious -Werror=array-bounds for non-taken branch
gcc/ChangeLog:
PR tree-optimization/88800
* gimple-fold.c (gimple_fold_builtin_memory_op): Avoid checking
NO_WARNING bit here. Avoid folding out-of-bounds calls.
* gimple-ssa-warn-restrict.c (maybe_diag_offset_bounds): Remove
redundant argument. Add new argument and issue diagnostics under
its control. Detect out-of-bounds access even with warnings
disabled.
(check_bounds_or_overlap): Change return type. Add argument.
(wrestrict_dom_walker::check_call): Adjust.
* gimple-ssa-warn-restrict.h (check_bounds_or_overlap): Add argument.
* tree-ssa-strlen.c (handle_builtin_strcpy): Adjust to change in
check_bounds_or_overlap's return value.
(handle_builtin_stxncpy): Same.
(handle_builtin_strcat): Same.
gcc/testsuite/ChangeLog:
PR tree-optimization/88800
* c-c++-common/Wrestrict.c: Adjust.
* gcc.dg/Warray-bounds-37.c: New test.
* gcc.dg/builtin-memcpy-2.c: New test.
* gcc.dg/builtin-memcpy.c: New test.
From-SVN: r268037
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 2d25f9e..500e551 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -697,8 +697,6 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, tree destvar, srcvar; location_t loc = gimple_location (stmt); - bool nowarn = gimple_no_warning_p (stmt); - /* If the LEN parameter is a constant zero or in range where the only valid value is zero, return DEST. */ if (size_must_be_zero_p (len)) @@ -766,12 +764,16 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, unsigned ilen = tree_to_uhwi (len); if (pow2p_hwi (ilen)) { - /* Detect invalid bounds and overlapping copies and issue - either -Warray-bounds or -Wrestrict. */ - if (!nowarn - && check_bounds_or_overlap (as_a <gcall *>(stmt), - dest, src, len, len)) - gimple_set_no_warning (stmt, true); + /* Detect out-of-bounds accesses without issuing warnings. + Avoid folding out-of-bounds copies but to avoid false + positives for unreachable code defer warning until after + DCE has worked its magic. + -Wrestrict is still diagnosed. */ + if (int warning = check_bounds_or_overlap (as_a <gcall *>(stmt), + dest, src, len, len, + false, false)) + if (warning != OPT_Wrestrict) + return false; scalar_int_mode mode; tree type = lang_hooks.types.type_for_size (ilen * 8, 1); @@ -1038,10 +1040,16 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, } } - /* Detect invalid bounds and overlapping copies and issue either - -Warray-bounds or -Wrestrict. */ - if (!nowarn) - check_bounds_or_overlap (as_a <gcall *>(stmt), dest, src, len, len); + /* Same as above, detect out-of-bounds accesses without issuing + warnings. Avoid folding out-of-bounds copies but to avoid + false positives for unreachable code defer warning until + after DCE has worked its magic. + -Wrestrict is still diagnosed. */ + if (int warning = check_bounds_or_overlap (as_a <gcall *>(stmt), + dest, src, len, len, + false, false)) + if (warning != OPT_Wrestrict) + return false; gimple *new_stmt; if (is_gimple_reg_type (TREE_TYPE (srcvar))) |