[PATCH] D30707: Fix C2712 build error on Windows

Konstantin Zhuravlyov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 11:11:23 PST 2017


kzhuravl created this revision.
Herald added a subscriber: wdng.

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.


https://reviews.llvm.org/D30707

Files:
  lib/Support/Windows/Threading.inc


Index: lib/Support/Windows/Threading.inc
===================================================================
--- lib/Support/Windows/Threading.inc
+++ lib/Support/Windows/Threading.inc
@@ -61,11 +61,8 @@
 
 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,16 +76,25 @@
 
   THREADNAME_INFO info;
   info.dwType = 0x1000;
-  info.szName = NameStr.data();
-  info.dwThreadId = ::GetCurrentThreadId();
+  info.szName = Name;
+  info.dwThreadId = Id;
   info.dwFlags = 0;
 
   __try {
     ::RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR),
       (ULONG_PTR *)&info);
   }
   __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
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30707.90892.patch
Type: text/x-patch
Size: 1285 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170307/7f6f3540/attachment-0001.bin>


More information about the llvm-commits mailing list