[llvm-bugs] [Bug 39624] New: UB avoiding bit rotate pattern is not recognized for uint8 and uint16
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Nov 10 19:40:48 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=39624
Bug ID: 39624
Summary: UB avoiding bit rotate pattern is not recognized for
uint8 and uint16
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Common Code Generator Code
Assignee: unassignedbugs at nondot.org
Reporter: trass3r at gmail.com
CC: llvm-bugs at lists.llvm.org
The following pattern should be used to avoid UB and is also emitted by the
_rotl intrinsic in clang-cl mode but fails for small types:
uint8_t rotl(uint8_t x, unsigned int n)
{
constexpr unsigned width = 8*sizeof(x);
return (x << (n % width)) | (x >> (-n % width));
}
uint16_t rotl(uint16_t x, unsigned int n)
{
constexpr unsigned width = 8*sizeof(x);
return (x << (n % width)) | (x >> (-n % width));
}
uint32_t rotl(uint32_t x, unsigned int n)
{
constexpr unsigned width = 8*sizeof(x);
return (x << (n % width)) | (x >> (-n % width));
}
Inserting casts doesn't help.
https://godbolt.org/z/VQzPHk
--
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/20181111/20ed6223/attachment.html>
More information about the llvm-bugs
mailing list