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

            Bug ID: 83299
           Summary: result of pointer addition can be assumed to be less
                    than or equal to PTRDIFF_MAX
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

This may be due to the same underlying limitation as pr79119, but it seems that
it should be easier to infer from the type of the argument of a POINTER_PLUS
expression that the result cannot be less than the first operand when the
integer operand is unsigned.

If it isn't any easier feel free to resolve this as a duplicate of pr79119.

$ cat a.c && gcc -O3 -S -fdump-tree-optimized=/dev/stdout a.c
typedef __SIZE_TYPE__ size_t;

void f (char *p, size_t i)
{
  char *q = p + i;   // i must be less than or equal to PTRDIFF_MAX

  if ((size_t)(p - q) > __PTRDIFF_MAX__)   // cannot be true
    __builtin_abort ();
}

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

f (char * p, size_t i)
{
  signed long _5;

  <bb 2> [local count: 1073741825]:
  _5 = (signed long) i_2(D);
  if (_5 > 0)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [99.96%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073312327]:
  return;

}

Reply via email to