* Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9
@ 2018-11-09 10:34 Dominique d'Humières
2018-11-09 11:05 ` Jakub Jelinek
0 siblings, 1 reply; 9+ messages in thread
From: Dominique d'Humières @ 2018-11-09 10:34 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: gcc-patches, Rainer Orth
Hi Jakub,
Bootstrapping r265942 on darwin failed with
In file included from /Applications/Xcode-6.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h:490,
from ../../../work/libgomp/affinity-fmt.c:28:
../../../work/libgomp/affinity-fmt.c: In function 'gomp_display_affinity':
../../../work/libgomp/affinity-fmt.c:369:17: error: format '%x' expects argument of type 'unsigned int', but argument 5 has type 'long unsigned int' -Werror=format=]
369 | sprintf (buf, "0x%x", (uintptr_t) handle);
| ^~~~~~ ~~~~~~~~~~~~~~~~~~
| |
| long unsigned int
../../../work/libgomp/affinity-fmt.c:369:21: note: format string is defined here
369 | sprintf (buf, "0x%x", (uintptr_t) handle);
| ~^
| |
| unsigned int
| %lx
cc1: all warnings being treated as errors
I have managed to bootstrap with the following hack:
--- ../_clean/libgomp/affinity-fmt.c 2018-11-08 19:03:37.000000000 +0100
+++ libgomp/affinity-fmt.c 2018-11-09 01:00:16.000000000 +0100
@@ -362,11 +362,11 @@ gomp_display_affinity (char *buffer, siz
char buf[3 * (sizeof (handle) + sizeof (int)) + 4];
if (sizeof (handle) == sizeof (long))
- sprintf (buf, "0x%lx", (long) handle);
+ sprintf (buf, "0x%lx", (long) (uintptr_t) handle);
else if (sizeof (handle) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) handle);
+ sprintf (buf, "0x%llx", (long long) (uintptr_t) handle);
else
- sprintf (buf, "0x%x", (int) handle);
+ sprintf (buf, "0x%x", (int) (uintptr_t) handle);
gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
break;
}
which is certainly wrong, but allowed me to bootstrap.
TIA
Dominique
PS I can file a PR if necessary.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9
2018-11-09 10:34 [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9 Dominique d'Humières
@ 2018-11-09 11:05 ` Jakub Jelinek
2018-11-09 11:11 ` Jakub Jelinek
2018-11-09 14:37 ` [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9) Jakub Jelinek
0 siblings, 2 replies; 9+ messages in thread
From: Jakub Jelinek @ 2018-11-09 11:05 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gcc-patches, Rainer Orth
On Fri, Nov 09, 2018 at 11:34:48AM +0100, Dominique d'Humières wrote:
> Bootstrapping r265942 on darwin failed with
>
> In file included from /Applications/Xcode-6.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h:490,
> from ../../../work/libgomp/affinity-fmt.c:28:
> ../../../work/libgomp/affinity-fmt.c: In function 'gomp_display_affinity':
> ../../../work/libgomp/affinity-fmt.c:369:17: error: format '%x' expects argument of type 'unsigned int', but argument 5 has type 'long unsigned int' -Werror=format=]
> 369 | sprintf (buf, "0x%x", (uintptr_t) handle);
> | ^~~~~~ ~~~~~~~~~~~~~~~~~~
Weird, the above prints a line which just isn't there, line 369 is:
sprintf (buf, "0x%x", (int) handle);
not
sprintf (buf, "0x%x", (uintptr_t) handle);
What is pthread_t on your platform? An integral type (which one), pointer
or something different (e.g. an aggregate)?
I wonder if I shouldn't use __builtin_choose_expr to wrap it up and select
at compile time the only variant that applies.
Something like:
--- libgomp/affinity-fmt.c 2018-10-08 13:27:41.021061844 +0200
+++ libgomp/affinity-fmt.c 2018-11-09 12:01:17.048151087 +0100
@@ -356,37 +356,39 @@ gomp_display_affinity (char *buffer, siz
goto do_int;
case 'i':
#if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__)
- /* Handle integral pthread_t. */
- if (__builtin_classify_type (handle) == 1)
- {
- char buf[3 * (sizeof (handle) + sizeof (int)) + 4];
-
- if (sizeof (handle) == sizeof (long))
- sprintf (buf, "0x%lx", (long) handle);
- else if (sizeof (handle) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) handle);
- else
- sprintf (buf, "0x%x", (int) handle);
- gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
- break;
- }
- /* And pointer pthread_t. */
- else if (__builtin_classify_type (handle) == 5)
- {
- char buf[3 * (sizeof (uintptr_t) + sizeof (int)) + 4];
-
- if (sizeof (uintptr_t) == sizeof (long))
- sprintf (buf, "0x%lx", (long) (uintptr_t) handle);
- else if (sizeof (uintptr_t) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) (uintptr_t) handle);
- else
- sprintf (buf, "0x%x", (int) (uintptr_t) handle);
- gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
- break;
- }
-#endif
+ {
+ char buf[3 * (sizeof (handle) + sizeof (uintptr_t) + sizeof (int))
+ + 4];
+ /* Handle integral pthread_t. */
+ __builtin_choose_expr (__builtin_classify_type (handle) == 1,
+ sizeof (handle) == sizeof (long)
+ ? sprintf (buf, "0x%lx", (long) handle)
+ : sizeof (handle) == sizeof (long long)
+ ? sprintf (buf, "0x%llx",
+ (long long) handle)
+ : sprintf (buf, "0x%x", (int) handle),
+ 0);
+ /* And pointer pthread_t. */
+ __builtin_choose_expr (__builtin_classify_type (handle) == 5,
+ sizeof (uintptr_t) == sizeof (long)
+ ? sprintf (buf, "0x%lx",
+ (long) (uintptr_t) handle)
+ : sizeof (uintptr_t) == sizeof (long long)
+ ? sprintf (buf, "0x%llx",
+ (long long) (uintptr_t) handle)
+ : sprintf (buf, "0x%x",
+ (int) (uintptr_t) handle),
+ 0);
+ if (__builtin_classify_type (handle) != 1
+ && __builtin_classify_type (handle) != 5)
+ strcpy (buf, "0");
+ gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
+ break;
+ }
+#else
val = 0;
goto do_int;
+#endif
case 'A':
if (sz == (size_t) -1)
gomp_display_affinity_place (buffer, size, &ret,
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9
2018-11-09 11:05 ` Jakub Jelinek
@ 2018-11-09 11:11 ` Jakub Jelinek
2018-11-09 14:49 ` David Malcolm
2018-11-09 14:37 ` [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9) Jakub Jelinek
1 sibling, 1 reply; 9+ messages in thread
From: Jakub Jelinek @ 2018-11-09 11:11 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gcc-patches, Rainer Orth
On Fri, Nov 09, 2018 at 12:04:54PM +0100, Jakub Jelinek wrote:
> On Fri, Nov 09, 2018 at 11:34:48AM +0100, Dominique d'Humières wrote:
> > Bootstrapping r265942 on darwin failed with
> >
> > In file included from /Applications/Xcode-6.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h:490,
> > from ../../../work/libgomp/affinity-fmt.c:28:
> > ../../../work/libgomp/affinity-fmt.c: In function 'gomp_display_affinity':
> > ../../../work/libgomp/affinity-fmt.c:369:17: error: format '%x' expects argument of type 'unsigned int', but argument 5 has type 'long unsigned int' -Werror=format=]
> > 369 | sprintf (buf, "0x%x", (uintptr_t) handle);
> > | ^~~~~~ ~~~~~~~~~~~~~~~~~~
>
> Weird, the above prints a line which just isn't there, line 369 is:
> sprintf (buf, "0x%x", (int) handle);
> not
> sprintf (buf, "0x%x", (uintptr_t) handle);
>
> What is pthread_t on your platform? An integral type (which one), pointer
> or something different (e.g. an aggregate)?
The "but argument 5" in there is also weird, sprintf has 3 arguments.
Doesn't current gcc emit warnings like:
/tmp/j.c: In function âmainâ:
/tmp/j.c:8:21: warning: format â%xâ expects argument of type âunsigned intâ, but argument 3 has type âlong unsigned intâ [-Wformat=]
8 | sprintf (buf, "0x%x", l);
| ~^ ~
| | |
| | long unsigned int
| unsigned int
| %lx
?
So, what exact compiler is compiling this code?
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9)
2018-11-09 11:05 ` Jakub Jelinek
2018-11-09 11:11 ` Jakub Jelinek
@ 2018-11-09 14:37 ` Jakub Jelinek
2018-11-09 15:33 ` Iain Sandoe
1 sibling, 1 reply; 9+ messages in thread
From: Jakub Jelinek @ 2018-11-09 14:37 UTC (permalink / raw)
To: Dominique d'Humières; +Cc: gcc-patches, Rainer Orth
Hi!
The earlier patch doesn't work, because there were still expressions
where handle could be still cast to integer of different size if it
happened to be a pointer, or an invalid cast of e.g. aggregate to
integer.
The following patch so far only tested on a simplified code should
handle it properly though, gomp_integral should yield an integral type
without a warning (for aggregates etc. 0, but that is what I wanted to
print, don't know what else to print if pthread_t is an aggregate I have no
idea what it contains). Plus I've added some portability stuff for mingw
%llx vs. %I64x.
Can you please give it a whirl on Darwin and see what the
display-affinity-1.c testcase prints (in libgomp/testsuite/libgomp.log) ?
Thanks.
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.
--- libgomp/affinity-fmt.c.jj 2018-11-08 18:08:01.412987460 +0100
+++ libgomp/affinity-fmt.c 2018-11-09 15:24:52.049169494 +0100
@@ -30,6 +30,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h> /* For PRIx64. */
+#endif
#ifdef HAVE_UNAME
#include <sys/utsname.h>
#endif
@@ -356,37 +359,42 @@ gomp_display_affinity (char *buffer, siz
goto do_int;
case 'i':
#if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__)
- /* Handle integral pthread_t. */
- if (__builtin_classify_type (handle) == 1)
- {
- char buf[3 * (sizeof (handle) + sizeof (int)) + 4];
-
- if (sizeof (handle) == sizeof (long))
- sprintf (buf, "0x%lx", (long) handle);
- else if (sizeof (handle) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) handle);
- else
- sprintf (buf, "0x%x", (int) handle);
- gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
- break;
- }
- /* And pointer pthread_t. */
- else if (__builtin_classify_type (handle) == 5)
- {
- char buf[3 * (sizeof (uintptr_t) + sizeof (int)) + 4];
-
- if (sizeof (uintptr_t) == sizeof (long))
- sprintf (buf, "0x%lx", (long) (uintptr_t) handle);
- else if (sizeof (uintptr_t) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) (uintptr_t) handle);
- else
- sprintf (buf, "0x%x", (int) (uintptr_t) handle);
- gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
- break;
- }
+ {
+ char buf[3 * (sizeof (handle) + sizeof (uintptr_t) + sizeof (int))
+ + 4];
+ /* This macro returns expr unmodified for integral or pointer
+ types and 0 for anything else (e.g. aggregates). */
+#define gomp_nonaggregate(expr) \
+ __builtin_choose_expr (__builtin_classify_type (expr) == 1 \
+ || __builtin_classify_type (expr) == 5, expr, 0)
+ /* This macro returns expr unmodified for integral types,
+ (uintptr_t) (expr) for pointer types and 0 for anything else
+ (e.g. aggregates). */
+#define gomp_integral(expr) \
+ __builtin_choose_expr (__builtin_classify_type (expr) == 5, \
+ (uintptr_t) gomp_nonaggregate (expr), \
+ gomp_nonaggregate (expr))
+
+ if (sizeof (gomp_integral (handle)) == sizeof (unsigned long))
+ sprintf (buf, "0x%lx", (unsigned long) gomp_integral (handle));
+#if defined (HAVE_INTTYPES_H) && defined (PRIx64)
+ else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t))
+ sprintf (buf, "0x" PRIx64, (uint64_t) gomp_integral (handle));
+#else
+ else if (sizeof (gomp_integral (handle))
+ == sizeof (unsigned long long))
+ sprintf (buf, "0x%llx",
+ (unsigned long long) gomp_integral (handle));
#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;
goto do_int;
+#endif
case 'A':
if (sz == (size_t) -1)
gomp_display_affinity_place (buffer, size, &ret,
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9
2018-11-09 11:11 ` Jakub Jelinek
@ 2018-11-09 14:49 ` David Malcolm
0 siblings, 0 replies; 9+ messages in thread
From: David Malcolm @ 2018-11-09 14:49 UTC (permalink / raw)
To: Jakub Jelinek, Dominique d'Humières; +Cc: gcc-patches, Rainer Orth
On Fri, 2018-11-09 at 12:11 +0100, Jakub Jelinek wrote:
> On Fri, Nov 09, 2018 at 12:04:54PM +0100, Jakub Jelinek wrote:
> > On Fri, Nov 09, 2018 at 11:34:48AM +0100, Dominique d'Humières
> > wrote:
> > > Bootstrapping r265942 on darwin failed with
> > >
> > > In file included from /Applications/Xcode-
> > > 6.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SD
> > > Ks/MacOSX10.9.sdk/usr/include/stdio.h:490,
> > > from ../../../work/libgomp/affinity-fmt.c:28:
> > > ../../../work/libgomp/affinity-fmt.c: In function
> > > 'gomp_display_affinity':
> > > ../../../work/libgomp/affinity-fmt.c:369:17: error: format '%x'
> > > expects argument of type 'unsigned int', but argument 5 has type
> > > 'long unsigned int' -Werror=format=]
> > > 369 | sprintf (buf, "0x%x", (uintptr_t) handle);
> > > | ^~~~~~ ~~~~~~~~~~~~~~~~~~
> >
> > Weird, the above prints a line which just isn't there, line 369 is:
> > sprintf (buf, "0x%x", (int) handle);
> > not
> > sprintf (buf, "0x%x", (uintptr_t) handle);
> >
> > What is pthread_t on your platform? An integral type (which one),
> > pointer
> > or something different (e.g. an aggregate)?
>
> The "but argument 5" in there is also weird, sprintf has 3 arguments.
> Doesn't current gcc emit warnings like:
> /tmp/j.c: In function âmainâ:
> /tmp/j.c:8:21: warning: format â%xâ expects argument of type
> âunsigned intâ, but argument 3 has type âlong unsigned intâ [-
> Wformat=]
> 8 | sprintf (buf, "0x%x", l);
> | ~^ ~
> | | |
> | | long unsigned int
> | unsigned int
> | %lx
> ?
> So, what exact compiler is compiling this code?
I agree that that looks weird. I wonder if this is showing a bug in
the substring-locations.c or c-format.c code? (I've changed these in
the last couple of months; maybe I messed up?) Or is the compiler
picking up the wrong code?
The fact that it fails to use the location *within* the string in the
initial error but then prints a supporting "note" with it suggests to
me that there are macros involved. Is sprintf a macro on this
configuration? Maybe that's got something to do with it.
Dave
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9)
2018-11-09 14:37 ` [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9) Jakub Jelinek
@ 2018-11-09 15:33 ` Iain Sandoe
2018-11-09 15:40 ` Jakub Jelinek
0 siblings, 1 reply; 9+ messages in thread
From: Iain Sandoe @ 2018-11-09 15:33 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Dominique d'Humières, gcc-patches, Rainer Orth
Hi Jakub,
> On 9 Nov 2018, at 06:37, Jakub Jelinek <jakub@redhat.com> wrote:
> +#if defined (HAVE_INTTYPES_H) && defined (PRIx64)
> + else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t))
> + sprintf (buf, "0x" PRIx64, (uint64_t) gomp_integral (handle));
s/0x/0x%/?
Iain
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9)
2018-11-09 15:33 ` Iain Sandoe
@ 2018-11-09 15:40 ` Jakub Jelinek
2018-11-09 18:23 ` Iain Sandoe
0 siblings, 1 reply; 9+ messages in thread
From: Jakub Jelinek @ 2018-11-09 15:40 UTC (permalink / raw)
To: Iain Sandoe; +Cc: Dominique d'Humières, gcc-patches, Rainer Orth
On Fri, Nov 09, 2018 at 07:33:44AM -0800, Iain Sandoe wrote:
> > On 9 Nov 2018, at 06:37, Jakub Jelinek <jakub@redhat.com> wrote:
>
> > +#if defined (HAVE_INTTYPES_H) && defined (PRIx64)
> > + else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t))
> > + sprintf (buf, "0x" PRIx64, (uint64_t) gomp_integral (handle));
>
> s/0x/0x%/?
Oops, consider it adjusted. Haven't started my bootstrap/regtest of it
yet...
Thanks.
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9)
2018-11-09 15:40 ` Jakub Jelinek
@ 2018-11-09 18:23 ` Iain Sandoe
2018-11-09 20:24 ` Jakub Jelinek
0 siblings, 1 reply; 9+ messages in thread
From: Iain Sandoe @ 2018-11-09 18:23 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Dominique d'Humières, gcc-patches, Rainer Orth
Hi Jakub,
> On 9 Nov 2018, at 07:40, Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Fri, Nov 09, 2018 at 07:33:44AM -0800, Iain Sandoe wrote:
>>> On 9 Nov 2018, at 06:37, Jakub Jelinek <jakub@redhat.com> wrote:
>>
>>> +#if defined (HAVE_INTTYPES_H) && defined (PRIx64)
>>> + else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t))
>>> + sprintf (buf, "0x" PRIx64, (uint64_t) gomp_integral (handle));
>>
>> s/0x/0x%/?
>
> Oops, consider it adjusted. Haven't started my bootstrap/regtest of it
> yet…
Works For Me (as amended, bootstrap succeeds):
display-affinity-1.c:
libgomp: Affinity not supported on this configuration
L:00000%0>xxxxxx.local <! xxxxxx.local! 14527_0x7fffe64ed3c0_0x00007fffe64ed3c0_-000001 0-7
L:00000%0>xxxxxx.local <! xxxxxx.local! 14527_0x7fffe64ed3c0_0x00007fffe64ed3c0_-000001 0-7
%000000001
00!0! 1!4; 0;01;0;1;0-7
00!1! 1!4; 0;01;0;1;0-7
00!2! 1!4; 0;01;0;1;0-7
00!3! 1!4; 0;01;0;1;0-7
=====
Iain
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9)
2018-11-09 18:23 ` Iain Sandoe
@ 2018-11-09 20:24 ` Jakub Jelinek
0 siblings, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2018-11-09 20:24 UTC (permalink / raw)
To: Iain Sandoe; +Cc: Dominique d'Humières, gcc-patches, Rainer Orth
On Fri, Nov 09, 2018 at 10:23:24AM -0800, Iain Sandoe wrote:
> Works For Me (as amended, bootstrap succeeds):
>
> display-affinity-1.c:
> libgomp: Affinity not supported on this configuration
> L:00000%0>xxxxxx.local <! xxxxxx.local! 14527_0x7fffe64ed3c0_0x00007fffe64ed3c0_-000001 0-7
> L:00000%0>xxxxxx.local <! xxxxxx.local! 14527_0x7fffe64ed3c0_0x00007fffe64ed3c0_-000001 0-7
> %000000001
> 00!0! 1!4; 0;01;0;1;0-7
> 00!1! 1!4; 0;01;0;1;0-7
> 00!2! 1!4; 0;01;0;1;0-7
> 00!3! 1!4; 0;01;0;1;0-7
>
> =====
Thanks, I've also successfully bootstrapped/regtested it on x86_64-linux and
i686-linux, verified the display-affinity-1.c output on both and committed
to trunk. Here it is again because of the missing %:
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.
--- libgomp/affinity-fmt.c.jj 2018-11-08 18:08:01.412987460 +0100
+++ libgomp/affinity-fmt.c 2018-11-09 15:24:52.049169494 +0100
@@ -30,6 +30,9 @@
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
+#ifdef HAVE_INTTYPES_H
+# include <inttypes.h> /* For PRIx64. */
+#endif
#ifdef HAVE_UNAME
#include <sys/utsname.h>
#endif
@@ -356,37 +359,42 @@ gomp_display_affinity (char *buffer, siz
goto do_int;
case 'i':
#if defined(LIBGOMP_USE_PTHREADS) && defined(__GNUC__)
- /* Handle integral pthread_t. */
- if (__builtin_classify_type (handle) == 1)
- {
- char buf[3 * (sizeof (handle) + sizeof (int)) + 4];
-
- if (sizeof (handle) == sizeof (long))
- sprintf (buf, "0x%lx", (long) handle);
- else if (sizeof (handle) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) handle);
- else
- sprintf (buf, "0x%x", (int) handle);
- gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
- break;
- }
- /* And pointer pthread_t. */
- else if (__builtin_classify_type (handle) == 5)
- {
- char buf[3 * (sizeof (uintptr_t) + sizeof (int)) + 4];
-
- if (sizeof (uintptr_t) == sizeof (long))
- sprintf (buf, "0x%lx", (long) (uintptr_t) handle);
- else if (sizeof (uintptr_t) == sizeof (long long))
- sprintf (buf, "0x%llx", (long long) (uintptr_t) handle);
- else
- sprintf (buf, "0x%x", (int) (uintptr_t) handle);
- gomp_display_num (buffer, size, &ret, zero, right, sz, buf);
- break;
- }
+ {
+ char buf[3 * (sizeof (handle) + sizeof (uintptr_t) + sizeof (int))
+ + 4];
+ /* This macro returns expr unmodified for integral or pointer
+ types and 0 for anything else (e.g. aggregates). */
+#define gomp_nonaggregate(expr) \
+ __builtin_choose_expr (__builtin_classify_type (expr) == 1 \
+ || __builtin_classify_type (expr) == 5, expr, 0)
+ /* This macro returns expr unmodified for integral types,
+ (uintptr_t) (expr) for pointer types and 0 for anything else
+ (e.g. aggregates). */
+#define gomp_integral(expr) \
+ __builtin_choose_expr (__builtin_classify_type (expr) == 5, \
+ (uintptr_t) gomp_nonaggregate (expr), \
+ gomp_nonaggregate (expr))
+
+ if (sizeof (gomp_integral (handle)) == sizeof (unsigned long))
+ sprintf (buf, "0x%lx", (unsigned long) gomp_integral (handle));
+#if defined (HAVE_INTTYPES_H) && defined (PRIx64)
+ else if (sizeof (gomp_integral (handle)) == sizeof (uint64_t))
+ sprintf (buf, "0x%" PRIx64, (uint64_t) gomp_integral (handle));
+#else
+ else if (sizeof (gomp_integral (handle))
+ == sizeof (unsigned long long))
+ sprintf (buf, "0x%llx",
+ (unsigned long long) gomp_integral (handle));
#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;
goto do_int;
+#endif
case 'A':
if (sz == (size_t) -1)
gomp_display_affinity_place (buffer, size, &ret,
Jakub
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2018-11-09 20:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-09 10:34 [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9 Dominique d'Humières
2018-11-09 11:05 ` Jakub Jelinek
2018-11-09 11:11 ` Jakub Jelinek
2018-11-09 14:49 ` David Malcolm
2018-11-09 14:37 ` [PATCH] Fix up affinity-fmt.c (was Re: [committed 0/4] (Partial) OpenMP 5.0 support for GCC 9) Jakub Jelinek
2018-11-09 15:33 ` Iain Sandoe
2018-11-09 15:40 ` Jakub Jelinek
2018-11-09 18:23 ` Iain Sandoe
2018-11-09 20:24 ` Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).