undef value


I am opening llvm more and more for me, so now I have some questions about shifting and undef value:

  1. undef value is like a separate entity. But I have seen in some notes, that this is legal to compute expressions with undef value. So , undef |1 will be equal to one (the size of the result will depended on the size of one)? And undef & 0 will be equal to zero and so on?

  2. Is it compiler dependent (may be here there is a lack of my knowledges) that unoptimized version of llvm , when I try:

char a = 6;

char a = 2;

char c = 6<<2 - performs sext on 6 before performing a 32 bit shl?

Thank you in advance for the answers.

I have also tested and found out, that however in this example:
unsigned a = 1;
unsigned b = a << 33;
for (int i = 0; i < 32; i++)
printf("%d ", ((b >> i) & 1));
return b;

I get the undef value at the end:

ret i32 undef

he bits are printed correctly - shifted by the modulo, as is defined in the standard. What is the explanation?

This seems like a misunderstanding of the standard.

For unsigned a, a << b is equal to (a * pow(2,b)) % (MAXUINT+1), except if b is greater than or equal to the word size, in which case the result is undefined.

For the particular case of 1 << 33, many machines will give 0 and many will give 2. Some many give other values. As far as the C standard, the result is undefined and llvm is correct.

Ok, thank you for the clarification.