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: unassignedb...@nondot.org
          Reporter: tras...@gmail.com
                CC: llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to