<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 - Static analyzer ignores calls through function pointers"
href="https://bugs.llvm.org/show_bug.cgi?id=50771">50771</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Static analyzer ignores calls through function pointers
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>aaronpuchert@alice-dsl.net
</td>
</tr>
<tr>
<th>CC</th>
<td>dcoughlin@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>We observed this with Google Test, which stores a pointer to a function
destroying a object in a data structure, and then releases data by calling
through that pointer. A reduced test case is this:
void MatcherBase() {
void* shared = new int();
void (*shared_destroy)(void*) = [](void* p) { delete static_cast<int*>(p); };
shared_destroy(shared);
} // warning: Potential leak of memory pointed to by 'shared'
[cplusplus.NewDeleteLeaks]
The warning disappears when changing the type of shared_destroy to auto, so
we're not converting to a function pointer type but rather keeping an object of
lambda type. Then the call at the end is a direct call and inlined. Similarly
for a global function shared_destroy.
Now I guess that tracing calls through function pointers would be pretty hard,
because then control flow would depend on data flow in a way that's not
amenable to a constrain solver. But we could at least treat the function
pointer call like an opaque call, which also makes the warning disappear:
void shared_destroy(void* p);
void MatcherBase() {
void* shared = new int();
shared_destroy(shared);
} // no warning.</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>