From 082031949cceceb2a26a9e10ce8890196db43338 Mon Sep 17 00:00:00 2001 From: Nawrin Sultana Date: Fri, 6 Nov 2020 10:47:33 -0600 Subject: [PATCH] [OpenMP] Fix potential division by 0 This patch fixes potential division by 0 in case hwloc does not recognize cores (or architecture has no cores). Patch by Andrey Churbanov Differential Revision: https://reviews.llvm.org/D90954 --- openmp/runtime/src/kmp_affinity.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp index f78288710349a..10ba3e5125dc7 100644 --- a/openmp/runtime/src/kmp_affinity.cpp +++ b/openmp/runtime/src/kmp_affinity.cpp @@ -589,6 +589,8 @@ static int __kmp_affinity_create_hwloc_map(AddrUnsPair **address2os, else __kmp_nThreadsPerCore = 1; // no CORE found __kmp_ncores = __kmp_xproc / __kmp_nThreadsPerCore; + if (nCoresPerPkg == 0) + nCoresPerPkg = 1; // to prevent possible division by 0 nPackages = (__kmp_xproc + nCoresPerPkg - 1) / nCoresPerPkg; if (__kmp_affinity_verbose) { KMP_INFORM(AffNotCapableUseLocCpuidL11, "KMP_AFFINITY");