[PATCH] Fixes -fsanitize=undefined warning about left-shifting a negative signed value.

Chandler Carruth chandlerc at google.com
Fri Jan 9 15:53:32 PST 2015


FYI, commented on Alexey's patch that I mildly prefer that source change to
fix this. (Shoulf have said that here, but I hadn't actually looked at the
patch, mea culpa.)

On Fri, Jan 9, 2015 at 3:46 PM, Alexey Samsonov <vonosmas at gmail.com> wrote:

> I've just encountered the same problem - it seems to be the last failure
> in UBSan bootstrap of check-llvm testsuite (and mailed
> http://reviews.llvm.org/D6908).
>
> On Thu, Jan 8, 2015 at 2:06 PM, Artem Belevich <tra at google.com> wrote:
>
>> I've attached the patch.
>>
>> The issue is that ubsan spotted a case where we extract 21 bits from a
>> negative signed addend value in order to encode it into binary
>> representation of reloc.
>>
>> While behavior is harmless in this case, technically it does fall under
>> undefined behavior. The patch extracts relevant bits into an unsigned
>> variable first and then uses that unsigned value to shift bits around.
>>
>> --Artem
>>
>> On Thu, Jan 8, 2015 at 1:46 PM, Chandler Carruth <chandlerc at google.com>
>> wrote:
>>
>>> FYI, could you attach the patch file rather than including it inline, or
>>> post it using Phabricator[1]?
>>>
>>> [1]: http://llvm.org/docs/Phabricator.html
>>>
>>>
>>> --
>> --Artem Belevich
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>>
>
>
> --
> Alexey Samsonov
> vonosmas at gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150109/7dd30983/attachment.html>


More information about the llvm-commits mailing list