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

--- Comment #17 from Martin Sebor <msebor at gcc dot gnu.org> ---
As you observed, the warning disappears if the assert is removed, so that's one
workaround.  But rather than working around it I would suggest to rewrite the
code to avoid the pointer subtraction.  Chances are it will not only avoid the
warning but help improve the emitted object code.  I'm not sure I understand
correctly what the test case is meant to do but the example below shows what
I'm thinking of.  If modifying the code isn't feasible then #pragma GCC
diagnostic is the recommended suppression mechanism.

typedef unsigned char byte;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __SIZE_TYPE__ size_t;

typedef struct pstream_t {
  const byte * p;
  ptrdiff_t n;
} pstream_t;

static inline _Bool ps_has (const pstream_t *ps, size_t len)
{
  return (size_t)ps->n >= len;
}

static inline int __ps_skip (pstream_t * ps, size_t len)
{
  if (!ps_has (ps, len))
    __builtin_abort ();
  ps->p += len;
  ps->n -= len;
  return 0;
}

static inline int ps_skip (pstream_t * ps, size_t len)
{
  return ps_has (ps, len) ? __ps_skip(ps, len) : -1;
}

byte c;
int c_len;

void f(void)
{
  pstream_t ps = { &c, c_len };

  ps_skip (&ps, 7);
}

Reply via email to