[Openmp-commits] [openmp] 0820319 - [OpenMP] Fix potential division by 0

Nawrin Sultana via Openmp-commits openmp-commits at lists.llvm.org
Fri Nov 6 09:59:40 PST 2020


Author: Nawrin Sultana
Date: 2020-11-06T11:52:19-06:00
New Revision: 082031949cceceb2a26a9e10ce8890196db43338

URL: https://github.com/llvm/llvm-project/commit/082031949cceceb2a26a9e10ce8890196db43338
DIFF: https://github.com/llvm/llvm-project/commit/082031949cceceb2a26a9e10ce8890196db43338.diff

LOG: [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

Added: 
    

Modified: 
    openmp/runtime/src/kmp_affinity.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_affinity.cpp b/openmp/runtime/src/kmp_affinity.cpp
index f78288710349..10ba3e5125dc 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");


        


More information about the Openmp-commits mailing list