From 2ceccedc54ed9f822fd0da71f2f7c5c73bcb2728 Mon Sep 17 00:00:00 2001 From: Dana Robinson <43805+derobins@users.noreply.github.com> Date: Wed, 7 Jun 2023 05:51:19 -0700 Subject: Bring gcc/clang attribute and warning macros over (#3063) --- src/H5private.h | 102 ++++++++++++++++++++++++++++++++------------------------ src/H5public.h | 34 ++++++++++++++++--- 2 files changed, 89 insertions(+), 47 deletions(-) diff --git a/src/H5private.h b/src/H5private.h index 36a40ad..ff23370 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -276,52 +276,68 @@ * gcc warnings (it has to use the public API and can't include this * file). Be sure to update that file if the #ifdefs change here. */ +/* clang-format off */ #if defined(H5_HAVE_ATTRIBUTE) && !defined(__SUNPRO_C) -#define H5_ATTR_FORMAT(X, Y, Z) __attribute__((format(X, Y, Z))) -#define H5_ATTR_UNUSED __attribute__((unused)) -#ifdef H5_HAVE_PARALLEL -#define H5_ATTR_PARALLEL_UNUSED __attribute__((unused)) -#define H5_ATTR_PARALLEL_USED /*void*/ -#else -#define H5_ATTR_PARALLEL_UNUSED /*void*/ -#define H5_ATTR_PARALLEL_USED __attribute__((unused)) -#endif -#ifdef H5_NO_DEPRECATED_SYMBOLS -#define H5_ATTR_DEPRECATED_USED H5_ATTR_UNUSED -#else /* H5_NO_DEPRECATED_SYMBOLS */ -#define H5_ATTR_DEPRECATED_USED /*void*/ -#endif /* H5_NO_DEPRECATED_SYMBOLS */ -#ifdef H5_DEBUG_API -#define H5_ATTR_DEBUG_API_USED /*void*/ -#else /* H5_DEBUG_API */ -#define H5_ATTR_DEBUG_API_USED H5_ATTR_UNUSED -#endif /* H5_DEBUG_API */ -#ifndef NDEBUG -#define H5_ATTR_NDEBUG_UNUSED /*void*/ -#else /* NDEBUG */ -#define H5_ATTR_NDEBUG_UNUSED H5_ATTR_UNUSED -#endif /* NDEBUG */ -#define H5_ATTR_NORETURN __attribute__((noreturn)) -#define H5_ATTR_CONST __attribute__((const)) -#define H5_ATTR_PURE __attribute__((pure)) -#if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 7 && !defined(__INTEL_COMPILER) -#define H5_ATTR_FALLTHROUGH __attribute__((fallthrough)); -#else -#define H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ -#endif +# define H5_ATTR_FORMAT(X, Y, Z) __attribute__((format(X, Y, Z))) +# define H5_ATTR_UNUSED __attribute__((unused)) + +# ifdef H5_HAVE_PARALLEL +# define H5_ATTR_PARALLEL_UNUSED __attribute__((unused)) +# define H5_ATTR_PARALLEL_USED /*void*/ +# else +# define H5_ATTR_PARALLEL_UNUSED /*void*/ +# define H5_ATTR_PARALLEL_USED __attribute__((unused)) +# endif + +# ifdef H5_NO_DEPRECATED_SYMBOLS +# define H5_ATTR_DEPRECATED_USED H5_ATTR_UNUSED +# else +# define H5_ATTR_DEPRECATED_USED /*void*/ +# endif + +# ifdef H5_DEBUG_API +# define H5_ATTR_DEBUG_API_USED /*void*/ +# else +# define H5_ATTR_DEBUG_API_USED H5_ATTR_UNUSED +# endif + +# ifndef NDEBUG +# define H5_ATTR_NDEBUG_UNUSED /*void*/ +# else +# define H5_ATTR_NDEBUG_UNUSED H5_ATTR_UNUSED +# endif + +# define H5_ATTR_NORETURN __attribute__((noreturn)) +# define H5_ATTR_CONST __attribute__((const)) +# define H5_ATTR_PURE __attribute__((pure)) + +# if defined(__clang__) || defined(__GNUC__) && __GNUC__ >= 7 && !defined(__INTEL_COMPILER) +# define H5_ATTR_FALLTHROUGH __attribute__((fallthrough)); +# else +# define H5_ATTR_FALLTHROUGH /* FALLTHROUGH */ +# endif + +# if defined(__GNUC__) && !defined(__INTEL_COMPILER) +# define H5_ATTR_MALLOC __attribute__((malloc)) +# else +# define H5_ATTR_MALLOC /*void*/ +# endif + #else -#define H5_ATTR_FORMAT(X, Y, Z) /*void*/ -#define H5_ATTR_UNUSED /*void*/ -#define H5_ATTR_NDEBUG_UNUSED /*void*/ -#define H5_ATTR_DEBUG_API_USED /*void*/ -#define H5_ATTR_DEPRECATED_USED /*void*/ -#define H5_ATTR_PARALLEL_UNUSED /*void*/ -#define H5_ATTR_PARALLEL_USED /*void*/ -#define H5_ATTR_NORETURN /*void*/ -#define H5_ATTR_CONST /*void*/ -#define H5_ATTR_PURE /*void*/ -#define H5_ATTR_FALLTHROUGH /*void*/ +# define H5_ATTR_FORMAT(X, Y, Z) /*void*/ +# define H5_ATTR_UNUSED /*void*/ +# define H5_ATTR_NDEBUG_UNUSED /*void*/ +# define H5_ATTR_DEBUG_API_USED /*void*/ +# define H5_ATTR_DEPRECATED_USED /*void*/ +# define H5_ATTR_PARALLEL_UNUSED /*void*/ +# define H5_ATTR_PARALLEL_USED /*void*/ +# define H5_ATTR_NORETURN /*void*/ +# define H5_ATTR_CONST /*void*/ +# define H5_ATTR_PURE /*void*/ +# define H5_ATTR_FALLTHROUGH /*void*/ +# define H5_ATTR_MALLOC /*void*/ #endif +/* clang-format on */ /* * Networking headers used by the mirror VFD and related tests and utilities. diff --git a/src/H5public.h b/src/H5public.h index 303a133..7fc36f5 100644 --- a/src/H5public.h +++ b/src/H5public.h @@ -75,19 +75,45 @@ * http://www.dbp-consulting.com/tutorials/SuppressingGCCWarnings.html * http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas */ -/* These pragmas are only implemented usefully in gcc 4.6+ */ -#if ((__GNUC__ * 100) + __GNUC_MINOR__) >= 406 #define H5_GCC_DIAG_JOINSTR(x, y) x y #define H5_GCC_DIAG_DO_PRAGMA(x) _Pragma(#x) #define H5_GCC_DIAG_PRAGMA(x) H5_GCC_DIAG_DO_PRAGMA(GCC diagnostic x) -#define H5_GCC_DIAG_OFF(x) H5_GCC_DIAG_PRAGMA(push) H5_GCC_DIAG_PRAGMA(ignored H5_GCC_DIAG_JOINSTR("-W", x)) -#define H5_GCC_DIAG_ON(x) H5_GCC_DIAG_PRAGMA(pop) +#define H5_DIAG_OFF(x) H5_GCC_DIAG_PRAGMA(push) H5_GCC_DIAG_PRAGMA(ignored H5_GCC_DIAG_JOINSTR("-W", x)) +#define H5_DIAG_ON(x) H5_GCC_DIAG_PRAGMA(pop) + +/* Macros for enabling/disabling particular GCC-only warnings. + * These pragmas are only implemented usefully in gcc 4.6+ + */ +#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) +#define H5_GCC_DIAG_OFF(x) H5_DIAG_OFF(x) +#define H5_GCC_DIAG_ON(x) H5_DIAG_ON(x) #else #define H5_GCC_DIAG_OFF(x) #define H5_GCC_DIAG_ON(x) #endif +/* Macros for enabling/disabling particular clang-only warnings. + */ +#if defined(__clang__) +#define H5_CLANG_DIAG_OFF(x) H5_DIAG_OFF(x) +#define H5_CLANG_DIAG_ON(x) H5_DIAG_ON(x) +#else +#define H5_CLANG_DIAG_OFF(x) +#define H5_CLANG_DIAG_ON(x) +#endif + +/* Macros for enabling/disabling particular GCC / clang warnings. + * These macros should be used for warnings supported by both gcc and clang. + */ +#if (((__GNUC__ * 100) + __GNUC_MINOR__) >= 406) || defined(__clang__) +#define H5_GCC_CLANG_DIAG_OFF(x) H5_DIAG_OFF(x) +#define H5_GCC_CLANG_DIAG_ON(x) H5_DIAG_ON(x) +#else +#define H5_GCC_CLANG_DIAG_OFF(x) +#define H5_GCC_CLANG_DIAG_ON(x) +#endif + /* Version numbers */ /** * For major interface/format changes -- cgit v0.12