<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 positive null pointer analysis due to not inlined list operator == and !="
   href="https://bugs.llvm.org/show_bug.cgi?id=38199">38199</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>false positive null pointer analysis due to not inlined list operator == and !=
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>trunk
          </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>dcoughlin@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>chh@google.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>To reproduce:

$ cat /tmp/null.cpp
#include <list>
typedef std::list<int*> MyList;
extern MyList &mylist;
struct A {
  A();
  void f0();
};
extern void f1(), f2();
void foo()
{
  A *p = nullptr;
  MyList::iterator begin = mylist.begin();
  MyList::iterator end = mylist.end();
  if (begin != end) {
    f1();
    p = new A();
  }
  if (!(begin != end)) {
    f2();
    if (p != nullptr) delete p;
    p = new A();
  }
  p->f0();
  delete p;
}


$ clang-tidy -checks=-*,clang-analy* /tmp/null.cpp -- -std=c++11 -O2
/tmp/null.cpp:23:3: warning: Called C++ object pointer is null
[clang-analyzer-core.CallAndMessage]
  p->f0();
  ^
/tmp/null.cpp:11:3: note: 'p' initialized to a null pointer value
  A *p = nullptr;
  ^
/tmp/null.cpp:14:7: note: Assuming the condition is false
  if (begin != end) {
      ^
/tmp/null.cpp:14:3: note: Taking false branch
  if (begin != end) {
  ^
/tmp/null.cpp:18:7: note: Assuming the condition is false
  if (!(begin != end)) {
      ^
/tmp/null.cpp:18:3: note: Taking false branch
  if (!(begin != end)) {
  ^
/tmp/null.cpp:23:3: note: Called C++ object pointer is null
  p->f0();
  ^



If compiled with clang -O2, we can see that all calls to the list and iterator
functions can be inlined and it is impossible to have both !(begin != end) and
!!(begin != end)

The clang static analyzer does not seem be inlining the != and == operators of
the list::iterator.</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>