[PATCH] D32212: Create some helpers for generating bit masks
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 19 09:43:35 PDT 2017
Err, not sure why I'm talking about a static_cast, but in any case can you
test that out? I wasn't getting a warning with MSVC 2017
On Wed, Apr 19, 2017 at 9:43 AM Zachary Turner <zturner at google.com> wrote:
> We can just use a static_cast to get rid of the warning. MathExtras.h
> already has such a thing to silence this exact warning:
>
> // Replace "-Value" by "1+~Value" in the following commented code to
> avoid
> // MSVC warning C4146
> // return (A | B) & -(A | B);
> return (A | B) & (1 + ~(A | B));
>
>
> On Wed, Apr 19, 2017 at 9:26 AM Adrian McCarthy via Phabricator <
> reviews at reviews.llvm.org> wrote:
>
>> amccarth added inline comments.
>>
>>
>> ================
>> Comment at: llvm/trunk/include/llvm/Support/MathExtras.h:207
>> + assert(N <= Bits && "Invalid bit index");
>> + return -T(N != 0) & (T(-1) >> (Bits - N));
>> +}
>> ----------------
>> Be aware that this can lead to compiler warnings, at least in MSVC, if T
>> is an unsigned type:
>>
>> [[ https://msdn.microsoft.com/en-us/library/4kh09110.aspx | C4146:
>> unary minus operator applied to unsigned type, result still unsigned ]]
>>
>> Depending on the specific details, this can be a level 2 or level 3
>> warning. I'm surprised the tests aren't triggering it. We must disable
>> this warning somewhere.
>>
>>
>>
>>
>> Repository:
>> rL LLVM
>>
>> https://reviews.llvm.org/D32212
>>
>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170419/5fdece7e/attachment.html>
More information about the llvm-commits
mailing list