Following on from https://reviews.llvm.org/rG8ddcd1dc26bad9d97bbf34cf4fc91dbf3c153431.
As pointed out here: https://reviews.llvm.org/D71059 this does not build on some systems with LLVM_ENABLE_THREADS=OFF.
Differential D71548
Fix time trace multi threaded support with LLVM_ENABLE_THREADS=OFF russell.gallop on Dec 16 2019, 6:56 AM. Authored by
Details Following on from https://reviews.llvm.org/rG8ddcd1dc26bad9d97bbf34cf4fc91dbf3c153431. As pointed out here: https://reviews.llvm.org/D71059 this does not build on some systems with LLVM_ENABLE_THREADS=OFF.
Diff Detail Event TimelineThis comment was removed by Kai. Comment Actions This broke a whole lot of bots like http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/28924 or http://lab.llvm.org:8011/builders/clang-atom-d525-fedora-rel/builds/30851: [2/3225] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TimeProfiler.cpp.o FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/TimeProfiler.cpp.o /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/Support -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/llvm/lib/Support -Iinclude -I/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -UNDEBUG -std=c++14 -fno-exceptions -fno-rtti -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/TimeProfiler.cpp.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/TimeProfiler.cpp.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/TimeProfiler.cpp.o -c /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/llvm/lib/Support/TimeProfiler.cpp /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/llvm/lib/Support/TimeProfiler.cpp:36:54: error: non-local variable 'llvm::TimeTraceProfilerInstance' declared '__thread' has a non-trivial destructor LLVM_THREAD_LOCAL std::unique_ptr<TimeTraceProfiler> TimeTraceProfilerInstance; ^~~~~~~~~~~~~~~~~~~~~~~~~ /home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/llvm/lib/Support/TimeProfiler.cpp:36:54: note: C++11 'thread_local' allows dynamic initialization and destruction Comment Actions I don't think LLVM_THREAD_LOCAL is correct here. unique_ptr isn't a POD so this doesn't really fit to the use case of` LLVM_THREAD_LOCAL`. Maybe we should have a LLVM_NONTRIVIAL_THREAD_LOCAL. that doesn't fall back to __thread. Or we just use raw pointer here instead of a global unique_ptr (it seems that we anyway use it here just as an annotation to describe memory ownership?). Comment Actions I'd prefer a "thread_local if threads enabled" as the unique_ptr helps enforce ownership when https://reviews.llvm.org/D71060 lands. Interestingly, thread_local was okay on all public bots, the only problem was with LLVM_ENABLE_THREADS=OFF so maybe LLVM_THREAD_LOCAL could be simplified to "thread_local if threads enabled" now (removing declspec(thread) and thread). I don't know enough about how that is used to know whether that would be okay. Comment Actions Ping! Okay to land this? (I moved it back to needs review as this was very different from before).
|
This patch still doesn't unbreak the build on Mac OSX:
Personally, I'd like to see the original patch reverted until you can find a way to do it without thread_local. ...And it seems like you do have a way? If the code works without using thread_local at all, then what's the logic behind adding thread_local to it conditionally? Given that the version without thread_local works fine, can we just use that version on all platforms?