[PATCH] D14731: [libcxx] Add clang thread safety annotations to mutex and lock_guard

James Robinson via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 1 17:12:08 PST 2015


jamesr added a comment.

In http://reviews.llvm.org/D14731#299152, @mclow.lists wrote:

> Where are the tests?


There aren't any yet.  I investigated a few avenues for testing but none seem very useful.

The most obvious testing strategy would be to write some code that fails the -Wthread-safety checks such as

  std::mutex m; m.lock(); m.lock();

and verify that this generates the expected warning.  There's a harness for expected warnings that does this in the clang repo but no such harness exists in libcxx.  Depending on the text of warnings from clang in libcxx tests seems like a layering violation, anyway.  Another check would be to test that such code fails to compile with -Wthread-safety -Werror set.  libcxx's test suite does support negative compilation tests but I can't find any way to specify that particular tests should be compiled with particular flags.  I tried enabling -Wthread-safety for all tests, but other tests fail because they do things that the annotations do not understand (deliberately, the annotations are for static checking not dynamic code analysis).  I could add suppressions to all of these tests but that seems backwards.  This also hits the problem that such annotations would only have meaning for new-enough versions of clang and there's no way for the driver to cleanly tell if the cxx being used supports the annotations or not.

The annotations are (by design) not supposed to have an influence on the program other than generating warnings in non-default configs so there isn't any  other testing hook I can think of.


http://reviews.llvm.org/D14731





More information about the cfe-commits mailing list