[cfe-dev] constant propagation produces undef

Eli Friedman eli.friedman at gmail.com
Fri Jan 22 09:09:53 PST 2010


On Fri, Jan 22, 2010 at 8:57 AM,  <Alireza.Moshtaghi at microchip.com> wrote:
> I’m sure I’m missing something in my port for PIC16 because the following
> code produces undef for pic16 but it is ok for other ports but I’m not sure
> what is it that I’m missing.
>
> Looks like the constant propagation pass finds out that f() is always
> returning 16 and it tries to substitute the call site in the shift with
> statement 16. But since int is 16 bit it results in undef in the input of
> check() function while zero is expected.

If int is 16 bits, 1<<16 is undefined, not zero.  If you want a "safe"
shift, try defining something like the following:

static inline int safe_shift(int a, int b) {
  return b>=16?0:a<<b;
}

-Eli




More information about the cfe-dev mailing list