On 10/31/22 21:54, Peter Zijlstra wrote:
PeterZ is contending that this isn't actually undefined behavior given how the
kernel is compiled[*]. That said, I would be in favor of replacing the open-coded
shift with BIT() to make the code a bit more self-documenting, and that would
naturally fix this maybe-undefined-behavior issue.
[*]https://lore.kernel.org/all/Y1%2FAaJOcgIc%2FINtv@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I'm definitely in favour of updating this code; both your suggestion and
hpa's suggestion look like sane changes. But I do feel that whatever
UBSAN thing generated this warning needs to be fixed too.
I'm fine with the compiler warning about this code -- but it must not
claim undefined behaviour given the compiler flags we use.
Yes, the compiler is buggy here (see old bug report for GCC, now fixed,
at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68418).
I cannot even reproduce the problem with the simple userspace testcase
#include <stdlib.h>
int main(int argc) {
int i = argc << 31;
exit(i < 0);
}
on either GCC 12 or clang 15.
Paolo