Re: Undefined Code in .../include/linux.bitops.h

From: Clemens Ladisch
Date: Wed Feb 20 2013 - 11:11:38 EST

Jeffrey Walton wrote:
> is a tough read, and Item 4, "I think I found
> a bug, how do I report it?" does not tell me how to report this.

>From that page:
| A bug is when something (in the kernel, presumably) doesn't behave the
| way it should

So just tell us what it is that doesn't behave the way it should.

> According to Section 5.8, "Shift Operators" of

The kernel doesn't try to be fully standard conformant.

> return (word >> shift) | (word << (32 - shift));

> "The behavior is undefined if the right operand is ... equal to the
> length in bits of the promoted left operand."
> If I ask for a shift of 0

Does the kernel ever do this?

> the various ops will perform `32 - shift` (or `64 - shift`, etc). That
> means the right operand *IS* equal to the length in bits of the
> operand, so the code is undefined.

In practice, what CPUs actually do is to shift either by zero or by the
full 32/64 bits. Both implementations give the correct result.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at