bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: commit 452fee36 causes trouble when compiling with clang


From: Bruno Haible
Subject: Re: commit 452fee36 causes trouble when compiling with clang
Date: Sun, 23 Aug 2020 16:28:11 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-186-generic; KDE/5.18.0; x86_64; ; )

Hi Benno,

> Running a compile test of nano with the current state of gnulib
> (commit 452fee36, "verify: Do use __builtin_assume on clang")
> on FreeBSD (which happens to use clang), the compile failed:
> 
> clang -DHAVE_CONFIG_H -I. -I..   -D_GNU_SOURCE -D_DEFAULT_SOURCE
> -I/usr/include/ncursesw   -g -O1 -march=native -Wvla -Wshadow -Wall -MT 
> regex.o
> -MD -MP -MF $depbase.Tpo -c -o regex.o regex.c &&\
> mv -f $depbase.Tpo $depbase.Po
> In file included from regex.c:74:
> ./regexec.c:1198:3: error: invalid application of 'typeof' to bit-field
>   DEBUG_ASSERT (state->halt);
>   ^
> ./regex_internal.h:42:26: note: expanded from macro 'DEBUG_ASSERT'
> # define DEBUG_ASSERT(x) assume (x)
>                          ^
> ./verify.h:327:27: note: expanded from macro 'assume'
>     ((void) ({ __typeof__ (R) _gl_verify_temp = (R); \
>                           ^
> 1 error generated.
> 
> Stepping one commit back, the compile succeeds fine.
> 
> $ clang --version
> FreeBSD clang version 8.0.1 (tags/RELEASE_801/final 366581) (based on LLVM 
> 8.0.1)
> 
> 
> Same failure on Ubuntu 18.04 when using clang.
> 
> $ clang --version
> clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)

Thanks for the report. I didn't know that __typeof__ does not work for all
kinds of expressions. (intprops uses __typeof__ as well.) This patch fixes it.


2020-08-23  Bruno Haible  <bruno@clisp.org>

        verify: Make assume work on bit field expressions (regr. 2020-08-22).
        Reported by Benno Schulenberg <bensberg@telfort.nl> in
        <https://lists.gnu.org/archive/html/bug-gnulib/2020-08/msg00202.html>.
        * lib/verify.h (assume): Use '_Bool' or 'bool' as type of the temporary
        variable.

diff --git a/lib/verify.h b/lib/verify.h
index 04bb2df..6d7b961 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -322,10 +322,19 @@ template <int w>
 #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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]