Message ID | 1511266813-5215-1-git-send-email-adhemerval.zanella@linaro.org |
---|---|
State | New |
Headers | show |
Series | nptl: Add workaround for ASSERT_PTHREAD_INTERNAL_SIZE with GCC 4.9 | expand |
On 11/21/2017 01:20 PM, Adhemerval Zanella wrote: > - _Static_assert (sizeof ((type) { 0 }).__size >= sizeof (internal), \ > + _Static_assert (sizeof ((type) { { 0 } }).__size >= sizeof (internal),\ Doesn't GCC support an empty initializer as an extension? Maybe you can use that. Otherwise, the version above is fine as well. Thanks, Florian
On 21/11/2017 11:10, Florian Weimer wrote: > On 11/21/2017 01:20 PM, Adhemerval Zanella wrote: >> - _Static_assert (sizeof ((type) { 0 }).__size >= sizeof (internal), \ >> + _Static_assert (sizeof ((type) { { 0 } }).__size >= sizeof (internal),\ > > Doesn't GCC support an empty initializer as an extension? Maybe you can use that. Otherwise, the version above is fine as well. My understanding from bug report is empty initializer is really defined for C++. Anyway the internal contents of the created struct is not really important here, I think either would work (I will stick with mine just because I already checked it works on GCC from 4 to 7).
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 1cc80b6..713000e 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -644,7 +644,7 @@ check_stacksize_attr (size_t st) "sizeof (" #type ") != " #size) #define ASSERT_PTHREAD_INTERNAL_SIZE(type, internal) \ - _Static_assert (sizeof ((type) { 0 }).__size >= sizeof (internal), \ + _Static_assert (sizeof ((type) { { 0 } }).__size >= sizeof (internal),\ "sizeof (" #type ".__size) < sizeof (" #internal ")") #define ASSERT_PTHREAD_STRING(x) __STRING (x)
GCC 4.9 (the minimum current supported) emits an warning for universal zero initializer ({0}) on ASSERT_PTHREAD_INTERNAL_SIZE: pthread_attr_init.c: In function ‘__pthread_attr_init_2_1’: pthread_attr_init.c:37:3: error: missing braces around initializer [-Werror=missing-braces] ASSERT_PTHREAD_INTERNAL_SIZE (pthread_attr_t, struct pthread_attr); ^ pthread_attr_init.c:37:3: error: (near initialization for ‘(anonymous).__size’) [-Werror=missing-braces] It is fact GCC BZ#53119 [1] fixed in later version (GCC5+). Since current branch is closed and there is no indication it will be backports (comment #20 in same bug report) this patch fixes by using a double bracket to zero initialize the struct. Checked on x86_64-linux-gnu with GCC 7 and GCC 4.9. * nptl/pthreadP.h (ASSERT_PTHREAD_INTERNAL_SIZE): Add workarond for -Wmissing-braces on GCC 4.9. [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119 Signed-off-by: Adhemerval Zanella <adhemerval.zanella@linaro.org> --- ChangeLog | 5 +++++ nptl/pthreadP.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) -- 2.7.4