<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123227>123227</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Clang static analyzer false positive suppression does not suppress an issue report
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
SergeySatskiy
</td>
</tr>
</table>
<pre>
We use the clang static analyzer for our C++ code as a part of a workflow. Sometimes there are false positives and I have troubles to suppress them.
Here is an example of the code:
```c++
template<class TDescription>
inline
typename CParam<TDescription>::TValueType
CParam<TDescription>::Get(void) const
{
if ( !m_ValueSet ) {
// The lock prevents multiple initializations with the default value
// in Get(), but does not prevent Set() from modifying the value
// while another thread is reading it.
CMutexGuard guard(s_GetLock());
if ( !m_ValueSet ) {
m_Value = GetThreadDefault();
if (GetState() >= eState_Config) {
// All sources checked or the value is set by user.
m_ValueSet = true;
}
}
}
return m_Value;
}
```
An issue is reported for the
```return m_Value;```
line as follows: "Undefined or garbage value returned to caller".
The developer of the code investigated this case and it seems that the false positive is because the multithreaded nature of the code was not taken into consideration. It is understandable so I tried to suppress the issue reporting. Following the documentation I tried multiple options (adding before the ```return ...``` line):
- ```__attribute__((suppress))```
- ```[[clang::suppress]]```
- ```[[gsl::suppress("lifetime")]]```
- ```[[gsl::suppress("bounds")]]```
And none of this options suppressed the issue reporting.
Do I do something wrong or there is an issue with the clang analyzer so that the suppress attribute is not taken into consideration?
Note: the code is compiled with ```-std=gnu++17``` option. I tried ```-std=c++17``` option as well with the same outcome.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVl-P4jYQ_zTmZbQRcWCBBx5YKNuT2qrSbttH5MSTxF3HjuwJHPfpK9sQ2N3eVSqKCDgzv_n7m4nwXjUGcc3mT2y-m4iBWuvWL-gaPL8I8m_qPCmtPK__Qhg8ArUIlRamAU-CVAXCCH3-hg5q68A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