public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
@ 2020-06-03 17:12 ` msebor at gcc dot gnu.org
  2020-06-05 19:42 ` msebor at gcc dot gnu.org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-03 17:12 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
  2020-06-03 17:12 ` [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis msebor at gcc dot gnu.org
@ 2020-06-05 19:42 ` msebor at gcc dot gnu.org
  2020-06-26  9:03 ` redi at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-05 19:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |msebor at gcc dot gnu.org
             Status|NEW                         |ASSIGNED
           Keywords|                            |patch

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Full patch: https://gcc.gnu.org/pipermail/gcc-patches/2020-June/547415.html

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
  2020-06-03 17:12 ` [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis msebor at gcc dot gnu.org
  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
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-26  9:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |haoxintu at gmail dot com

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 95892 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  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
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-26  9:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
PR 95892 points out the -Wsign-conversion warnings below all have the location
of the closing parenthesis:

unsigned int var = 10;
void foo ( 
    int a = var, 
    int b = var,
    int c = var )   
{    }

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  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
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: redi at gcc dot gnu.org @ 2020-06-26 13:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
*** Bug 95831 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  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
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-28 20:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:75ff24e1920ea6b198350a2961e23175e6108e75

commit r11-1697-g75ff24e1920ea6b198350a2961e23175e6108e75
Author: Martin Sebor <msebor@redhat.com>
Date:   Sun Jun 28 14:22:14 2020 -0600

    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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  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
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-28 20:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
There's still more work to do to make the argument location available to the
warning code (e.g., when passing the literal 0 or nullptr, or to the middle
end) so I'm going to leave this open, but for the following variant of the test
case in comment #0 GCC now prints the warnings below:

$ cat pr86568.C && gcc -O2 -S -Wall pr86568.C
void f(void*, void*) __attribute__((nonnull(2)));

struct A {
  void f(void*, void*) __attribute__((nonnull(2)));
};

int main()
{
  void * const p = 0;

  f(p, p);
  A().f(p, p);
}
pr86568.C: In function ‘int main()’:
pr86568.C:11:8: warning: argument 2 null where non-null expected [-Wnonnull]
   11 |   f(p, p);
      |        ^
pr86568.C:1:6: note: in a call to function ‘void f(void*, void*)’ declared
‘nonnull’
    1 | void f(void*, void*) __attribute__((nonnull(2)));
      |      ^
pr86568.C:12:9: warning: argument 1 null where non-null expected [-Wnonnull]
   12 |   A().f(p, p);
      |         ^
pr86568.C:4:8: note: in a call to function ‘void A::f(void*, void*)’ declared
‘nonnull’
    4 |   void f(void*, void*) __attribute__((nonnull(2)));
      |        ^

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-29 11:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:fe7c43a7bc72931941dec20df0df5993c932f964

commit r11-1707-gfe7c43a7bc72931941dec20df0df5993c932f964
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 29 13:47:44 2020 +0200

    testsuite: Adjust testcase for recent -Wnonnull changes

    2020-06-29  Jakub Jelinek  <jakub@redhat.com>

            PR c++/86568
    gcc/testsuite/
            * c-c++-common/builtin-arith-overflow-1.c (generic_3,
typed_3_null):
            Adjust dg-warning.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-29 12:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

https://gcc.gnu.org/g:baa4578911dbcc247110934505efdb6590e0f1b6

commit r11-1708-gbaa4578911dbcc247110934505efdb6590e0f1b6
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Mon Jun 29 14:25:00 2020 +0200

    testsuite: Adjust testcase for recent -Wnonnull changes

    2020-06-29  Jakub Jelinek  <jakub@redhat.com>

            PR c++/86568
            * c-c++-common/builtin-arith-overflow-1.c (generic_3,
typed_3_null):
            Adjust dg-warning.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-06-29 12:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Liska <marxin@gcc.gnu.org>:

https://gcc.gnu.org/g:95d7d7f92924bca0dc04df95b14d7d1b56f92d98

commit r11-1711-g95d7d7f92924bca0dc04df95b14d7d1b56f92d98
Author: Martin Liska <mliska@suse.cz>
Date:   Mon Jun 29 14:24:33 2020 +0200

    testsuite: Fix coding style.

    2020-06-29  Martin Liska  <mliska@suse.cz>

            PR c++/86568
            * c-c++-common/builtin-arith-overflow-1.c (generic_3,
typed_3_null):
            Fix coding style.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  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
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-01 14:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Martin Sebor <msebor@gcc.gnu.org>:

https://gcc.gnu.org/g:8461191b826654a30eaaa57257bcca8e548f11c2

commit r11-1760-g8461191b826654a30eaaa57257bcca8e548f11c2
Author: Martin Sebor <msebor@redhat.com>
Date:   Wed Jul 1 08:30:52 2020 -0600

    Adjust text of expected warnings changed in PR c++/86568.

    libstdc++-v3/ChangeLog:

            * testsuite/21_strings/basic_string_view/cons/char/nonnull.cc:
Adjust
            text of expected warning.
            * testsuite/21_strings/basic_string_view/cons/wchar_t/nonnull.cc:
Same.
            *
testsuite/21_strings/basic_string_view/operations/compare/char/nonnull.cc:
Same.
            *
testsuite/21_strings/basic_string_view/operations/find/char/nonnull.cc: Same.
            *
testsuite/21_strings/basic_string_view/operations/rfind/char/nonnull.cc: Same.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  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
  12 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-05-04 12:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis
       [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
                   ` (11 preceding siblings ...)
  2021-05-04 12:31 ` rguenth at gcc dot gnu.org
@ 2022-01-26 17:13 ` msebor at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: msebor at gcc dot gnu.org @ 2022-01-26 17:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86568

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW
           Assignee|msebor at gcc dot gnu.org          |unassigned at gcc dot gnu.org

--- Comment #12 from Martin Sebor <msebor at gcc dot gnu.org> ---
I'm not working on this anymore.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-01-26 17:13 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-86568-4@http.gcc.gnu.org/bugzilla/>
2020-06-03 17:12 ` [Bug c++/86568] -Wnonnull warnings should highlight the relevant argument not the closing parenthesis msebor at gcc dot gnu.org
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

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).