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

            Bug ID: 95136
           Summary: missing -Wuninitialized on an array access with a
                    variable offset
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC successfully reports uninitialized reads from arrays involving variable
indices but it fails to find the same bugs when besides the index the array
reference also includes an offset.  The test case below shows the difference.

In addition, the issued warning in these cases is missing essential detail such
as the name or location of the declaration of the variable.

$ cat x.c && gcc -O2 -S -Wall -fdump-tree-uninit=/dev/stdout x.c
int f (int i)
{ 
  int a[4];
  int *p = &a[i + 1];
  return *p;             // -Wuninitialized
}

int g (int i)
{
  int a[4];
  int *p = &a[i] + 1;
  return *p;             // missing warning
}

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

x.c: In function ‘f’:
x.c:5:10: warning: ‘a[<unknown>]’ is used uninitialized in this function
[-Wuninitialized]
    5 |   return *p;             // -Wuninitialized
      |          ^~
f (int i)
{
  int a[4];
  int _1;
  int _4;

  <bb 2> [local count: 1073741824]:
  _1 = i_2(D) + 1;
  _4 = MEM <int[4]> [(int *)&a][_1];
  a ={v} {CLOBBER};
  return _4;

}



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

g (int i)
{
  int a[4];
  int * _1;
  int _4;
  sizetype _6;
  sizetype _7;

  <bb 2> [local count: 1073741824]:
  _6 = (sizetype) i_2(D);
  _7 = _6 * 4;
  _1 = &a + _7;
  _4 = MEM[(int *)_1 + 4B];
  a ={v} {CLOBBER};
  return _4;

}

Reply via email to