<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I have managed to reproduce this and I have a workaround (although it is not ideal). I’ll be sending patches out for review shortly. The root cause of the problem is a bug in Microsoft’s implementation of std::call_once. I found a public bug report tracking the issue here:<div class=""><br class=""></div><div class=""><a href="http://connect.microsoft.com/VisualStudio/feedbackdetail/view/811192/std-call-once-hangs" class="">http://connect.microsoft.com/VisualStudio/feedbackdetail/view/811192/std-call-once-hangs</a></div><div class=""><br class=""></div><div class="">The core issue of the bug is that std::call_once can’t be called from a static initializer. Unfortunately the bug report doesn’t say when or where they fixed it, but I expect it was fixed in a newer version of the C++ runtime. The problem then becomes that I don’t believe LLVM has a precedent for requiring specific versions of the C++ redistributable package (which I think is where the fix would be).</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">-Chris</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Oct 17, 2014, at 1:07 PM, Chris Bieneman <<a href="mailto:cbieneman@apple.com" class="">cbieneman@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">I’ve been having trouble reproducing this. Admittedly this is probably mostly due to my total lack of familiarity with Windows development. Any help tracking this down is greatly appreciated.<br class=""><br class="">Thanks,<br class="">-Chris<br class=""><br class=""><blockquote type="cite" class="">On Oct 14, 2014, at 9:30 AM, Aaron Ballman <<a href="mailto:aaron@aaronballman.com" class="">aaron@aaronballman.com</a>> wrote:<br class=""><br class="">On Tue, Oct 14, 2014 at 12:28 PM, Chris Bieneman <<a href="mailto:beanz@apple.com" class="">beanz@apple.com</a>> wrote:<br class=""><blockquote type="cite" class="">Thank you. I will also see if I can reproduce the hang.<br class=""></blockquote><br class="">As a data point, I am able to reproduce the hang on Windows 7 with an<br class="">x86, MSVC-built clang by running the test suite. It is somewhere in<br class="">the arcmt-test and c-index-test suites, judging by how many tests<br class="">hung.<br class=""><br class="">~Aaron<br class=""><br class=""><blockquote type="cite" class=""><br class="">-Chris<br class=""><br class=""><blockquote type="cite" class="">On Oct 14, 2014, at 9:11 AM, NAKAMURA Takumi <<a href="mailto:geek4civic@gmail.com" class="">geek4civic@gmail.com</a>> wrote:<br class=""><br class="">Excuse me, I have reverted it in r219687.<br class=""><br class="">It caused hangup in msc builder, probably deadlock in clang's<br class="">arcmt-test and c-index-test.<br class=""><a href="http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/10976" class="">http://bb.pgr.jp/builders/ninja-clang-i686-msc17-R/builds/10976</a><br class=""><br class="">I will investigate tomorrow.<br class=""><br class="">2014-10-14 7:37 GMT+09:00 Chris Bieneman <beanz@apple.com>:<br class=""><blockquote type="cite" class="">Author: cbieneman<br class="">Date: Mon Oct 13 17:37:25 2014<br class="">New Revision: 219638<br class=""><br class="">URL: http://llvm.org/viewvc/llvm-project?rev=219638&view=rev<br class="">Log:<br class="">Removing the static destructor from ManagedStatic.cpp by controlling the allocation and de-allocation of the mutex.<br class=""><br class="">This patch adds a new llvm_call_once function which is used by the ManagedStatic implementation to safely initialize a global to avoid static construction and destruction.<br class=""><br class="">Modified:<br class="">  llvm/trunk/include/llvm/Support/Threading.h<br class="">  llvm/trunk/lib/Support/ManagedStatic.cpp<br class=""><br class="">Modified: llvm/trunk/include/llvm/Support/Threading.h<br class="">URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=219638&r1=219637&r2=219638&view=diff<br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/Support/Threading.h (original)<br class="">+++ llvm/trunk/include/llvm/Support/Threading.h Mon Oct 13 17:37:25 2014<br class="">@@ -15,6 +15,10 @@<br class="">#ifndef LLVM_SUPPORT_THREADING_H<br class="">#define LLVM_SUPPORT_THREADING_H<br class=""><br class="">+#if !defined(__MINGW__)<br class="">+#include <mutex><br class="">+#endif<br class="">+<br class="">namespace llvm {<br class=""> /// Returns true if LLVM is compiled with support for multi-threading, and<br class=""> /// false otherwise.<br class="">@@ -33,6 +37,20 @@ namespace llvm {<br class=""> /// the thread stack.<br class=""> void llvm_execute_on_thread(void (*UserFn)(void*), void *UserData,<br class="">                             unsigned RequestedStackSize = 0);<br class="">+<br class="">+template <void (*UserFn)(void)> void llvm_call_once() {<br class="">+<br class="">+#if !defined(__MINGW__)<br class="">+  static std::once_flag flag;<br class="">+  std::call_once(flag, UserFn);<br class="">+<br class="">+#else<br class="">+  struct InitOnceWrapper {<br class="">+    InitOnceWrapper() { UserFn(); }<br class="">+  };<br class="">+  static InitOnceWrapper InitOnceVar;<br class="">+#endif<br class="">+}<br class="">}<br class=""><br class="">#endif<br class=""><br class="">Modified: llvm/trunk/lib/Support/ManagedStatic.cpp<br class="">URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ManagedStatic.cpp?rev=219638&r1=219637&r2=219638&view=diff<br class="">==============================================================================<br class="">--- llvm/trunk/lib/Support/ManagedStatic.cpp (original)<br class="">+++ llvm/trunk/lib/Support/ManagedStatic.cpp Mon Oct 13 17:37:25 2014<br class="">@@ -16,16 +16,22 @@<br class="">#include "llvm/Support/Atomic.h"<br class="">#include "llvm/Support/Mutex.h"<br class="">#include "llvm/Support/MutexGuard.h"<br class="">+#include "llvm/Support/Threading.h"<br class="">#include <cassert><br class="">using namespace llvm;<br class=""><br class="">static const ManagedStaticBase *StaticList = nullptr;<br class="">+static sys::Mutex *ManagedStaticMutex = nullptr;<br class=""><br class="">-static sys::Mutex& getManagedStaticMutex() {<br class="">+static void initializeMutex() {<br class="">+  ManagedStaticMutex = new sys::Mutex();<br class="">+}<br class="">+<br class="">+static sys::Mutex* getManagedStaticMutex() {<br class=""> // We need to use a function local static here, since this can get called<br class=""> // during a static constructor and we need to guarantee that it's initialized<br class=""> // correctly.<br class="">-  static sys::Mutex ManagedStaticMutex;<br class="">+  llvm_call_once<initializeMutex>();<br class=""> return ManagedStaticMutex;<br class="">}<br class=""><br class="">@@ -33,7 +39,7 @@ void ManagedStaticBase::RegisterManagedS<br class="">                                             void (*Deleter)(void*)) const {<br class=""> assert(Creator);<br class=""> if (llvm_is_multithreaded()) {<br class="">-    MutexGuard Lock(getManagedStaticMutex());<br class="">+    MutexGuard Lock(*getManagedStaticMutex());<br class=""><br class="">   if (!Ptr) {<br class="">     void* tmp = Creator();<br class="">@@ -83,8 +89,13 @@ void ManagedStaticBase::destroy() const<br class=""><br class="">/// llvm_shutdown - Deallocate and destroy all ManagedStatic variables.<br class="">void llvm::llvm_shutdown() {<br class="">-  MutexGuard Lock(getManagedStaticMutex());<br class="">+  {<br class="">+    MutexGuard Lock(*getManagedStaticMutex());<br class="">+<br class="">+    while (StaticList)<br class="">+      StaticList->destroy();<br class="">+  }<br class=""><br class="">-  while (StaticList)<br class="">-    StaticList->destroy();<br class="">+  delete ManagedStaticMutex;<br class="">+  ManagedStaticMutex = nullptr;<br class="">}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class="">llvm-commits@cs.uiuc.edu<br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></blockquote></blockquote><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></blockquote></blockquote><br class=""></div></blockquote></div><br class=""></div></body></html>