]> granicus.if.org Git - llvm/commitdiff
Fix C2712 build error on Windows
authorKonstantin Zhuravlyov <kzhuravl_dev@outlook.com>
Tue, 7 Mar 2017 20:09:46 +0000 (20:09 +0000)
committerKonstantin Zhuravlyov <kzhuravl_dev@outlook.com>
Tue, 7 Mar 2017 20:09:46 +0000 (20:09 +0000)
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

lib/Support/Windows/Threading.inc

index 93b2dfe09457dd4dd77f486037de069a278bc48a..decb48887af22a7a08f2495c3713766315d4098a 100644 (file)
@@ -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
 }