diff options
author | Jakub Jelinek <jakub@redhat.com> | 2012-07-20 11:37:25 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2012-07-20 11:37:25 +0200 |
commit | 332f1d2404d4e69a8fb88a3d2b6fc302901caec4 (patch) | |
tree | 25252a03826e4bf84e9d1273eae3b049d63f7537 /gcc/c-family/c-common.c | |
parent | 3c82efd91f3f8f1f957907fd7d902e26279239e9 (diff) | |
download | gcc-332f1d2404d4e69a8fb88a3d2b6fc302901caec4.zip gcc-332f1d2404d4e69a8fb88a3d2b6fc302901caec4.tar.gz gcc-332f1d2404d4e69a8fb88a3d2b6fc302901caec4.tar.bz2 |
re PR c++/28656 (duplicated null argument warning on memcpy())
PR c++/28656
* tree-vrp.c (nonnull_arg_p): Handle all nonnull attributes instead
of just the first one.
* c-common.c (check_function_nonnull): Handle multiple nonnull
attributes properly.
* c-c++-common/pr28656.c: New test.
From-SVN: r189707
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r-- | gcc/c-family/c-common.c | 44 |
1 files changed, 30 insertions, 14 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 4a8b56d..b72506b 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -8051,26 +8051,42 @@ handle_nonnull_attribute (tree *node, tree ARG_UNUSED (name), static void check_function_nonnull (tree attrs, int nargs, tree *argarray) { - tree a, args; + tree a; int i; - for (a = attrs; a; a = TREE_CHAIN (a)) + attrs = lookup_attribute ("nonnull", attrs); + if (attrs == NULL_TREE) + return; + + a = attrs; + /* See if any of the nonnull attributes has no arguments. If so, + then every pointer argument is checked (in which case the check + for pointer type is done in check_nonnull_arg). */ + if (TREE_VALUE (a) != NULL_TREE) + do + a = lookup_attribute ("nonnull", TREE_CHAIN (a)); + while (a != NULL_TREE && TREE_VALUE (a) != NULL_TREE); + + if (a != NULL_TREE) + for (i = 0; i < nargs; i++) + check_function_arguments_recurse (check_nonnull_arg, NULL, argarray[i], + i + 1); + else { - if (is_attribute_p ("nonnull", TREE_PURPOSE (a))) + /* Walk the argument list. If we encounter an argument number we + should check for non-null, do it. */ + for (i = 0; i < nargs; i++) { - args = TREE_VALUE (a); - - /* Walk the argument list. If we encounter an argument number we - should check for non-null, do it. If the attribute has no args, - then every pointer argument is checked (in which case the check - for pointer type is done in check_nonnull_arg). */ - for (i = 0; i < nargs; i++) + for (a = attrs; ; a = TREE_CHAIN (a)) { - if (!args || nonnull_check_p (args, i + 1)) - check_function_arguments_recurse (check_nonnull_arg, NULL, - argarray[i], - i + 1); + a = lookup_attribute ("nonnull", a); + if (a == NULL_TREE || nonnull_check_p (TREE_VALUE (a), i + 1)) + break; } + + if (a != NULL_TREE) + check_function_arguments_recurse (check_nonnull_arg, NULL, + argarray[i], i + 1); } } } |