[Openmp-commits] [PATCH] D107348: [OpenMP][NFC] Cleanup: minor fixes to silence static analyzer.

Andrey Churbanov via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Tue Aug 3 06:30:17 PDT 2021


AndreyChurbanov created this revision.
AndreyChurbanov added reviewers: hbae, Nawrin.
AndreyChurbanov added a project: OpenMP.
Herald added subscribers: manas, steakhal, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, a.sidorin, guansong, baloghadamsoftware, yaxunl.
AndreyChurbanov requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added subscribers: openmp-commits, sstefan1.

Added couple more checks to silence KlocWork static code analyzer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107348

Files:
  openmp/runtime/src/kmp_affinity.cpp
  openmp/runtime/src/kmp_alloc.cpp
  openmp/runtime/src/kmp_dispatch.cpp


Index: openmp/runtime/src/kmp_dispatch.cpp
===================================================================
--- openmp/runtime/src/kmp_dispatch.cpp
+++ openmp/runtime/src/kmp_dispatch.cpp
@@ -668,6 +668,8 @@
   case kmp_sch_static_chunked:
   case kmp_sch_dynamic_chunked:
   dynamic_init:
+    if (tc == 0)
+      break;
     if (pr->u.p.parm1 <= 0)
       pr->u.p.parm1 = KMP_DEFAULT_CHUNK;
     else if (pr->u.p.parm1 > tc)
Index: openmp/runtime/src/kmp_alloc.cpp
===================================================================
--- openmp/runtime/src/kmp_alloc.cpp
+++ openmp/runtime/src/kmp_alloc.cpp
@@ -883,7 +883,7 @@
   __kmp_bget_dequeue(th); /* Release any queued buffers */
 
 #ifdef SizeQuant
-  len &= ~(SizeQuant - 1);
+  len &= ~((bufsize)(SizeQuant - 1));
 #endif
   if (thr->pool_len == 0) {
     thr->pool_len = len;
Index: openmp/runtime/src/kmp_affinity.cpp
===================================================================
--- openmp/runtime/src/kmp_affinity.cpp
+++ openmp/runtime/src/kmp_affinity.cpp
@@ -2386,7 +2386,10 @@
         unsigned val;
         if ((p == NULL) || (KMP_SSCANF(p + 1, "%u\n", &val) != 1))
           goto no_val;
-        KMP_ASSERT(nodeIdIndex + level <= maxIndex);
+        // validate the input before using level:
+        if (level > (unsigned)__kmp_xproc) { // level is too big
+          level = __kmp_xproc;
+        }
         if (threadInfo[num_avail][nodeIdIndex + level] != UINT_MAX)
           goto dup_field;
         threadInfo[num_avail][nodeIdIndex + level] = val;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107348.363714.patch
Type: text/x-patch
Size: 1540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210803/b18a82ad/attachment.bin>


More information about the Openmp-commits mailing list