[llvm] Fix AppVerifier GetThreadId(NULL) error in llvm::thread (PR #216941)
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 20 19:56:58 PDT 2026
================
@@ -49,7 +49,15 @@ void llvm_thread_detach_impl(HANDLE hThread) {
ReportLastErrorFatal("CloseHandle failed");
}
-DWORD llvm_thread_get_id_impl(HANDLE hThread) { return ::GetThreadId(hThread); }
+DWORD llvm_thread_get_id_impl(HANDLE hThread) {
+ // AppVerifier (runtime verification tool from Windows SDK) reports an error
+ // when GetThreadId(NULL) is called. Suppress this by manually checking for
+ // NULL. Return 0 as this is what's returned (by documentation) if
+ // GetThreadId() fails.
+ if (!hThread)
+ return 0;
+ return ::GetThreadId(hThread);
----------------
compnerd wrote:
Why not write this as:
```
if (hThread)
return ::GetThreadId(hThread);
return ::GetThreadId(::GetCurrentThread());
```
That should preserve the semantics desired given the description in the commit message that it is used to get the current thread. The current thread psuedo handle is `(HANDLE)-2`.
https://github.com/llvm/llvm-project/pull/216941
More information about the llvm-commits
mailing list