[LLVMbugs] [Bug 20902] New: False positives related to __builtin_clzll() and std::vector

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Sep 10 21:52:08 PDT 2014


            Bug ID: 20902
           Summary: False positives related to __builtin_clzll() and
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: wschudy at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13017
  --> http://llvm.org/bugs/attachment.cgi?id=13017&action=edit
scan-build error report demonstrating the bug

Running scan-build on this program yeilds a warning about the result of the
left-shift expression being undefined, which appears to be spurious, and a note
that the 'true' branch of an 'if' is taken, which is definitely invalid. I've
attached the scan-build error report. Running the program confirms the obvious:
the 'false' branch of the 'if' is taken. The expected output is no bug reports
and (optionally) a note that the 'false' branch of the 'if' is taken.

------ Details ------

I created a fresh Ubuntu 14.04.1 install. I then installed the packages
clang-3.5 and g++ with apt-get. 

wschudy at ubuntu:~$ cat test.cc
#include <cstdio>
#include <vector>

inline int Log2Floor64(unsigned long long n) {
  return n == 0 ? -1 : 63 ^ __builtin_clzll(n);

int main(int argc, char** argv) {
  std::vector<int> xs = {0};
  if (xs[0] != 0) {
    unsigned long long count = 1ull << Log2Floor64(5.0);
    printf("\"Then\" branch, i.e. xs[0] != 0, with count == %llu\n", count);
  } else {
    printf("\"Else\" branch, i.e. xs[0] == 0\n");

wschudy at ubuntu:~$ clang --version
Ubuntu clang version 3.5-1ubuntu1 (trunk) (based on LLVM 3.5)
Target: x86_64-pc-linux-gnu
Thread model: posix
wschudy at ubuntu:~$ clang test.cc -std=c++11 -lstdc++
wschudy at ubuntu:~$ ./a.out
"Else" branch, i.e. xs[0] == 0
wschudy at ubuntu:~$ scan-build clang test.cc -std=c++11 -lstdc++
scan-build: Using '/usr/bin/clang' for static analysis
test.cc:11:37: warning: The result of the '<<' expression is undefined
    unsigned long long count = 1ull << Log2Floor64(5.0);
1 warning generated.
scan-build: 1 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2014-09-10-214330-4211-1' to examine
bug reports.

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/20140911/0ca1101c/attachment.html>

More information about the llvm-bugs mailing list