Skip to content

Clang static analyzer false positive suppression does not suppress an issue report #123227

@SergeySatskiy

Description

@SergeySatskiy

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions