public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/102103] New: missing warning for arrays
@ 2021-08-27 19:21 msebor at gcc dot gnu.org
  2021-08-27 19:23 ` [Bug c/102103] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-08-27 19:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102103
           Summary: missing warning for arrays
           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: ---

GCC issues -Waddress only for the equality test in f() but not those in g() or
h(), even though all three evaluate to false (and even though GCC folds all
three to false even with no optimization).  It would be helpful to diagnose all
three.

$ cat z.c && gcc -S -Wall -fdump-tree-optimized=/dev/stdout z.c
void f (void)
{ 
  int i;
  if (&i == 0)   // -Waddress (good)
    __builtin_abort ();
}

void g (void)
{
  int a[1];
  if (a == 0)   // missing warning
    __builtin_abort ();
}

void h (void)
{
  int a[1][2];
  if (a[0] == 0)   // missing warning
    __builtin_abort ();
}

z.c: In function ‘f’:
z.c:4:10: warning: the comparison will always evaluate as ‘false’ for the
address of ‘i’ will never be NULL [-Waddress]
    4 |   if (&i == 0)   // -Waddress (good)
      |          ^~

;; Function f (f, funcdef_no=0, decl_uid=1943, cgraph_uid=1, symbol_order=0)

void f ()
{
  int i;

  <bb 2> :
  i ={v} {CLOBBER};
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1947, cgraph_uid=2, symbol_order=1)

void g ()
{
  int a[1];

  <bb 2> :
  a ={v} {CLOBBER};
  return;

}



;; Function h (h, funcdef_no=2, decl_uid=1951, cgraph_uid=3, symbol_order=2)

void h ()
{
  int a[1][2];

  <bb 2> :
  a ={v} {CLOBBER};
  return;

}


Clang diagnoses both the one in f() and in g() (but not the one in h()).  GCC
4.4.7 does as well but the latter has been lost since GCC 4.5  (see
https://gcc.godbolt.org/z/8dbjxv89E) so technically this could be viewed as a
regression.

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

end of thread, other threads:[~2021-10-02  9:10 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27 19:21 [Bug c/102103] New: missing warning for arrays msebor at gcc dot gnu.org
2021-08-27 19:23 ` [Bug c/102103] " pinskia at gcc dot gnu.org
2021-08-30 23:00 ` [Bug c/102103] missing warning comparing array address to null msebor at gcc dot gnu.org
2021-09-01  2:22 ` msebor at gcc dot gnu.org
2021-10-01 17:57 ` cvs-commit at gcc dot gnu.org
2021-10-01 18:00 ` msebor at gcc dot gnu.org
2021-10-02  9:10 ` egallager 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).