<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - False positives related to __builtin_clzll() and std::vector"
   href="http://llvm.org/bugs/show_bug.cgi?id=20902">20902</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positives related to __builtin_clzll() and std::vector
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>wschudy@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=13017" name="attach_13017" title="scan-build error report demonstrating the bug">attachment 13017</a> <a href="attachment.cgi?id=13017&action=edit" title="scan-build error report demonstrating the bug">[details]</a></span>
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@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@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@ubuntu:~$ clang test.cc -std=c++11 -lstdc++
wschudy@ubuntu:~$ ./a.out
"Else" branch, i.e. xs[0] == 0
wschudy@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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>