Hi!

When investigating bit shifts I got an incomprehensible moment with
the following example:

int f(int x, int k)
{
    int tmp = x >> k;
    return (tmp & 1) << 10;
}

If we would like to take a look into GIMPLE then we'll get:

int f (int x, int k)
{
  int tmp;
  int D.2746;
  int _1;
  int _5;

  <bb 2> :
  tmp_4 = x_2(D) >> k_3(D);
  _1 = tmp_4 << 10;
  _5 = _1 & 1024;

  <bb 3> :
<L0>:
  return _5;

}

Is the expression '_1 = tmp_4 << 10' considered legal in GIMPLE? Given the
semantics of C bit shifts, this statement could modify the sign bit,
potentially leading to overflow.

---
With best regards,
Daniil

Reply via email to