Fix a threading bug.

llvm-svn: 305718
This commit is contained in:
Rui Ueyama
2017-06-19 17:47:04 +00:00
parent df2b283bf9
commit 02e5d2a6cb

View File

@@ -8,6 +8,7 @@
//===----------------------------------------------------------------------===//
#include "Strings.h"
#include <mutex>
#if defined(_MSC_VER)
#include <Windows.h>
@@ -21,6 +22,10 @@ using namespace llvm;
Optional<std::string> coff::demangle(StringRef S) {
#if defined(_MSC_VER)
// UnDecorateSymbolName is not thread-safe, so we need a mutex.
static std::mutex Mu;
std::lock_guard<std::mutex> Lock(mu);
char Buf[4096];
if (S.startswith("?"))
if (size_t Len = UnDecorateSymbolName(S.str().c_str(), Buf, sizeof(Buf), 0))