public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102558] New: missing warning comparing T[static N] to null
@ 2021-10-01 16:42 msebor at gcc dot gnu.org
  2023-08-05 13:31 ` [Bug c/102558] " muecker at gwdg dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-01 16:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102558
           Summary: missing warning comparing T[static N] to null
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

This is the diagnostic part of pr102556:

The C99 [static N] array notation in a function parameter indicates that the
caller must provide as an argument an array with at least N element. 
Therefore, in the body of the function, the parameter may be assumed to be
nonnull, the same way as if it had been declared with attribute nonnull.

The test case below shows that GCC fails to issue a warning for the pointless
equality expression in g(), equivalent to the one in f() (although -Waddress
might be more suitable than than -Wnonnull-compare).

$ cat z.c && gcc -O2 -S -Wall z.c
__attribute__ ((nonnull)) int f (int *a)
{
  return a == 0;   // warning (good, folded to false)
}

int g (int a[static 1])
{
  return a == 0;   // missing warning (not folded)
}
z.c: In function ‘f’:
z.c:3:12: warning: ‘nonnull’ argument ‘a’ compared to NULL [-Wnonnull-compare]
    3 |   return a == 0;   // warning (good, folded to false)
      |          ~~^~~~

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

* [Bug c/102558] missing warning comparing T[static N] to null
  2021-10-01 16:42 [Bug c/102558] New: missing warning comparing T[static N] to null msebor at gcc dot gnu.org
@ 2023-08-05 13:31 ` muecker at gwdg dot de
  2023-12-17 19:40 ` uecker at gcc dot gnu.org
  2023-12-17 19:43 ` uecker at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: muecker at gwdg dot de @ 2023-08-05 13:31 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Uecker <muecker at gwdg dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |muecker at gwdg dot de

--- Comment #1 from Martin Uecker <muecker at gwdg dot de> ---
Possibly fix by synthesizing a nonnull attribute:

https://gcc.gnu.org/pipermail/gcc-patches/2023-July/625559.html

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

* [Bug c/102558] missing warning comparing T[static N] to null
  2021-10-01 16:42 [Bug c/102558] New: missing warning comparing T[static N] to null msebor at gcc dot gnu.org
  2023-08-05 13:31 ` [Bug c/102558] " muecker at gwdg dot de
@ 2023-12-17 19:40 ` uecker at gcc dot gnu.org
  2023-12-17 19:43 ` uecker at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: uecker at gcc dot gnu.org @ 2023-12-17 19:40 UTC (permalink / raw)
  To: gcc-bugs

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

uecker at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0
                 CC|                            |uecker at gcc dot gnu.org

--- Comment #2 from uecker at gcc dot gnu.org ---
Fixed on trunk.

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

* [Bug c/102558] missing warning comparing T[static N] to null
  2021-10-01 16:42 [Bug c/102558] New: missing warning comparing T[static N] to null msebor at gcc dot gnu.org
  2023-08-05 13:31 ` [Bug c/102558] " muecker at gwdg dot de
  2023-12-17 19:40 ` uecker at gcc dot gnu.org
@ 2023-12-17 19:43 ` uecker at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: uecker at gcc dot gnu.org @ 2023-12-17 19:43 UTC (permalink / raw)
  To: gcc-bugs

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

uecker at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from uecker at gcc dot gnu.org ---
.

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

end of thread, other threads:[~2023-12-17 19:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 16:42 [Bug c/102558] New: missing warning comparing T[static N] to null msebor at gcc dot gnu.org
2023-08-05 13:31 ` [Bug c/102558] " muecker at gwdg dot de
2023-12-17 19:40 ` uecker at gcc dot gnu.org
2023-12-17 19:43 ` uecker 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).