diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2023-01-28 08:56:54 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2023-01-28 08:56:54 +0000 |
commit | d305570c9b1fd87c4acdec589761cfa39fd04a3b (patch) | |
tree | e340315dd9d6966ccc3a48aa7a845e2213e40e62 /lib/mesa/src/util/macros.h | |
parent | 1c5c7896c1d54abd25c0f33ca996165b359eecb3 (diff) |
Merge Mesa 22.3.4
Diffstat (limited to 'lib/mesa/src/util/macros.h')
-rw-r--r-- | lib/mesa/src/util/macros.h | 81 |
1 files changed, 45 insertions, 36 deletions
diff --git a/lib/mesa/src/util/macros.h b/lib/mesa/src/util/macros.h index 7c6df7e58..4175a795a 100644 --- a/lib/mesa/src/util/macros.h +++ b/lib/mesa/src/util/macros.h @@ -24,13 +24,10 @@ #ifndef UTIL_MACROS_H #define UTIL_MACROS_H -#include <stdio.h> #include <assert.h> - -#include "c99_compat.h" -#include "c11_compat.h" - +#include <stddef.h> #include <stdint.h> +#include <stdio.h> /* Compute the size of an array */ #ifndef ARRAY_SIZE @@ -73,25 +70,9 @@ /** * Static (compile-time) assertion. */ -#if defined(_MSC_VER) - /* MSVC doesn't like VLA's, but it also dislikes zero length arrays - * (which gcc is happy with), so we have to define STATIC_ASSERT() - * slightly differently. - */ -# define STATIC_ASSERT(COND) do { \ - (void) sizeof(char [(COND) != 0]); \ - } while (0) -#elif defined(__GNUC__) - /* This version of STATIC_ASSERT() relies on VLAs. If COND is - * false/zero, the array size will be -1 and we'll get a compile - * error - */ -# define STATIC_ASSERT(COND) do { \ - (void) sizeof(char [1 - 2*!(COND)]); \ - } while (0) -#else -# define STATIC_ASSERT(COND) do { } while (0) -#endif +#define STATIC_ASSERT(cond) do { \ + static_assert(cond, #cond); \ +} while (0) /** * container_of - cast a member of a structure out to the containing structure @@ -108,9 +89,9 @@ __builtin_types_compatible_p(__typeof__(a), __typeof__(b)) # define container_of(ptr, type, member) ({ \ uint8_t *__mptr = (uint8_t *)(ptr); \ - STATIC_ASSERT(__same_type(*(ptr), ((type *)0)->member) || \ - __same_type(*(ptr), void) || \ - !"pointer type mismatch in container_of()"); \ + static_assert(__same_type(*(ptr), ((type *)0)->member) || \ + __same_type(*(ptr), void), \ + "pointer type mismatch in container_of()"); \ ((type *)(__mptr - offsetof(type, member))); \ }) #endif @@ -160,7 +141,7 @@ do { \ * value. As a result, calls to it can be CSEed. Note that using memory * pointed to by the arguments is not allowed for const functions. */ -#ifdef HAVE_FUNC_ATTRIBUTE_CONST +#if !defined(__clang__) && defined(HAVE_FUNC_ATTRIBUTE_CONST) #define ATTRIBUTE_CONST __attribute__((__const__)) #else #define ATTRIBUTE_CONST @@ -247,8 +228,10 @@ do { \ * performs no action and all member variables and base classes are * trivially destructible themselves. */ -# if (defined(__clang__) && defined(__has_feature)) -# if __has_feature(has_trivial_destructor) +# if defined(__clang__) +# if __has_builtin(__is_trivially_destructible) +# define HAS_TRIVIAL_DESTRUCTOR(T) __is_trivially_destructible(T) +# elif (defined(__has_feature) && __has_feature(has_trivial_destructor)) # define HAS_TRIVIAL_DESTRUCTOR(T) __has_trivial_destructor(T) # endif # elif defined(__GNUC__) @@ -299,6 +282,8 @@ do { \ */ #ifdef HAVE_FUNC_ATTRIBUTE_UNUSED #define UNUSED __attribute__((unused)) +#elif defined (_MSC_VER) +#define UNUSED __pragma(warning(suppress:4100 4101)) #else #define UNUSED #endif @@ -373,6 +358,9 @@ do { \ /** Align a value to a power of two */ #define ALIGN_POT(x, pot_align) (((x) + (pot_align) - 1) & ~((pot_align) - 1)) +/** Checks is a value is a power of two. Does not handle zero. */ +#define IS_POT(v) (((v) & ((v) - 1)) == 0) + /** * Macro for declaring an explicit conversion operator. Defaults to an * implicit conversion if C++11 is not supported. @@ -425,13 +413,12 @@ u_uintN_max(unsigned bit_size) return UINT64_MAX >> (64 - bit_size); } -#if !defined(alignof) && !defined(__cplusplus) -#if __STDC_VERSION__ >= 201112L -#define alignof(t) _Alignof(t) -#elif defined(_MSC_VER) -#define alignof(t) __alignof(t) +#ifndef __cplusplus +#ifdef _MSC_VER +#define alignof _Alignof +#define alignas _Alignas #else -#define alignof(t) __alignof__(t) +#include <stdalign.h> #endif #endif @@ -466,4 +453,26 @@ typedef int lock_cap_t; /* TODO: this could be different on non-x86 architectures. */ #define CACHE_LINE_SIZE 64 +#define DO_PRAGMA(X) _Pragma (#X) + +#if defined(__clang__) +#define PRAGMA_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") +#define PRAGMA_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#define PRAGMA_DIAGNOSTIC_ERROR(X) DO_PRAGMA( clang diagnostic error #X ) +#define PRAGMA_DIAGNOSTIC_WARNING(X) DO_PRAGMA( clang diagnostic warning #X ) +#define PRAGMA_DIAGNOSTIC_IGNORED(X) DO_PRAGMA( clang diagnostic ignored #X ) +#elif defined(__GNUC__) +#define PRAGMA_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") +#define PRAGMA_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#define PRAGMA_DIAGNOSTIC_ERROR(X) DO_PRAGMA( GCC diagnostic error #X ) +#define PRAGMA_DIAGNOSTIC_WARNING(X) DO_PRAGMA( GCC diagnostic warning #X ) +#define PRAGMA_DIAGNOSTIC_IGNORED(X) DO_PRAGMA( GCC diagnostic ignored #X ) +#else +#define PRAGMA_DIAGNOSTIC_PUSH +#define PRAGMA_DIAGNOSTIC_POP +#define PRAGMA_DIAGNOSTIC_ERROR(X) +#define PRAGMA_DIAGNOSTIC_WARNING(X) +#define PRAGMA_DIAGNOSTIC_IGNORED(X) +#endif + #endif /* UTIL_MACROS_H */ |