aboutsummaryrefslogtreecommitdiffstats
path: root/lib/verify.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/verify.h')
-rw-r--r--lib/verify.h41
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/verify.h b/lib/verify.h
index 58172f3cb7f..d485a0283a9 100644
--- a/lib/verify.h
+++ b/lib/verify.h
@@ -23,11 +23,15 @@
23 23
24/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC) 24/* Define _GL_HAVE__STATIC_ASSERT to 1 if _Static_assert (R, DIAGNOSTIC)
25 works as per C11. This is supported by GCC 4.6.0 and later, in C 25 works as per C11. This is supported by GCC 4.6.0 and later, in C
26 mode. 26 mode, and by clang (also in C++ mode).
27 27
28 Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as 28 Define _GL_HAVE__STATIC_ASSERT1 to 1 if _Static_assert (R) works as
29 per C2X, and define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) 29 per C2X. This is supported by GCC 9.1 and later, and by clang in
30 works as per C++17. This is supported by GCC 9.1 and later. 30 C++1z mode.
31
32 Define _GL_HAVE_STATIC_ASSERT1 if static_assert (R) works as per
33 C++17. This is supported by GCC 9.1 and later, and by clang in
34 C++1z mode.
31 35
32 Support compilers claiming conformance to the relevant standard, 36 Support compilers claiming conformance to the relevant standard,
33 and also support GCC when not pedantic. If we were willing to slow 37 and also support GCC when not pedantic. If we were willing to slow
@@ -35,7 +39,8 @@
35 since this affects only the quality of diagnostics, why bother? */ 39 since this affects only the quality of diagnostics, why bother? */
36#ifndef __cplusplus 40#ifndef __cplusplus
37# if (201112L <= __STDC_VERSION__ \ 41# if (201112L <= __STDC_VERSION__ \
38 || (!defined __STRICT_ANSI__ && 4 < __GNUC__ + (6 <= __GNUC_MINOR__))) 42 || (!defined __STRICT_ANSI__ \
43 && (4 < __GNUC__ + (6 <= __GNUC_MINOR__) || 4 <= __clang_major__)))
39# define _GL_HAVE__STATIC_ASSERT 1 44# define _GL_HAVE__STATIC_ASSERT 1
40# endif 45# endif
41# if (202000L <= __STDC_VERSION__ \ 46# if (202000L <= __STDC_VERSION__ \
@@ -43,7 +48,15 @@
43# define _GL_HAVE__STATIC_ASSERT1 1 48# define _GL_HAVE__STATIC_ASSERT1 1
44# endif 49# endif
45#else 50#else
46# if 201703L <= __cplusplus || 9 <= __GNUC__ 51# if 4 <= __clang_major__
52# define _GL_HAVE__STATIC_ASSERT 1
53# endif
54# if 4 <= __clang_major__ && 201411 <= __cpp_static_assert
55# define _GL_HAVE__STATIC_ASSERT1 1
56# endif
57# if 201703L <= __cplusplus \
58 || 9 <= __GNUC__ \
59 || (4 <= __clang_major__ && 201411 <= __cpp_static_assert)
47# define _GL_HAVE_STATIC_ASSERT1 1 60# define _GL_HAVE_STATIC_ASSERT1 1
48# endif 61# endif
49#endif 62#endif
@@ -233,13 +246,6 @@ template <int w>
233 246
234/* @assert.h omit start@ */ 247/* @assert.h omit start@ */
235 248
236#if defined __has_builtin
237/* <https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions> */
238# define _GL_HAS_BUILTIN_ASSUME __has_builtin (__builtin_assume)
239#else
240# define _GL_HAS_BUILTIN_ASSUME 0
241#endif
242
243#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__)) 249#if 3 < __GNUC__ + (3 < __GNUC_MINOR__ + (4 <= __GNUC_PATCHLEVEL__))
244# define _GL_HAS_BUILTIN_TRAP 1 250# define _GL_HAS_BUILTIN_TRAP 1
245#elif defined __has_builtin 251#elif defined __has_builtin
@@ -299,11 +305,14 @@ template <int w>
299 305
300 Although assuming R can help a compiler generate better code or 306 Although assuming R can help a compiler generate better code or
301 diagnostics, performance can suffer if R uses hard-to-optimize 307 diagnostics, performance can suffer if R uses hard-to-optimize
302 features such as function calls not inlined by the compiler. */ 308 features such as function calls not inlined by the compiler.
309
310 Avoid Clang’s __builtin_assume, as clang 9.0.1 -Wassume can
311 generate a bogus diagnostic "the argument to '__builtin_assume' has
312 side effects that will be discarded" even when the argument has no
313 side effects. */
303 314
304#if _GL_HAS_BUILTIN_ASSUME 315#if _GL_HAS_BUILTIN_UNREACHABLE
305# define assume(R) __builtin_assume (R)
306#elif _GL_HAS_BUILTIN_UNREACHABLE
307# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ()) 316# define assume(R) ((R) ? (void) 0 : __builtin_unreachable ())
308#elif 1200 <= _MSC_VER 317#elif 1200 <= _MSC_VER
309# define assume(R) __assume (R) 318# define assume(R) __assume (R)