public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis Date: Wed, 03 Jun 2020 17:12:16 +0000 [thread overview] Message-ID: <bug-86568-4-ReWRJcE20h@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-86568-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568 Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2020-06-03 Ever confirmed|0 |1 CC| |msebor at gcc dot gnu.org Known to fail| |10.1.0, 11.0, 9.2.0 Blocks| |95507 Status|UNCONFIRMED |NEW --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. The problem isn't unique to -Wnonnull but affects other warnings as well. An example involving -Walloc-size-larger-than is below. The middle end warnings use the location of the call when they should instead be using the location of the argument (when it has one). $ cat z.c && gcc -O2 -S -Wall -Wpedantic z.c typedef __SIZE_TYPE__ size_t; __attribute__ ((alloc_size (2))) void* f (const char*, size_t, int); void* g (void) { size_t n = (size_t)-1 / 2; return f ("foo", n + 1, 0); } z.c: In function ‘g’: z.c:9:10: warning: argument 2 value ‘9223372036854775808’ exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=] 9 | return f ("foo", n + 1, 0); | ^~~~~~~~~~~~~~~~~~~ z.c:3:40: note: in a call to allocation function ‘f’ declared here 3 | __attribute__ ((alloc_size (2))) void* f (const char*, size_t, int); | ^ I'm not too familiar with the front end implementation but it too looks like it uses the location of the call. The patch below produces the (almost) expected output for the simple test case. The argument numbers are still off. index b1379faa412..9c5e76c1e59 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5497,7 +5497,10 @@ check_nonnull_arg (void *ctx, tree param, unsigned HOST_WIDE_INT param_num) /* Diagnose the simple cases of null arguments. */ if (integer_zerop (fold_for_warn (param))) { - warning_at (pctx->loc, OPT_Wnonnull, "null argument where non-null " + location_t loc + = EXPR_HAS_LOCATION (param) ? EXPR_LOCATION (param) : pctx->loc; + + warning_at (loc, OPT_Wnonnull, "null argument where non-null " "required (argument %lu)", (unsigned long) param_num); pctx->warned_p = true; } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95507 [Bug 95507] [meta-bug] bogus/missing -Wnonnull
next parent reply other threads:[~2020-06-03 17:12 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/> 2020-06-03 17:12 ` msebor at gcc dot gnu.org [this message] 2020-06-05 19:42 ` msebor at gcc dot gnu.org 2020-06-26 9:03 ` redi at gcc dot gnu.org 2020-06-26 9:04 ` redi at gcc dot gnu.org 2020-06-26 13:33 ` redi at gcc dot gnu.org 2020-06-28 20:25 ` cvs-commit at gcc dot gnu.org 2020-06-28 20:40 ` msebor at gcc dot gnu.org 2020-06-29 11:51 ` cvs-commit at gcc dot gnu.org 2020-06-29 12:38 ` cvs-commit at gcc dot gnu.org 2020-06-29 12:49 ` cvs-commit at gcc dot gnu.org 2020-07-01 14:33 ` cvs-commit at gcc dot gnu.org 2021-05-04 12:31 ` rguenth at gcc dot gnu.org 2022-01-26 17:13 ` msebor at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-86568-4-ReWRJcE20h@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).