<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 - Add attribute for asserting that memory is valid"
href="https://bugs.llvm.org/show_bug.cgi?id=34868">34868</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Add attribute for asserting that memory is valid
</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>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>akrzemi1@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>BACKGROUND:
The following page provides a set of hints for disabling false positives
returned from static-analyzer: <a href="http://clang-analyzer.llvm.org/faq.html">http://clang-analyzer.llvm.org/faq.html</a>
Using an `assert` is very elegant; and using `#define`, although not elegant is
a good last resort that makes in possible to disable practically any warning.
Yet, there is a class of false positives that cannot be disabled with an
`assert` and are to specific/focused to qualify for a #define, namely the
problems with memory used after free.
I recently got hit by the following false positive:
<a href="https://github.com/google/googletest/issues/853">https://github.com/google/googletest/issues/853</a>
It had already been described, and a corresponding bug report filed under
<a class="bz_bug_link
bz_status_NEW "
title="NEW - False positive "Use of memory after it is freed" using gmock linked_ptr and std::vector."
href="show_bug.cgi?id=28053">https://bugs.llvm.org/show_bug.cgi?id=28053</a> 15 months ago.
What would help me here is if clang provided an additional attribute, like
`__attribute__((analyzer_memory_valid))`, which I could use to instruct the
analyzer that memory under given address is valid at this point, regardless of
what the analyzer has concluded.
I had a different false positive recently in my job. I cannot make a
self-contained example, because the bug manifested only in big portions of
code, using a number of libraries, and each time I tried to reduce it, the bug
disappeared. But it basically said that the re is a risk memory would not be
freed if some exception was thrown (but the memory in question was guarded by a
std::unique_ptr). What I was missing was another attribute, like
`__attribute__((analyzer_memory_will_be_freed))` wherewith I could overwrite
the conclusion from the static analyzer.
FEATURE REQUEST:
Provide two additional attributes for the static analyzer, where I can add
manual input to the analysis as to when memory is valid, and that it will be
freed:
`__attribute__((analyzer_memory_valid))` -- this means that at this point of
execution the memory under the annotated pointer is valid (in particular: not
freed yet).
`__attribute__((analyzer_memory_will_be_freed))` -- this means that the memory
under the annotated address will be freed, even if the analyzer fails to see
it.</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>