diff options
author | Martin Sebor <msebor@redhat.com> | 2018-03-12 18:04:16 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-03-12 12:04:16 -0600 |
commit | e9b9fa4cdaedd40ab429c0c98e8801ae039a33e9 (patch) | |
tree | 3fbe1a5f54834ad2c8f3f4f8d5572933ad7b9ae0 /gcc/gimple-fold.c | |
parent | df4cfec5540bfb982bfec374346493bed6608fa4 (diff) | |
download | gcc-e9b9fa4cdaedd40ab429c0c98e8801ae039a33e9.zip gcc-e9b9fa4cdaedd40ab429c0c98e8801ae039a33e9.tar.gz gcc-e9b9fa4cdaedd40ab429c0c98e8801ae039a33e9.tar.bz2 |
PR tree-optimization/83456 - -Wrestrict false positive on a non-overlapping memcpy in an inline function
gcc/ChangeLog:
PR tree-optimization/83456
* gimple-fold.c (gimple_fold_builtin_memory_op): Avoid warning
for perfectly overlapping calls to memcpy.
(gimple_fold_builtin_memory_chk): Same.
(gimple_fold_builtin_strcpy): Handle no-warning.
(gimple_fold_builtin_stxcpy_chk): Same.
* tree-ssa-strlen.c (maybe_diag_stxncpy_trunc): Handle no-warning.
gcc/c-family/ChangeLog:
PR tree-optimization/83456
* gcc/c-family/c-common.c (check_function_restrict): Return bool.
Restore checking of bounded built-in functions.
(check_function_arguments): Also return the result
of warn_for_restrict.
* gcc/c-family/c-common.c (check_function_restrict): Return bool.
* gcc/c-family/c-warn.c (warn_for_restrict): Return bool.
gcc/testsuite/ChangeLog:
PR tree-optimization/83456
* c-c++-common/Wrestrict-2.c: Remove test cases.
* c-c++-common/Wrestrict.c: Same.
* gcc.dg/Wrestrict-12.c: New test.
* gcc.dg/Wrestrict-14.c: New test.
From-SVN: r258455
Diffstat (limited to 'gcc/gimple-fold.c')
-rw-r--r-- | gcc/gimple-fold.c | 43 |
1 files changed, 15 insertions, 28 deletions
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 8257873..7771988 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -682,11 +682,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, tree destvar, srcvar; location_t loc = gimple_location (stmt); - tree func = gimple_call_fndecl (stmt); bool nowarn = gimple_no_warning_p (stmt); - bool check_overlap = (DECL_FUNCTION_CODE (func) != BUILT_IN_MEMMOVE - && DECL_FUNCTION_CODE (func) != BUILT_IN_MEMMOVE_CHK - && !nowarn); /* If the LEN parameter is a constant zero or in range where the only valid value is zero, return DEST. */ @@ -713,13 +709,7 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi, { /* Avoid diagnosing exact overlap in calls to __builtin_memcpy. It's safe and may even be emitted by GCC itself (see bug - 32667). However, diagnose it in explicit calls to the memcpy - function. */ - if (check_overlap && *IDENTIFIER_POINTER (DECL_NAME (func)) != '_') - warning_at (loc, OPT_Wrestrict, - "%qD source argument is the same as destination", - func); - + 32667). */ unlink_stmt_vdef (stmt); if (gimple_vdef (stmt) && TREE_CODE (gimple_vdef (stmt)) == SSA_NAME) release_ssa_name (gimple_vdef (stmt)); @@ -1622,11 +1612,14 @@ gimple_fold_builtin_strcpy (gimple_stmt_iterator *gsi, /* If SRC and DEST are the same (and not volatile), return DEST. */ if (operand_equal_p (src, dest, 0)) { - tree func = gimple_call_fndecl (stmt); + if (!gimple_no_warning_p (stmt)) + { + tree func = gimple_call_fndecl (stmt); - warning_at (loc, OPT_Wrestrict, - "%qD source argument is the same as destination", - func); + warning_at (loc, OPT_Wrestrict, + "%qD source argument is the same as destination", + func); + } replace_call_with_value (gsi, dest); return true; @@ -2499,15 +2492,6 @@ gimple_fold_builtin_memory_chk (gimple_stmt_iterator *gsi, (resp. DEST+LEN for __mempcpy_chk). */ if (fcode != BUILT_IN_MEMSET_CHK && operand_equal_p (src, dest, 0)) { - if (fcode != BUILT_IN_MEMMOVE && fcode != BUILT_IN_MEMMOVE_CHK) - { - tree func = gimple_call_fndecl (stmt); - - warning_at (loc, OPT_Wrestrict, - "%qD source argument is the same as destination", - func); - } - if (fcode != BUILT_IN_MEMPCPY_CHK) { replace_call_with_value (gsi, dest); @@ -2609,11 +2593,14 @@ gimple_fold_builtin_stxcpy_chk (gimple_stmt_iterator *gsi, /* If SRC and DEST are the same (and not volatile), return DEST. */ if (fcode == BUILT_IN_STRCPY_CHK && operand_equal_p (src, dest, 0)) { - tree func = gimple_call_fndecl (stmt); + if (!gimple_no_warning_p (stmt)) + { + tree func = gimple_call_fndecl (stmt); - warning_at (loc, OPT_Wrestrict, - "%qD source argument is the same as destination", - func); + warning_at (loc, OPT_Wrestrict, + "%qD source argument is the same as destination", + func); + } replace_call_with_value (gsi, dest); return true; |