<div dir="ltr">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</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 19, 2017 at 9:43 AM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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:<div><br></div><div><div>  // Replace "-Value" by "1+~Value" in the following commented code to avoid</div><div>  // MSVC warning C4146</div><div>  //    return (A | B) & -(A | B);</div></div><div><div>  return (A | B) & (1 + ~(A | B));</div></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Apr 19, 2017 at 9:26 AM Adrian McCarthy via Phabricator <<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">amccarth added inline comments.<br>
<br>
<br>
================<br>
Comment at: llvm/trunk/include/llvm/Support/MathExtras.h:207<br>
+  assert(N <= Bits && "Invalid bit index");<br>
+  return -T(N != 0) & (T(-1) >> (Bits - N));<br>
+}<br>
----------------<br>
Be aware that this can lead to compiler warnings, at least in MSVC, if T is an unsigned type:<br>
<br>
 [[ <a href="https://msdn.microsoft.com/en-us/library/4kh09110.aspx" rel="noreferrer" target="_blank">https://msdn.microsoft.com/en-us/library/4kh09110.aspx</a> |  C4146: unary minus operator applied to unsigned type, result still unsigned ]]<br>
<br>
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.<br>
<br>
<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D32212" rel="noreferrer" target="_blank">https://reviews.llvm.org/D32212</a><br>
<br>
<br>
<br>
</blockquote></div></blockquote></div>