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

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
The failures in Warray-bounds-56.c boil down to this test case where the
powerpc64 cross-compiler diagnoses only three out of the four buffer overflows,
 missing the one first one in f().  The native x86_64 compiler detects all of
them.  I'll adjust the test to avoid the failure but I'll probably raise a
separate bug to look into why it happens because it affects other tests as
well.

$ cat t.c && /build/powerpc64le-linux/gcc-svn/gcc/xgcc -B
/build/powerpc64le-linux/gcc-svn/gcc -O2 -S -Wall -Wno-stringop-overflow
-ftrack-macro-expansion=0 t.c
typedef __SIZE_TYPE__ size_t;

extern void* malloc (size_t);
extern char* strcpy (char*, const char*);

void sink (void*);

size_t value (void);

size_t range (size_t min, size_t max)
{
  size_t val = value ();
  return val < min || max < val ? min : val;
}

#undef T
#define T(T, src, n) do {                       \
    char *s = src;                              \
    typedef struct { T n, ax[]; } Flex;         \
    Flex *p = (Flex*)malloc (sizeof *p + n);    \
    char *d = (char*)p->ax;                     \
    strcpy (d, s);                              \
    sink (p);                                   \
  } while (0)

void f (void)
{
  size_t r_1_2 = range (1, 2);
  size_t r_2_3 = range (2, 3);

  T (char, "12", r_1_2);           // { dg-warning "\\\[-Warray-bounds" }
  T (char, "123456789", r_2_3);    // { dg-warning "\\\[-Warray-bounds" }
}

void g (void)
{
  size_t r_1_2 = range (1, 2);
  T (char, "12", r_1_2);           // { dg-warning "\\\[-Warray-bounds" }

  size_t r_2_3 = range (2, 3);
  T (char, "123456789", r_2_3);    // { dg-warning "\\\[-Warray-bounds" }
}

t.c: In function 'f':
t.c:32:3: warning: '__builtin_memcpy' forming offset [4, 10] is out of the
bounds [0, 4] [-Warray-bounds]
   32 |   T (char, "123456789", r_2_3);    // { dg-warning "\\\[-Warray-bounds"
}
      |   ^
t.c: In function 'g':
t.c:38:3: warning: '__builtin_memcpy' forming offset 3 is out of the bounds [0,
3] [-Warray-bounds]
   38 |   T (char, "12", r_1_2);           // { dg-warning "\\\[-Warray-bounds"
}
      |   ^
t.c:41:3: warning: '__builtin_memcpy' forming offset [4, 10] is out of the
bounds [0, 4] [-Warray-bounds]
   41 |   T (char, "123456789", r_2_3);    // { dg-warning "\\\[-Warray-bounds"
}
      |   ^

Reply via email to