SUPERH platform development
 help / color / mirror / Atom feed
* likely signedness bug in arch/{m32r,sh}/include/asm/thread_info.h
@ 2015-07-20 21:02 Rasmus Villemoes
  0 siblings, 0 replies; only message in thread
From: Rasmus Villemoes @ 2015-07-20 21:02 UTC (permalink / raw)
  To: linux-sh

Right-shifted ~0 aka -1 always gives -1 again, since gcc always does
arithmetic right shift of signed types. So the common code (one is
copy-pasted from the other)

      ti->flags = (ti->flags & (~0 >> (32 - TI_FLAG_FAULT_CODE_SHIFT)))
              | (val << TI_FLAG_FAULT_CODE_SHIFT);

doesn't actually clear any of ti->flags; it's entirely equivalent to

      ti->flags |= (val << TI_FLAG_FAULT_CODE_SHIFT);

Presumably harmless since this hasn't been noticed before.

[Surprisingly, for non-const shifts, gcc doesn't realize the shift is a
noop: unsigned g(int s) { return ~0 >> s; } compiles to

        movl    %edi, %ecx
        movl    $-1, %eax
        sarl    %cl, %eax
        ret

Since ~0 >> whatever is almost always used as a mask, probably
gcc/sparse/smatch should warn about this and suggest using 0u.]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-20 21:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-20 21:02 likely signedness bug in arch/{m32r,sh}/include/asm/thread_info.h Rasmus Villemoes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox