[Openmp-commits] [PATCH] D90954: [OpenMP] Fix potential division by 0

Nawrin Sultana via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Fri Nov 6 09:03:21 PST 2020


Nawrin created this revision.
Nawrin added a reviewer: AndreyChurbanov.
Nawrin added a project: OpenMP.
Herald added subscribers: guansong, yaxunl.
Nawrin requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

This patch fixes potential division by 0 in case hwloc does not recognize cores (or architecture has no cores).

Patch by Andrey Churbanov


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D90954

Files:
  openmp/runtime/src/kmp_affinity.cpp


Index: openmp/runtime/src/kmp_affinity.cpp
===================================================================
--- openmp/runtime/src/kmp_affinity.cpp
+++ openmp/runtime/src/kmp_affinity.cpp
@@ -589,6 +589,8 @@
     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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90954.303476.patch
Type: text/x-patch
Size: 584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20201106/dee71d9b/attachment.bin>


More information about the Openmp-commits mailing list