[cfe-dev] constant propagation produces undef

Alireza.Moshtaghi at microchip.com Alireza.Moshtaghi at microchip.com
Fri Jan 22 09:24:42 PST 2010

For us all undefined values are zero, I tried it on ARM and X86 also and
clang generates zero, and not an undefined.

Maybe the better question would be "how can I tell clang to replace all
undefined values with zero constant?"


-----Original Message-----
From: Eli Friedman [mailto:eli.friedman at gmail.com] 
Sent: Friday, January 22, 2010 10:10 AM
To: Alireza Moshtaghi - C13012
Cc: cfe-dev at cs.uiuc.edu
Subject: Re: [cfe-dev] constant propagation produces undef

On Fri, Jan 22, 2010 at 8:57 AM,  <Alireza.Moshtaghi at microchip.com>
> I'm sure I'm missing something in my port for PIC16 because the
> code produces undef for pic16 but it is ok for other ports but I'm not
> 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
> statement 16. But since int is 16 bit it results in undef in the input
> 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;


More information about the cfe-dev mailing list