[llvm-bugs] [Bug 52079] New: Undetected UB of shift operator with Clang 14

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 5 06:26:35 PDT 2021


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

            Bug ID: 52079
           Summary: Undetected UB of shift operator with Clang 14
           Product: new-bugs
           Version: 12.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: k.even-mendoza at imperial.ac.uk
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

This code example contains undetected UB with Clang 14 (also older versions):
int main() {
  if (0 << 2 % (short)((int)6503265032 << (int)(__CHAR_BIT__ + 6503265032)))
    return 0;
  return 0;
}

However, if I change a bit the number (e.g., 650326503), then clang-UBSan works
fine; also clang does give a warning during compilation, so UBSan should be
able to detect it.

GCC for example, gives these warnings:
8e588485791c300e738ae2773f5d270b24789c80_copy.c:2:40: runtime error: shift
exponent -2086669552 is negative
8e588485791c300e738ae2773f5d270b24789c80_copy.c:2:14: runtime error: division
by zero

-- 
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/20211005/1ee145ca/attachment.html>


More information about the llvm-bugs mailing list