From: Konstantin Zhuravlyov Date: Tue, 7 Mar 2017 20:09:46 +0000 (+0000) Subject: Fix C2712 build error on Windows X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0578f3744f325fc71b24192ff5c117c871eb0418;p=llvm Fix C2712 build error on Windows Move the __try/__except block outside of the set_thread_name function to avoid a conflict with object unwinding due to the use of the llvm::Storage. Differential Revision: https://reviews.llvm.org/D30707 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297192 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/Windows/Threading.inc b/lib/Support/Windows/Threading.inc index 93b2dfe0945..decb48887af 100644 --- a/lib/Support/Windows/Threading.inc +++ b/lib/Support/Windows/Threading.inc @@ -61,11 +61,8 @@ uint64_t llvm::get_threadid() { uint32_t llvm::get_max_thread_name_length() { return 0; } -void llvm::set_thread_name(const Twine &Name) { #if defined(_MSC_VER) - // Make sure the input is null terminated. - SmallString<64> Storage; - StringRef NameStr = Name.toNullTerminatedStringRef(Storage); +static void SetThreadName(DWORD Id, LPCSTR Name) { constexpr DWORD MS_VC_EXCEPTION = 0x406D1388; #pragma pack(push, 8) @@ -79,8 +76,8 @@ void llvm::set_thread_name(const Twine &Name) { THREADNAME_INFO info; info.dwType = 0x1000; - info.szName = NameStr.data(); - info.dwThreadId = ::GetCurrentThreadId(); + info.szName = Name; + info.dwThreadId = Id; info.dwFlags = 0; __try { @@ -89,6 +86,15 @@ void llvm::set_thread_name(const Twine &Name) { } __except (EXCEPTION_EXECUTE_HANDLER) { } +} +#endif + +void llvm::set_thread_name(const Twine &Name) { +#if defined(_MSC_VER) + // Make sure the input is null terminated. + SmallString<64> Storage; + StringRef NameStr = Name.toNullTerminatedStringRef(Storage); + SetThreadName(::GetCurrentThreadId(), NameStr.data()); #endif }