This is an archive of the discontinued LLVM Phabricator instance.

Annotate scoped_lock as with scoped_lockable attribute
ClosedPublic

Authored by aaronpuchert on Oct 9 2018, 3:35 PM.

Details

Summary

Scoped capabilities need to be annotated as such, otherwise the thread
safety analysis won't work as intended.

Fixes PR39234.

Event Timeline

aaronpuchert created this revision.Oct 9 2018, 3:35 PM
ldionne accepted this revision.Oct 9 2018, 4:21 PM
ldionne added inline comments.
test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp
28

What is the purpose of this added function?

This revision is now accepted and ready to land.Oct 9 2018, 4:21 PM

Thanks a lot for taking a look so quickly!

test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp
28

Nevermind, I just read the comment on PR39234 and understood.

This revision was automatically updated to reflect the committed changes.
NoQ added a subscriber: NoQ.Oct 10 2018, 11:40 AM

Hmm, this seems to be causing buildbot failures, could you take a look?

Eg., http://lab.llvm.org:8080/green/job/libcxx_master_cmake/5459/consoleFull

/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp:28:8: error: no member named 'scoped_lock' in namespace 'std'
  std::scoped_lock<std::mutex> lock(m);
  ~~~~~^
/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp:28:30: error: expected '(' for function-style cast or type construction
  std::scoped_lock<std::mutex> lock(m);
                   ~~~~~~~~~~^
/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/test/libcxx/thread/thread.mutex/thread_safety_lock_guard.pass.cpp:28:32: error: no matching function for call to 'lock'
  std::scoped_lock<std::mutex> lock(m);
                               ^~~~
/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/include/mutex:372:1: note: candidate function template not viable: requires 2 arguments, but 1 was provided
lock(_L0& __l0, _L1& __l1)
^
/Users/buildslave/jenkins/sharedspace/libcxx/libcxx.src/include/mutex:446:1: note: candidate function template not viable: requires at least 3 arguments, but 1 was provided
lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
^
3 errors generated.
--

Compilation failed unexpectedly!
In D53049#1260836, @NoQ wrote:

Hmm, this seems to be causing buildbot failures, could you take a look?

Hmm, std::scoped_lock is only available with C++17. I'll put an #ifdef around it if you don't mind.

In D53049#1260836, @NoQ wrote:

Hmm, this seems to be causing buildbot failures, could you take a look?

Hmm, std::scoped_lock is only available with C++17. I'll put an #ifdef around it if you don't mind.

#if TEST_STD_VER >= 17 is what you're looking for. And don't forget to `#include "test_macros.h".

#if TEST_STD_VER >= 17 is what you're looking for. And don't forget to `#include "test_macros.h".

Oh, I was a bit to quick and used __cplusplus. Should I change it?

#if TEST_STD_VER >= 17 is what you're looking for. And don't forget to `#include "test_macros.h".

Oh, I was a bit to quick and used __cplusplus. Should I change it?

Ok, I cleaned this up a bit in rCXX344194. I hope you don't mind, the change is rather small.