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

            Bug ID: 77627
           Summary: Unexpected void * dereference in uninit warning (and
                    missed out-of-bounds warning)
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fw at gcc dot gnu.org
  Target Milestone: ---

This snippet, derived from code provided by Ron Garret:

int main(int argc, char* argv[]) {
  int x[100] = {0};
  int y = x[101];
  int z = *(x+102);
  return y+z;
}

results in the following warning:

t.c: In function ‘main’:
t.c:3:12: warning: array subscript is above array bounds [-Warray-bounds]
   int y = x[101];
           ~^~~~~
t.c:4:7: warning: ‘*((void *)&x+408)’ is used uninitialized in this function
[-Wuninitialized]
   int z = *(x+102);
       ^

The expression *((void *)&x+408) looks rather out of place. C programmers do
not expect that void * pointers can be dereferenced in this way.

GCC clearly realizes that the subscript is out of bounds, so perhaps it would
be possible to issue an out-of-bounds warning for this case, too.

Reply via email to