<html>
    <head>
      <base href="https://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 --- - unix.Malloc and cplusplus.NewDeleteLeaks doesn't report leaks in functions declared in header files."
   href="https://llvm.org/bugs/show_bug.cgi?id=23425">23425</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>unix.Malloc and cplusplus.NewDeleteLeaks doesn't report leaks in functions declared in header files.
          </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>Windows XP
          </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>anton.yartsev@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>Symptoms: the analyzer doesn't report a leak in a given case:
<span class="quote">>cat header.h</span >
void f();

<span class="quote">>cat test.cpp</span >
#include "header.h"

void f() {
  int *p = new int;
}

<span class="quote">>clang -cc1 -analyzer-checker=cplusplus.NewDeleteLeaks test.cpp</span >

Adding an option '-analyzer-opt-analyze-headers' makes analyzer report a
warning:
<span class="quote">>clang -cc1 -analyzer-checker=cplusplus.NewDeleteLeaks -analyzer-opt-analyze-headers -analyze test.cpp</span >
test.cpp:5:1: warning: Potential leak of memory pointed to by 'p'
}
^
1 warning generated.

Clang help for -analyzer-opt-analyze-headers says that an option 'Force the
static analyzer to analyze functions defined in header files', but in the test
above the function is defined in the cpp file.
The deadcode.DeadStores checker reports an error regardless of whether
-analyzer-opt-analyze-headers was passed or not:
<span class="quote">>clang -cc1 -analyzer-checker=deadcode.DeadStores -analyze test.cpp</span >
test.cpp:4:8: warning: Value stored to 'p' during its initialization is never
read
  int *p = new int;
       ^   ~~~~~~~
1 warning generated.</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>