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

            Bug ID: 86850
           Summary: ubsan: runtime error: member call on null pointer
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

This C code:

struct {
  long a[0]
} b;
c, d, k;
long l() {
  long e, g, h, j;
  int f, i;
  for (; i < 4; i++)
    j = h < 0;
  e += i >> i + j ^ j;
  g -= h + j ^ j;
  for (i--; i; i++) {
    j = -(h < 0);
    e += i >> i + j ^ g >> 1;
    g -= h >> 1 + j ^ j;
    h -= c + j ^ j;
  }
  return f << 7 + e;
}
m() {
  if (d)
    if (k)
      b.a[1] = b.a[0] = l() - 4;
}

when compiled by a recent ubsan version of trunk, does this:

$ ~/gcc/results.263285.ubsan/bin/gcc -c -O3 -std=c89 -w bug453.c
../../trunk/gcc/vec.h:1688:5: runtime error: member call on null pointer of
type 'struct vec'

It is fine at lower optimise levels:

$ ~/gcc/results.263285.ubsan/bin/gcc -c -O2 -std=c89 -w bug453.c
$

Reply via email to