<div dir="ltr">Recently, I checked out llvm tools from following link.<div><br></div><div><a href="http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary">http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary</a><br></div><div><br></div><div>I followed the instructions and build the tools required for clang-tidy.</div><div><br></div><div>At my workplace, we are modernizing our module's source code to C++11 standard and we aggressively using clang-tidy (built from the trunk as mentioned above) for this purpose.<br><div><br></div><div>One of the use cases where we are stuck is a weird warning for mutex locks.</div><div><br></div><div>Here is a smaller reproducible version of our use case</div><div><br></div><div><div>#include <boost/thread.hpp></div><div><br></div><div>void foo2()</div><div>{</div><div>    boost::mutex crapmutex;</div><div>    boost::mutex::scoped_lock lock(crapmutex);</div><div>}</div><div><br></div><div>int main() {    </div><div>    foo2();    </div><div>    return 0;</div><div>}</div></div><div><br></div><div>When we run clang-tidy with all checks enabled, specify our internal compilation options followed by standard compiler flags, we get following warnings for mutex locks</div><div><br></div><div><div>33110 warnings generated.</div><div>..../boost/include/boost/thread/pthread/mutex.hpp:149:23: warning: This lock has already been acquired [clang-analyzer-alpha.unix.PthreadLock]</div><div>            int res = posix::pthread_mutex_lock(&m);</div><div>                      ^</div><div>..../Source.cpp:13:5: note: Calling 'foo2'</div><div>    foo2();</div><div>    ^</div><div>...../Source.cpp:8:31: note: Calling constructor for 'unique_lock'</div><div>    boost::mutex::scoped_lock lock(crapmutex);</div><div>                              ^</div><div>..../boost/include/boost/thread/lock_types.hpp:157:7: note: Calling 'unique_lock::lock'</div><div>      lock();</div><div>      ^</div><div>..../boost/include/boost/thread/lock_types.hpp:369:7: note: Taking false branch</div><div>      if (m == 0)</div><div>      ^</div><div>..../boost/include/boost/thread/lock_types.hpp:374:7: note: Taking false branch</div><div>      if (owns_lock())</div><div>      ^</div><div>..../boost/include/boost/thread/lock_types.hpp:379:7: note: Calling 'mutex::lock'</div><div>      m->lock();</div><div>      ^</div><div>..../boost/include/boost/thread/pthread/mutex.hpp:149:23: note: This lock has already been acquired</div><div>            int res = posix::pthread_mutex_lock(&m);</div><div>                      ^</div><div>Suppressed 33109 warnings (33109 in non-user code).</div><div>Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.</div></div><div><div><div><br></div><div>Why is this warning coming up? These two locks are totally not related. Is this a bug? If not then why is this warning coming up?</div><div class="gmail_signature"><br>Please let me know if any more details are required.<br><br>Thanks,</div><div class="gmail_signature">Recker</div>
</div></div></div></div>