<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Yes,<div><span style="background-color: rgba(255, 255, 255, 0);"> #define ALPHA_OFFSET 0x3</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">should turn off the diagnostic. (We skip hex decimals).</span></div><div><br><div dir="ltr"><br>Dňa 19. 8. 2019 o 20:06 užívateľ Arthur O'Dwyer <<a href="mailto:arthur.j.odwyer@gmail.com">arthur.j.odwyer@gmail.com</a>> napísal:<br><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div dir="ltr">On Mon, Aug 19, 2019 at 1:53 PM Nico Weber via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>this results in a false positive on webrtc, on this code:</div><div><br></div><div><a href="https://cs.chromium.org/chromium/src/third_party/libwebp/src/enc/picture_csp_enc.c?q=picture_csp_enc.c&sq=package:chromium&dr&l=1002" target="_blank">https://cs.chromium.org/chromium/src/third_party/libwebp/src/enc/picture_csp_enc.c?q=picture_csp_enc.c&sq=package:chromium&dr&l=1002</a><br></div><div><br></div><div>The code does this:</div><div><br></div><div>#ifdef WORDS_BIGENDIAN<br>#define ALPHA_OFFSET 0 // uint32_t 0xff000000 is 0xff,00,00,00 in memory<br>#else<br>#define ALPHA_OFFSET 3 // uint32_t 0xff000000 is 0x00,00,00,ff in memory<br>#endif<br></div><div><br></div><div>// ...</div><div><br></div><div> const uint8_t* const argb = (const uint8_t*)picture->argb;<br> const uint8_t* const a = argb + (0 ^ ALPHA_OFFSET);<br> const uint8_t* const r = argb + (1 ^ ALPHA_OFFSET);<br> const uint8_t* const g = argb + (2 ^ ALPHA_OFFSET);<br> const uint8_t* const b = argb + (3 ^ ALPHA_OFFSET);<br></div><div><br></div><div>The idea is to get bytes 0, 1, 2, 3 as a, r, g, b if ALPHA_OFFSET is 0, or bytes 3, 2, 1, 0 if ALPHA_OFFSET is 3.</div><div><br></div><div>Maybe this shouldn't fire if the rhs is a macro?</div></div></blockquote><div><br></div><div>Does it show a fix-it that suggests replacing</div><div> #define ALPHA_OFFSET 3</div><div>with</div><div> #define ALPHA_OFFSET 0x3</div><div>? That would be the quickest way to shut up the warning, if I understand correctly. The use of hexadecimal or octal or binary indicates unambiguously that you mean to do a bitwise operation (xor), not an arithmetic one (pow).</div><div><br></div><div>If the use of a macro here <i><b>prevents</b></i> the hex workaround from working, then I'd call that a bug in the diagnostic.</div><div><br></div><div>It would be great if Clang could do what humans do instinctively, and see that this "2 ^ FOO" is actually part of a larger pattern — "0 ^ FOO, 1 ^ FOO, 2 ^ FOO, 3 ^ FOO" — and therefore it probably isn't wrong unless the three surrounding lines are also wrong. However, I'm pretty sure that Clang isn't set up to discover "patterns" like this in general. It sees "2 ^ LITERAL_EXPONENT" and gives a warning regardless of the surrounding lines.</div><div><br></div><div>–Arthur</div></div></div>
</div></blockquote></div></body></html>