[compiler-rt] r243241 - tsan: fix shift overflow

Dmitry Vyukov dvyukov at google.com
Mon Jul 27 13:27:03 PDT 2015


On Mon, Jul 27, 2015 at 10:19 PM, Davide Italiano <davide at freebsd.org> wrote:
> On Mon, Jul 27, 2015 at 1:00 PM, Dmitry Vyukov <dvyukov at google.com> wrote:
>> I miserably failed to acknowledge the right tool. I did not run it
>> under ubsan. It is a new gcc warning that caught it:
>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67009
>>
>
> For what it's worth Clang has the same very warning -- but it's not
> able to cathc your specific case. I'll open a bug for that.

Yeah, it makes sense.

> % cat shift.c
> #include <sys/types.h>
>
> static const uint32_t kFlagSync  = 2 << 30;
> static const uint32_t kFlagSync2 = 1 << 35;
>
> % ./clang shift.c -Wshift-overflow
> shift.c:4:38: warning: shift count >= width of type [-Wshift-count-overflow]
> static const uint32_t kFlagSync2 = 1 << 35;
>                                      ^  ~~
>

I guess clang misses signedness of the value, so it assumes that it is
32-bits, while it actually has only 31-bits.



More information about the llvm-commits mailing list