[Openmp-commits] [PATCH] D13827: Avoid bad conversion for __kmp_sys_max_nth

Dimitry Andric via Openmp-commits openmp-commits at lists.llvm.org
Fri Oct 16 13:14:55 PDT 2015


dim created this revision.
dim added reviewers: jlpeyton, joerg.
dim added a subscriber: openmp-commits.

On FreeBSD, compiling openmp trunk results in the following warning,
because `PTHREADS_THREADS_MAX` is `0xffffffffffffffffU` there:

    runtime/src/kmp_global.c:117:35: warning: implicit conversion from 'unsigned long' to 'int' changes value from 18446744073709551615 to -1 [-Wconstant-conversion]
    int           __kmp_sys_max_nth = KMP_MAX_NTH;
                  ~~~~~~~~~~~~~~~~~   ^~~~~~~~~~~
    runtime/src/kmp.h:849:34: note: expanded from macro 'KMP_MAX_NTH'
    #    define KMP_MAX_NTH          PTHREAD_THREADS_MAX
                                     ^~~~~~~~~~~~~~~~~~~
    /usr/include/pthread.h:55:31: note: expanded from macro 'PTHREAD_THREADS_MAX'
    #define PTHREAD_THREADS_MAX                     __ULONG_MAX
                                                    ^~~~~~~~~~~
    /usr/include/x86/_limits.h:61:21: note: expanded from macro '__ULONG_MAX'
    #define __ULONG_MAX     0xffffffffffffffff      /* max for an unsigned long */
                            ^~~~~~~~~~~~~~~~~~
    1 warning generated.

This patch attempts to avoid it.  The first iteration of this patch used
`PTHREAD_THREADS_MAX < INT_MAX ? PTHREAD_THREADS_MAX : INT_MAX` as the
definition of `KMP_MAX_NTH`, but Joerg noted that it isn't a constant
expression then, and advised this approach.

http://reviews.llvm.org/D13827

Files:
  runtime/src/kmp_global.c
  runtime/src/z_Linux_util.c

Index: runtime/src/z_Linux_util.c
===================================================================
--- runtime/src/z_Linux_util.c
+++ runtime/src/z_Linux_util.c
@@ -2142,7 +2142,7 @@
         }
         else if ( __kmp_sys_max_nth <= 1 ) {
             /* Can't tell, just use PTHREAD_THREADS_MAX */
-            __kmp_sys_max_nth = KMP_MAX_NTH;
+            __kmp_sys_max_nth = KMP_MAX_NTH < INT_MAX ? KMP_MAX_NTH : INT_MAX;
         }
 
         /* Query the minimum stack size */
Index: runtime/src/kmp_global.c
===================================================================
--- runtime/src/kmp_global.c
+++ runtime/src/kmp_global.c
@@ -114,7 +114,11 @@
 int                 __kmp_xproc = 0;
 int            __kmp_avail_proc = 0;
 size_t    __kmp_sys_min_stksize = KMP_MIN_STKSIZE;
+#if KMP_MAX_NTH < INT_MAX
 int           __kmp_sys_max_nth = KMP_MAX_NTH;
+#else
+int           __kmp_sys_max_nth = INT_MAX;
+#endif
 int               __kmp_max_nth = 0;
 int      __kmp_threads_capacity = 0;
 int         __kmp_dflt_team_nth = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13827.37631.patch
Type: text/x-patch
Size: 1041 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20151016/c945e6fd/attachment.bin>


More information about the Openmp-commits mailing list