Module: Mesa
Branch: main
Commit: b15d0a11a44e6db2071e687ecb52a3df7d5eea90
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=b15d0a11a44e6db2071e687ecb52a3df7d5eea90

Author: Mark Janes <[email protected]>
Date:   Thu Jul 28 15:49:36 2022 -0700

util: define helpful macros for compiler diagnostic features

Suggested-by: Kenneth Graunke <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17749>

---

 src/util/macros.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/util/macros.h b/src/util/macros.h
index e978007df6b..652ba63ac5a 100644
--- a/src/util/macros.h
+++ b/src/util/macros.h
@@ -450,4 +450,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 */

Reply via email to