public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/99944] New: incorrect maybe-uninitialized warning on variable defined as an array
@ 2021-04-06 20:59 vincent-gcc at vinc17 dot net
  2021-04-07  7:25 ` [Bug c/99944] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2021-04-06 20:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 99944
           Summary: incorrect maybe-uninitialized warning on variable
                    defined as an array
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincent-gcc at vinc17 dot net
  Target Milestone: ---

Consider the following testcase derived from the initial testcase of PR85777
and its cleaned-up testcase (which is actually a bit different since an enum
was replaced by an int, and it matters here).

int d;
int h(void);
void e1(void)
{
  int f[2];
  int g = 0;
  if (d)
    g++;
  if (d == 1)
    f[g++] = 2;
  (void) (f[0] || (g && h()));
}
void e2(void)
{
  enum { a } f[2];
  int g = 0;
  if (d)
    g++;
  if (d == 1)
    f[g++] = a;
  (void) (f[0] || (g && h()));
}

With a GCC snapshot built a few hour ago from the master branch:

cventin% gcc --version
gcc (GCC) 11.0.1 20210406 (experimental)
[...]

cventin% gcc -Werror=maybe-uninitialized -O2 -c file.c
file.c: In function ‘e1’:
file.c:11:3: error: ‘f[0]’ may be used uninitialized
[-Werror=maybe-uninitialized]
   11 |   (void) (f[0] || (g && h()));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
file.c: In function ‘e2’:
file.c:21:3: error: ‘*(unsigned int *)(&f[0])’ may be used uninitialized
[-Werror=maybe-uninitialized]
   21 |   (void) (f[0] || (g && h()));
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors

The error for e1 is correct, but not the one for e2 (for e2, previous GCC
versions were outputting ‘f’ instead of ‘*(unsigned int *)(&f[0])’, but this is
about the same thing).

cventin% gcc -Werror=maybe-uninitialized -O2 -c file.c -fsanitize=undefined
file.c: In function ‘e1’:
file.c:11:12: error: ‘f’ may be used uninitialized
[-Werror=maybe-uninitialized]
   11 |   (void) (f[0] || (g && h()));
      |           ~^~~
file.c:5:7: note: ‘f’ declared here
    5 |   int f[2];
      |       ^
file.c: In function ‘e2’:
file.c:21:12: error: ‘f’ may be used uninitialized
[-Werror=maybe-uninitialized]
   21 |   (void) (f[0] || (g && h()));
      |           ~^~~
file.c:15:14: note: ‘f’ declared here
   15 |   enum { a } f[2];
      |              ^
cc1: some warnings being treated as errors

Here, with the option -fsanitize=undefined added, both errors are incorrect.

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

end of thread, other threads:[~2021-04-14 16:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-06 20:59 [Bug c/99944] New: incorrect maybe-uninitialized warning on variable defined as an array vincent-gcc at vinc17 dot net
2021-04-07  7:25 ` [Bug c/99944] " rguenth at gcc dot gnu.org
2021-04-07  7:41 ` vincent-gcc at vinc17 dot net
2021-04-14 16:38 ` [Bug c/99944] poor format of array reference in -Wuninitialized 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).