aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2020-06-28 14:22:14 -0600
committerMartin Sebor <msebor@redhat.com>2020-06-28 14:24:52 -0600
commit75ff24e1920ea6b198350a2961e23175e6108e75 (patch)
tree88dfd1e43a652ff5f769d9543cd22d764cbe29e3 /gcc/tree.c
parentce56fd949f359a62b86a45aaf975ac2ecc48fa64 (diff)
downloadgcc-75ff24e1920ea6b198350a2961e23175e6108e75.zip
gcc-75ff24e1920ea6b198350a2961e23175e6108e75.tar.gz
gcc-75ff24e1920ea6b198350a2961e23175e6108e75.tar.bz2
Underline argument in -Wnonnull and in C++ extend warning to the this pointer [PR c++/86568].
Resolves: PR c++/86568 - -Wnonnull warnings should highlight the relevant argument not the closing parenthesis gcc/c-family/ChangeLog: PR c++/86568 * c-common.c (struct nonnull_arg_ctx): Add members. (check_function_nonnull): Use nonnull_arg_ctx as argument. Handle C++ member functions specially. Consider the this pointer implicitly nonnull. (check_nonnull_arg): Use location of argument when available. (check_function_arguments): Use nonnull_arg_ctx as argument. gcc/ChangeLog: PR c++/86568 * calls.c (maybe_warn_rdwr_sizes): Use location of argument if available. * tree-ssa-ccp.c (pass_post_ipa_warn::execute): Same. Adjust indentation. * tree.c (get_nonnull_args): Consider the this pointer implicitly nonnull. * var-tracking.c (deps_vec): New type. (var_loc_dep_vec): New function. (VAR_LOC_DEP_VEC): Use it. gcc/testsuite/ChangeLog: PR c++/86568 * g++.dg/warn/Wnonnull5.C: New test. * c-c++-common/pr28656.c: Adjust text of expected warning. * c-c++-common/pr66208.c: Same. * g++.dg/cpp0x/nullptr22.C: Same. * g++.dg/ext/attr-nonnull.C: Same. * g++.dg/ext/attrib49.C: Same. * g++.dg/pr71973-2.C: Same. * g++.dg/warn/Wnonnull3.C: Same. * g++.dg/warn/Wnonnull4.C: Same. * obj-c++.dg/attributes/method-nonnull-1.mm: Same. * objc.dg/attributes/method-nonnull-1.m: Same.
Diffstat (limited to 'gcc/tree.c')
-rw-r--r--gcc/tree.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 805f669..342da55 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -14965,11 +14965,18 @@ get_nonnull_args (const_tree fntype)
if (fntype == NULL_TREE)
return NULL;
+ bitmap argmap = NULL;
+ if (TREE_CODE (fntype) == METHOD_TYPE)
+ {
+ /* The this pointer in C++ non-static member functions is
+ implicitly nonnull whether or not it's declared as such. */
+ argmap = BITMAP_ALLOC (NULL);
+ bitmap_set_bit (argmap, 0);
+ }
+
tree attrs = TYPE_ATTRIBUTES (fntype);
if (!attrs)
- return NULL;
-
- bitmap argmap = NULL;
+ return argmap;
/* A function declaration can specify multiple attribute nonnull,
each with zero or more arguments. The loop below creates a bitmap