From f3808e88c188193d0011b4cdce3441719ac16d83 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 23 Aug 2020 16:24:55 +0200 Subject: [PATCH] verify: Make assume work on bit field expressions (regr. 2020-08-22). Reported by Benno Schulenberg in . * lib/verify.h (assume): Use '_Bool' or 'bool' as type of the temporary variable. --- ChangeLog | 8 ++++++++ lib/verify.h | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5ff9ccf6ef..33d4dc0f7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2020-08-23 Bruno Haible + verify: Make assume work on bit field expressions (regr. 2020-08-22). + Reported by Benno Schulenberg in + . + * lib/verify.h (assume): Use '_Bool' or 'bool' as type of the temporary + variable. + +2020-08-23 Bruno Haible + libc-config: Improve comments. * lib/cdefs.h (__warndecl, __warnattr, __errordecl): Explain why we cannot use clang's __diagnose_if__ here. diff --git a/lib/verify.h b/lib/verify.h index 04bb2dfc33..6d7b961db7 100644 --- a/lib/verify.h +++ b/lib/verify.h @@ -322,10 +322,19 @@ template #if _GL_HAS_BUILTIN_ASSUME /* Use a temporary variable, to avoid a clang warning "the argument to '__builtin_assume' has side effects that will be discarded" - if R contains invocations of functions not marked as 'const'. */ -# define assume(R) \ - ((void) ({ __typeof__ (R) _gl_verify_temp = (R); \ - __builtin_assume (_gl_verify_temp); })) + if R contains invocations of functions not marked as 'const'. + The type of the temporary variable can't be __typeof__ (R), because that + does not work on bit field expressions. Use '_Bool' or 'bool' as type + instead. */ +# if defined __cplusplus +# define assume(R) \ + ((void) ({ bool _gl_verify_temp = (R); \ + __builtin_assume (_gl_verify_temp); })) +# else +# define assume(R) \ + ((void) ({ _Bool _gl_verify_temp = (R); \ + __builtin_assume (_gl_verify_temp); })) +# endif #elif _GL_HAS_BUILTIN_UNREACHABLE # define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) #elif 1200 <= _MSC_VER -- 2.11.4.GIT