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

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> ---
(In reply to Jakub Jelinek from comment #3)
> On the other side, one could argue that ECF_RET1 is a pure optimization
> thing and unless the compiler optimizes hard, when you use the return value
> of memcpy/memset etc. and call objsz on that what exact subobject it points
> to can be lost.  Definitely older versions of gcc wouldn't be able to track
> that, I bet they'd return a don't know value in those cases (all ones or 0
> depending on mode).

We can avoid memset.  if I rewrite the fail() function to be simply:

  r = &a.a[4] + 2;
  if (__builtin_object_size (r, 3) != sizeof (a.a) - 6)
    __builtin_abort ();

it goes from (in early_objsz)

 <bb 2> :
  r_2 = &a.a[4] + 2;
  _5 = __builtin_object_size (r_2, 3);
  _1 = MAX_EXPR <_5, 4>;
  if (_1 != 4)
    goto <bb 3>; [INV]
  else
    goto <bb 4>; [INV]

  <bb 3> :
  __builtin_abort ();

  <bb 4> :
  return;

to (in ccp1)

  <bb 2> :
  __builtin_abort ();

}

via

Folding statement: r_2 = &a.a[4] + 2;
Queued stmt for removal.  Folds to: &MEM <char> [(void *)&a + 6B]
Folding statement: _5 = __builtin_object_size (r_2, 3);
Queued stmt for removal.  Folds to: 22
Folding statement: _1 = MAX_EXPR <_5, 4>;
Queued stmt for removal.  Folds to: 22
Folding statement: if (_1 != 4) 
gimple_simplified to if (1 != 0)
which is likely CONSTANT
Match-and-simplified 1 != 0 to 1
Folding predicate 1 != 0 to 1
Folded into: if (1 != 0)

Reply via email to