I know there are many similar questions on SO. Please read carefully before calling this a dup. If it is, I would be happy to get a reference to the relevant question.
It seems to me that the clang sanitizer is complaining about a perfectly valid left shift of an unsigned number.
int main()
{
unsigned int x = 0x12345678;
x = x << 12;
return 15 & x;
}
Compiled thusly:
clang -fsanitize=undefined,integer shift-undefined.cpp -lubsan -lstdc++
Results in this error:
shift-undefined.cpp:4:11: runtime error: left shift of 305419896 by 12 places cannot be represented in type 'unsigned int'
I understand that some bits will be shifted off into oblivion, but I thought that was legal for unsigned numbers. What gives?