<div dir="auto">It looks like the complaint is about overflow of the pointer itself, which makes sense since you are adding a very large unsigned number to it. Maybe use ptrdiff_t for inc?<div dir="auto"><br></div><div dir="auto">I forget the rules for pointer overflow, but if pointer overflow is UB, then this seems like a perfectly fine error.<br><div dir="auto"><br><div dir="auto">-- Sean Silva</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Dec 16, 2017 12:18 PM, "Jeffrey Walton via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">We have code that processes a buffer in the forward or backwards<br>
direction. It looks similar to the following<br>
(<a href="https://github.com/weidai11/cryptopp/blob/master/adv-simd.h#L1138" rel="noreferrer" target="_blank">https://github.com/weidai11/<wbr>cryptopp/blob/master/adv-simd.<wbr>h#L1138</a>):<br>
<br>
uint8_t * ptr = ...<br>
size_t len = ...<br>
size_t inc = 16;<br>
<br>
if (flags & REVERSE_DIRECTION)<br>
{<br>
    ptr += len - inc;<br>
    inc = 0-inc;<br>
}<br>
<br>
while (len > 16)<br>
{<br>
    // process blocks<br>
<br>
    ptr += inc;<br>
    len -= 16;<br>
}<br>
<br>
Clang 5.0 and UBsan is producing findings<br>
(<a href="https://travis-ci.org/noloader/cryptopp/jobs/317442299#L967" rel="noreferrer" target="_blank">https://travis-ci.org/<wbr>noloader/cryptopp/jobs/<wbr>317442299#L967</a>):<br>
<br>
adv-simd.h:1138:26: runtime error: addition of unsigned offset to<br>
0x000003f78cf0 overflowed to 0x000003f78ce0<br>
adv-simd.h:1140:26: runtime error: addition of unsigned offset to<br>
0x000003f78ce0 overflowed to 0x000003f78cd0<br>
adv-simd.h:1142:26: runtime error: addition of unsigned offset to<br>
0x000003f78cd0 overflowed to 0x000003f78cc0<br>
...<br>
<br>
Lines 1138, 1140, 1142 (and friends) are the increment, which may<br>
stride backwards:<br>
<br>
    ptr += inc;<br>
<br>
The overflow is troubling because signed integer overflow is undefined<br>
behavior. The code above depends on unsigned wrap, and that's well<br>
defined behavior. We don't know where the signed operations are coming<br>
from.<br>
<br>
Previous versions of Clang and GCC did not produce a finding.<br>
<br>
My questions are, what is going on, and how do I fix it?<br>
<br>
Jeff<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>