From e5bb80443009c92b8a9dd61e92dcb43a04044f61 Mon Sep 17 00:00:00 2001 From: Christian Ulmann Date: Thu, 5 Jun 2025 08:19:32 +0000 Subject: [PATCH] [Support] Properly zero initialize CPU set when querying affinity 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. --- llvm/lib/Support/Unix/Threading.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/llvm/lib/Support/Unix/Threading.inc b/llvm/lib/Support/Unix/Threading.inc index 15a5b008604c3..a553230de054c 100644 --- a/llvm/lib/Support/Unix/Threading.inc +++ b/llvm/lib/Support/Unix/Threading.inc @@ -316,6 +316,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