[LLVMbugs] [Bug 22253] -Wdivision-by-zero does not warn on "1000 / (unsigned char)(a << 8)"

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu May 21 17:11:23 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=22253

Chengnian Sun <chengniansun at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #5 from Chengnian Sun <chengniansun at gmail.com> ---
(In reply to comment #3)
> (In reply to comment #2)
> > Is clang really wrong here?
> > There's no guarantte that a is zero if I recall correctly the C standard.
> 
> Can you elaborate more why the expression "(unsigned char)(a << 8)" is NOT
> zero? 
> 
> Thanks.

I did not see any undefined behavior here. The expression 'a << 8' will yield a
value of which the lowest 8 bits are 0. The cast from int to unsigned char will
only keep the lowest 8 bits. 

Please correct me if I am wrong. Thanks.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150522/7a817f33/attachment.html>


More information about the llvm-bugs mailing list