[libcxx-commits] [PATCH] D94656: [libcxx testing] Fix UB in tests for std::lock_guard

Igor Kudrin via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jan 14 08:04:46 PST 2021


ikudrin updated this revision to Diff 316665.
ikudrin marked an inline comment as done.
ikudrin added a comment.

- Updated as suggested. Thanks, @ldionne!


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D94656/new/

https://reviews.llvm.org/D94656

Files:
  libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
  libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp


Index: libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
+++ libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/mutex.pass.cpp
@@ -21,14 +21,20 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
 
+void do_try_lock() {
+  assert(m.try_lock() == false);
+}
+
 int main(int, char**) {
   {
     std::lock_guard<std::mutex> lg(m);
-    assert(m.try_lock() == false);
+    std::thread t = support::make_test_thread(do_try_lock);
+    t.join();
   }
 
   m.lock();
Index: libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
===================================================================
--- libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
+++ libcxx/test/std/thread/thread.mutex/thread.lock/thread.lock.guard/adopt_lock.pass.cpp
@@ -18,15 +18,21 @@
 #include <cstdlib>
 #include <cassert>
 
+#include "make_test_thread.h"
 #include "test_macros.h"
 
 std::mutex m;
 
+void do_try_lock() {
+  assert(m.try_lock() == false);
+}
+
 int main(int, char**) {
   {
     m.lock();
     std::lock_guard<std::mutex> lg(m, std::adopt_lock);
-    assert(m.try_lock() == false);
+    std::thread t = support::make_test_thread(do_try_lock);
+    t.join();
   }
 
   m.lock();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94656.316665.patch
Type: text/x-patch
Size: 1501 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210114/4fd99041/attachment.bin>


More information about the libcxx-commits mailing list