Commit 9666c522 by Jakub Jelinek Committed by Jakub Jelinek

affinity-fmt.c: Include inttypes.h if HAVE_INTTYPES_H.

	* affinity-fmt.c: Include inttypes.h if HAVE_INTTYPES_H.
	(gomp_display_affinity): Use __builtin_choose_expr to handle
	properly handle argument having integral, or pointer or some other
	type.  If inttypes.h is available and PRIx64 is defined, use PRIx64
	with uint64_t type instead of %llx and unsigned long long.

From-SVN: r265985
parent 213fd717
2018-11-09 Jakub Jelinek <jakub@redhat.com> 2018-11-09 Jakub Jelinek <jakub@redhat.com>
* affinity-fmt.c: Include inttypes.h if HAVE_INTTYPES_H.
(gomp_display_affinity): Use __builtin_choose_expr to handle
properly handle argument having integral, or pointer or some other
type. If inttypes.h is available and PRIx64 is defined, use PRIx64
with uint64_t type instead of %llx and unsigned long long.
* testsuite/libgomp.c-c++-common/task-reduction-13.c: New test. * testsuite/libgomp.c-c++-common/task-reduction-13.c: New test.
* testsuite/libgomp.c-c++-common/task-reduction-14.c: New test. * testsuite/libgomp.c-c++-common/task-reduction-14.c: New test.
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#ifdef HAVE_INTTYPES_H
# include <inttypes.h> /* For PRIx64. */
#endif
#ifdef HAVE_UNAME #ifdef HAVE_UNAME
#include <sys/utsname.h> #include <sys/utsname.h>
#endif #endif
...@@ -356,37 +359,42 @@ gomp_display_affinity (char *buffer, size_t size, ...@@ -356,37 +359,42 @@ gomp_display_affinity (char *buffer, size_t size,
goto do_int; goto do_int;
case 'i': case 'i':
#if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__) #if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__)
/* Handle integral pthread_t. */ {
if (__builtin_classify_type (handle) == 1) char buf[3 * (sizeof (handle) + sizeof (uintptr_t) + sizeof (int))
{ + 4];
char buf[3 * (sizeof (handle) + sizeof (int)) + 4]; /* This macro returns expr unmodified for integral or pointer
types and 0 for anything else (e.g. aggregates). */
if (sizeof (handle) == sizeof (long)) #define gomp_nonaggregate(expr) \
sprintf (buf, "0x%lx", (long) handle); __builtin_choose_expr (__builtin_classify_type (expr) == 1 \
else if (sizeof (handle) == sizeof (long long)) || __builtin_classify_type (expr) == 5, expr, 0)
sprintf (buf, "0x%llx", (long long) handle); /* This macro returns expr unmodified for integral types,
else (uintptr_t) (expr) for pointer types and 0 for anything else
sprintf (buf, "0x%x", (int) handle); (e.g. aggregates). */
gomp_display_num (buffer, size, &ret, zero, right, sz, buf); #define gomp_integral(expr) \
break; __builtin_choose_expr (__builtin_classify_type (expr) == 5, \
} (uintptr_t) gomp_nonaggregate (expr), \
/* And pointer pthread_t. */ gomp_nonaggregate (expr))
else if (__builtin_classify_type (handle) == 5)
{
char buf[3 * (sizeof (uintptr_t) + sizeof (int)) + 4];
if (sizeof (uintptr_t) == sizeof (long)) if (sizeof (gomp_integral (handle)) == sizeof (unsigned long))
sprintf (buf, "0x%lx", (long) (uintptr_t) handle); sprintf (buf, "0x%lx", (unsigned long) gomp_integral (handle));
else if (sizeof (uintptr_t) == sizeof (long long)) #if defined (HAVE_INTTYPES_H) && defined (PRIx64)
sprintf (buf, "0x%llx", (long long) (uintptr_t) handle); else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t))
else sprintf (buf, "0x%" PRIx64, (uint64_t) gomp_integral (handle));
sprintf (buf, "0x%x", (int) (uintptr_t) handle); #else
gomp_display_num (buffer, size, &ret, zero, right, sz, buf); else if (sizeof (gomp_integral (handle))
break; == sizeof (unsigned long long))
} sprintf (buf, "0x%llx",
(unsigned long long) gomp_integral (handle));
#endif #endif
else
sprintf (buf, "0x%x", (unsigned int) gomp_integral (handle));
gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
break;
}
#else
val = 0; val = 0;
goto do_int; goto do_int;
#endif
case 'A': case 'A':
if (sz == (size_t) -1) if (sz == (size_t) -1)
gomp_display_affinity_place (buffer, size, &ret, gomp_display_affinity_place (buffer, size, &ret,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment