[Openmp-commits] [PATCH] D98209: [OpenMP] Fix incorrect KMP_STRLEN() macro on Windows

Jonathan Peyton via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Mon Apr 5 07:03:56 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2aebb7cb3c88: [OpenMP] Fix incorrect KMP_STRLEN() macro (authored by jlpeyton).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98209/new/

https://reviews.llvm.org/D98209

Files:
  openmp/runtime/src/kmp_os.h
  openmp/runtime/src/kmp_safe_c_api.h


Index: openmp/runtime/src/kmp_safe_c_api.h
===================================================================
--- openmp/runtime/src/kmp_safe_c_api.h
+++ openmp/runtime/src/kmp_safe_c_api.h
@@ -10,6 +10,7 @@
 #ifndef KMP_SAFE_C_API_H
 #define KMP_SAFE_C_API_H
 
+#include <type_traits>
 #include "kmp_platform.h"
 #include <string.h>
 
@@ -33,7 +34,15 @@
 // Use this only when buffer size is unknown
 #define KMP_MEMCPY(dst, src, cnt) memcpy_s(dst, cnt, src, cnt)
 
-#define KMP_STRLEN(str) strnlen_s(str, RSIZE_MAX_STR)
+template <typename T, bool B = std::is_array<T>::value>
+struct kmp_get_rmax_t {};
+template <typename T> struct kmp_get_rmax_t<T, false> {
+  static const size_t value = RSIZE_MAX_STR;
+};
+template <typename T> struct kmp_get_rmax_t<T, true> {
+  static const size_t value = sizeof(T);
+};
+#define KMP_STRLEN(str) strnlen_s(str, kmp_get_rmax_t<decltype(str)>::value)
 
 // Use this only when buffer size is unknown
 #define KMP_STRNCPY(dst, src, cnt) strncpy_s(dst, cnt, src, cnt)
Index: openmp/runtime/src/kmp_os.h
===================================================================
--- openmp/runtime/src/kmp_os.h
+++ openmp/runtime/src/kmp_os.h
@@ -1040,6 +1040,9 @@
 } // extern "C"
 #endif // __cplusplus
 
+// Safe C API
+#include "kmp_safe_c_api.h"
+
 // Macros for C++11 atomic functions
 #define KMP_ATOMIC_LD(p, order) (p)->load(std::memory_order_##order)
 #define KMP_ATOMIC_OP(op, p, v, order) (p)->op(v, std::memory_order_##order)
@@ -1090,5 +1093,3 @@
 #endif
 
 #endif /* KMP_OS_H */
-// Safe C API
-#include "kmp_safe_c_api.h"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98209.335247.patch
Type: text/x-patch
Size: 1570 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210405/d230af7c/attachment.bin>


More information about the Openmp-commits mailing list