On 4/9/21 2:25 AM, Jakub Jelinek via Gcc-patches wrote:
Hi!
pthread_setspecific second argument is const void *, so that one can
call it even with pointers to const, but the function only stores the
pointer and does nothing else, so the new assumption of -Wmaybe-uninitialized
that functions taking such pointers will read from what those pointers
will point to is wrong. Maybe it would be useful to have some whitelist
of functions that surely don't do that.
The intended mechanism to suppress the warning in these cases is
attribute access: adding __attribute__ ((access (none, 2))) to
pthread_setspecific() avoids the warning. I opened a Glibc bug
to do that:
https://sourceware.org/bugzilla/show_bug.cgi?id=27714
Martin
Anyway, in this case it is easy to workaround the warning by moving the
pthread_setspecific call after the initialization without slowing anything
down.
I don't have access to a target without TLS support, so tested just by
manually commenting out #define HAVE_TLS 1 in libgomp config.h , verifying
the warning is gone and eyeballing -fdump-tree-{gimple,optimized}.
Committed to trunk.
2021-04-09 Jakub Jelinek <ja...@redhat.com>
PR libgomp/99984
* team.c (gomp_thread_start): Call pthread_setspecific for
!(defined HAVE_TLS || defined USE_EMUTLS) only after local_thr
has been initialized to avoid false positive warning.
--- libgomp/team.c.jj 2021-02-26 21:58:48.489853641 +0100
+++ libgomp/team.c 2021-04-09 10:03:09.355482978 +0200
@@ -78,7 +78,6 @@ gomp_thread_start (void *xdata)
#else
struct gomp_thread local_thr;
thr = &local_thr;
- pthread_setspecific (gomp_tls_key, thr);
#endif
gomp_sem_init (&thr->release, 0);
@@ -92,6 +91,9 @@ gomp_thread_start (void *xdata)
#ifdef GOMP_NEEDS_THREAD_HANDLE
thr->handle = data->handle;
#endif
+#if !(defined HAVE_TLS || defined USE_EMUTLS)
+ pthread_setspecific (gomp_tls_key, thr);
+#endif
thr->ts.team->ordered_release[thr->ts.team_id] = &thr->release;
Jakub