aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-common.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-03-12 18:04:16 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2018-03-12 12:04:16 -0600
commite9b9fa4cdaedd40ab429c0c98e8801ae039a33e9 (patch)
tree3fbe1a5f54834ad2c8f3f4f8d5572933ad7b9ae0 /gcc/c-family/c-common.c
parentdf4cfec5540bfb982bfec374346493bed6608fa4 (diff)
downloadgcc-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/c-family/c-common.c')
-rw-r--r--gcc/c-family/c-common.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index 858ed68..e1df1d3 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5309,10 +5309,11 @@ check_function_sentinel (const_tree fntype, int nargs, tree *argarray)
}
}
-/* Check that the same argument isn't passed to restrict arguments
- and other arguments. */
+/* Check that the same argument isn't passed to two or more
+ restrict-qualified formal and issue a -Wrestrict warning
+ if it is. Return true if a warning has been issued. */
-static void
+static bool
check_function_restrict (const_tree fndecl, const_tree fntype,
int nargs, tree *argarray)
{
@@ -5322,11 +5323,14 @@ check_function_restrict (const_tree fndecl, const_tree fntype,
if (fndecl
&& TREE_CODE (fndecl) == FUNCTION_DECL)
{
- /* Skip checking built-ins here. They are checked in more
- detail elsewhere. */
+ /* Avoid diagnosing calls built-ins with a zero size/bound
+ here. They are checked in more detail elsewhere. */
if (DECL_BUILT_IN (fndecl)
- && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL)
- return;
+ && DECL_BUILT_IN_CLASS (fndecl) == BUILT_IN_NORMAL
+ && nargs == 3
+ && TREE_CODE (argarray[2]) == INTEGER_CST
+ && integer_zerop (argarray[2]))
+ return false;
if (DECL_ARGUMENTS (fndecl))
parms = DECL_ARGUMENTS (fndecl);
@@ -5335,6 +5339,8 @@ check_function_restrict (const_tree fndecl, const_tree fntype,
for (i = 0; i < nargs; i++)
TREE_VISITED (argarray[i]) = 0;
+ bool warned = false;
+
for (i = 0; i < nargs && parms && parms != void_list_node; i++)
{
tree type;
@@ -5351,11 +5357,13 @@ check_function_restrict (const_tree fndecl, const_tree fntype,
if (POINTER_TYPE_P (type)
&& TYPE_RESTRICT (type)
&& !TYPE_READONLY (TREE_TYPE (type)))
- warn_for_restrict (i, argarray, nargs);
+ warned |= warn_for_restrict (i, argarray, nargs);
}
for (i = 0; i < nargs; i++)
TREE_VISITED (argarray[i]) = 0;
+
+ return warned;
}
/* Helper for check_function_nonnull; given a list of operands which
@@ -5596,8 +5604,10 @@ attribute_fallthrough_p (tree attr)
/* Check for valid arguments being passed to a function with FNTYPE.
- There are NARGS arguments in the array ARGARRAY. LOC should be used for
- diagnostics. Return true if -Wnonnull warning has been diagnosed. */
+ There are NARGS arguments in the array ARGARRAY. LOC should be used
+ for diagnostics. Return true if either -Wnonnull or -Wrestrict has
+ been issued. */
+
bool
check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
int nargs, tree *argarray, vec<location_t> *arglocs)
@@ -5620,7 +5630,7 @@ check_function_arguments (location_t loc, const_tree fndecl, const_tree fntype,
check_function_sentinel (fntype, nargs, argarray);
if (warn_restrict)
- check_function_restrict (fndecl, fntype, nargs, argarray);
+ warned_p |= check_function_restrict (fndecl, fntype, nargs, argarray);
return warned_p;
}