From 052d5889f871f792def285c92bd91182d07789cd Mon Sep 17 00:00:00 2001 From: Christian Ulmann Date: Fri, 6 Jun 2025 11:24:46 +0200 Subject: [PATCH] [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. --- 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 742660d5bea7..562971aae32f 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