[PATCH] D58117: Workaround std::thread begin not copy-constructible

serge via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 12 06:40:47 PST 2019


serge-sans-paille created this revision.
serge-sans-paille added a reviewer: george.karpenkov.
Herald added subscribers: Sanitizers, llvm-commits, jfb.
Herald added projects: LLVM, Sanitizers.

It's not possible to `push_back` in a vector of `std::thread` because `std::thread`  is not copy-constructible. And moving to `emplace_back` triggers a method lookup error related to the custom allocator, as showcased in https://godbolt.org/z/jsbEKC.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D58117

Files:
  lib/fuzzer/FuzzerDefs.h
  lib/fuzzer/FuzzerDriver.cpp


Index: lib/fuzzer/FuzzerDriver.cpp
===================================================================
--- lib/fuzzer/FuzzerDriver.cpp
+++ lib/fuzzer/FuzzerDriver.cpp
@@ -257,7 +257,7 @@
   std::thread Pulse(PulseThread);
   Pulse.detach();
   for (unsigned i = 0; i < NumWorkers; i++)
-    V.push_back(std::thread(WorkerThread, std::ref(Cmd), &Counter, NumJobs, &HasErrors));
+    V.emplace_back(WorkerThread, std::ref(Cmd), &Counter, NumJobs, &HasErrors);
   for (auto &T : V)
     T.join();
   return HasErrors ? 1 : 0;
Index: lib/fuzzer/FuzzerDefs.h
===================================================================
--- lib/fuzzer/FuzzerDefs.h
+++ lib/fuzzer/FuzzerDefs.h
@@ -183,6 +183,12 @@
 
       template<class Other>
       struct rebind { typedef fuzzer_allocator<Other> other;  };
+
+      template< class U, class... Args >
+      void construct( U* p, Args&&... args ) {
+        std::allocator<T>::construct(p, std::forward<Args>(args)...);
+      }
+
   };
 
 template<typename T>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58117.186451.patch
Type: text/x-patch
Size: 1000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190212/f6e5ab65/attachment.bin>


More information about the llvm-commits mailing list