[llvm] 052d588 - [Support] Properly zero initialize CPU set when querying affinity (#142924)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 6 02:24:50 PDT 2025
Author: Christian Ulmann
Date: 2025-06-06T11:24:46+02:00
New Revision: 052d5889f871f792def285c92bd91182d07789cd
URL: https://github.com/llvm/llvm-project/commit/052d5889f871f792def285c92bd91182d07789cd
DIFF: https://github.com/llvm/llvm-project/commit/052d5889f871f792def285c92bd91182d07789cd.diff
LOG: [Support] Properly zero initialize CPU set when querying affinity (#142924)
This commit resolves a potential issue of working with uninitialized
memory when querying the CPU's affinity. The man page of
`sched_getaffinity` does not guarantee that the memory will be fully
overwritten, so this change should ensure that issues are avoided.
Added:
Modified:
llvm/lib/Support/Unix/Threading.inc
Removed:
################################################################################
diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc
index 742660d5bea75..562971aae32fd 100644
--- a/llvm/lib/Support/Unix/Threading.inc
+++ b/llvm/lib/Support/Unix/Threading.inc
@@ -318,6 +318,7 @@ static int computeHostNumHardwareThreads() {
return CPU_COUNT(&mask);
#elif defined(__linux__)
cpu_set_t Set;
+ CPU_ZERO(&Set);
if (sched_getaffinity(0, sizeof(Set), &Set) == 0)
return CPU_COUNT(&Set);
#endif
More information about the llvm-commits
mailing list