diff mbox series

[1/7] lib: fwts: Add abstracted pragma macros to push/pop state and disable warnings

Message ID 20180730183059.28039-2-colin.king@canonical.com
State Accepted
Headers show
Series [1/7] lib: fwts: Add abstracted pragma macros to push/pop state and disable warnings | expand

Commit Message

Colin Ian King July 30, 2018, 6:30 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Add full version number checking macros for gcc and clang versions
and add macros to abstract the different ways to push/pop warning
state and disable specific warnings pramas. These pragmas macros are
no-ops for compilers other than gcc and clang.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/include/fwts.h | 64 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

Comments

Alex Hung July 31, 2018, 12:11 a.m. UTC | #1
On 2018-07-30 11:30 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Add full version number checking macros for gcc and clang versions
> and add macros to abstract the different ways to push/pop warning
> state and disable specific warnings pramas. These pragmas macros are
> no-ops for compilers other than gcc and clang.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/include/fwts.h | 64 ++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 64 insertions(+)
> 
> diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h
> index 1b6391c4..a9115da7 100644
> --- a/src/lib/include/fwts.h
> +++ b/src/lib/include/fwts.h
> @@ -23,6 +23,70 @@
>   
>   #include "config.h"
>   
> +/*
> + *  convert version to a large integer for easier comparison
> + */
> +#define _VER_(major, minor, patchlevel)			\
> +	((major * 10000) + (minor * 100) + patchlevel)
> +
> +/*
> + *  NEED_GLIBC is true if GLIBC version is greater than version needed
> + */
> +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
> +#define NEED_GLIBC(major, minor, patchlevel) 			\
> +	_VER_(major, minor, patchlevel) <= _VER_(__GLIBC__, __GLIBC_MINOR__, 0)
> +#else
> +#define NEED_GLIBC(major, minor, patchlevel) 	(0)
> +#endif
> +
> +#if defined(__GNUC__) && defined(__GNUC_MINOR__)
> +#if defined(__GNUC_PATCHLEVEL__)
> +#define NEED_GNUC(major, minor, patchlevel) 			\
> +	_VER_(major, minor, patchlevel) <= _VER_(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
> +#else
> +#define NEED_GNUC(major, minor, patchlevel) 			\
> +	_VER_(major, minor, patchlevel) <= _VER_(__GNUC__, __GNUC_MINOR__, 0)
> +#endif
> +#else
> +#define NEED_GNUC(major, minor, patchlevel) 	(0)
> +#endif
> +
> +/*
> + *  NEED_CLANG is true if CLANG version is greater than version needed
> + */
> +#if defined(__clang__) && defined(__clang_major__) && \
> +    defined(__clang_minor__) && defined(__clang_patchlevel__)
> +#define NEED_CLANG(major, minor, patchlevel)	\
> +	_VER_(major, minor, patchlevel) <= _VER_(__clang_major__, __clang_minor__, __clang_patchlevel__)
> +#else
> +#define NEED_CLANG(major, minor, patchlevel)	(0)
> +#endif
> +
> +/*
> + *  Wrappers to pragmas to push/pop warning state and disable struct
> + *  packing macro warnings
> + */
> +#if defined(__clang__) && NEED_CLANG(6, 0, 0)
> +#define PRAGMA_PUSH	_Pragma("GCC diagnostic push")
> +#define PRAGMA_POP	_Pragma("GCC diagnostic pop")
> +#define PRAGMA_PACK_WARN_OFF \
> +			_Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"")
> +#define PRAGMA_NULL_PTR_MATH \
> +			_Pragma("GCC diagnostic ignored \"-Wnull-pointer-arithmetic\"")
> +#elif defined(__GNUC__) && NEED_GNUC(8, 0, 0)
> +#define PRAGMA_PUSH	_Pragma("GCC diagnostic push")
> +#define PRAGMA_POP	_Pragma("GCC diagnostic pop")
> +#define PRAGMA_PACK_WARN_OFF \
> +			_Pragma("GCC diagnostic ignored \"-Wpacked-not-aligned\"")
> +#define PRAGMA_NULL_PTR_MATH
> +#else
> +#define PRAGMA_PUSH
> +#define PRAGMA_POP
> +#define PRAGMA_PACK_WARN_OFF
> +#define PRAGMA_NULL_PTR_MATH
> +#endif
> +
> +
>   #if defined(__x86_64__) || defined(__x86_64) || defined(__i386__) || defined(__i386)
>   #define FWTS_ARCH_INTEL	1
>   #define FWTS_HAS_ACPI	1
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu July 31, 2018, 7:48 a.m. UTC | #2
On 07/31/2018 02:30 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Add full version number checking macros for gcc and clang versions
> and add macros to abstract the different ways to push/pop warning
> state and disable specific warnings pramas. These pragmas macros are
> no-ops for compilers other than gcc and clang.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts.h | 64 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 64 insertions(+)
>
> diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h
> index 1b6391c4..a9115da7 100644
> --- a/src/lib/include/fwts.h
> +++ b/src/lib/include/fwts.h
> @@ -23,6 +23,70 @@
>  
>  #include "config.h"
>  
> +/*
> + *  convert version to a large integer for easier comparison
> + */
> +#define _VER_(major, minor, patchlevel)			\
> +	((major * 10000) + (minor * 100) + patchlevel)
> +
> +/*
> + *  NEED_GLIBC is true if GLIBC version is greater than version needed
> + */
> +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
> +#define NEED_GLIBC(major, minor, patchlevel) 			\
> +	_VER_(major, minor, patchlevel) <= _VER_(__GLIBC__, __GLIBC_MINOR__, 0)
> +#else
> +#define NEED_GLIBC(major, minor, patchlevel) 	(0)
> +#endif
> +
> +#if defined(__GNUC__) && defined(__GNUC_MINOR__)
> +#if defined(__GNUC_PATCHLEVEL__)
> +#define NEED_GNUC(major, minor, patchlevel) 			\
> +	_VER_(major, minor, patchlevel) <= _VER_(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
> +#else
> +#define NEED_GNUC(major, minor, patchlevel) 			\
> +	_VER_(major, minor, patchlevel) <= _VER_(__GNUC__, __GNUC_MINOR__, 0)
> +#endif
> +#else
> +#define NEED_GNUC(major, minor, patchlevel) 	(0)
> +#endif
> +
> +/*
> + *  NEED_CLANG is true if CLANG version is greater than version needed
> + */
> +#if defined(__clang__) && defined(__clang_major__) && \
> +    defined(__clang_minor__) && defined(__clang_patchlevel__)
> +#define NEED_CLANG(major, minor, patchlevel)	\
> +	_VER_(major, minor, patchlevel) <= _VER_(__clang_major__, __clang_minor__, __clang_patchlevel__)
> +#else
> +#define NEED_CLANG(major, minor, patchlevel)	(0)
> +#endif
> +
> +/*
> + *  Wrappers to pragmas to push/pop warning state and disable struct
> + *  packing macro warnings
> + */
> +#if defined(__clang__) && NEED_CLANG(6, 0, 0)
> +#define PRAGMA_PUSH	_Pragma("GCC diagnostic push")
> +#define PRAGMA_POP	_Pragma("GCC diagnostic pop")
> +#define PRAGMA_PACK_WARN_OFF \
> +			_Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"")
> +#define PRAGMA_NULL_PTR_MATH \
> +			_Pragma("GCC diagnostic ignored \"-Wnull-pointer-arithmetic\"")
> +#elif defined(__GNUC__) && NEED_GNUC(8, 0, 0)
> +#define PRAGMA_PUSH	_Pragma("GCC diagnostic push")
> +#define PRAGMA_POP	_Pragma("GCC diagnostic pop")
> +#define PRAGMA_PACK_WARN_OFF \
> +			_Pragma("GCC diagnostic ignored \"-Wpacked-not-aligned\"")
> +#define PRAGMA_NULL_PTR_MATH
> +#else
> +#define PRAGMA_PUSH
> +#define PRAGMA_POP
> +#define PRAGMA_PACK_WARN_OFF
> +#define PRAGMA_NULL_PTR_MATH
> +#endif
> +
> +
>  #if defined(__x86_64__) || defined(__x86_64) || defined(__i386__) || defined(__i386)
>  #define FWTS_ARCH_INTEL	1
>  #define FWTS_HAS_ACPI	1
Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/include/fwts.h b/src/lib/include/fwts.h
index 1b6391c4..a9115da7 100644
--- a/src/lib/include/fwts.h
+++ b/src/lib/include/fwts.h
@@ -23,6 +23,70 @@ 
 
 #include "config.h"
 
+/*
+ *  convert version to a large integer for easier comparison
+ */
+#define _VER_(major, minor, patchlevel)			\
+	((major * 10000) + (minor * 100) + patchlevel)
+
+/*
+ *  NEED_GLIBC is true if GLIBC version is greater than version needed
+ */
+#if defined(__GLIBC__) && defined(__GLIBC_MINOR__)
+#define NEED_GLIBC(major, minor, patchlevel) 			\
+	_VER_(major, minor, patchlevel) <= _VER_(__GLIBC__, __GLIBC_MINOR__, 0)
+#else
+#define NEED_GLIBC(major, minor, patchlevel) 	(0)
+#endif
+
+#if defined(__GNUC__) && defined(__GNUC_MINOR__)
+#if defined(__GNUC_PATCHLEVEL__)
+#define NEED_GNUC(major, minor, patchlevel) 			\
+	_VER_(major, minor, patchlevel) <= _VER_(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
+#else
+#define NEED_GNUC(major, minor, patchlevel) 			\
+	_VER_(major, minor, patchlevel) <= _VER_(__GNUC__, __GNUC_MINOR__, 0)
+#endif
+#else
+#define NEED_GNUC(major, minor, patchlevel) 	(0)
+#endif
+
+/*
+ *  NEED_CLANG is true if CLANG version is greater than version needed
+ */
+#if defined(__clang__) && defined(__clang_major__) && \
+    defined(__clang_minor__) && defined(__clang_patchlevel__)
+#define NEED_CLANG(major, minor, patchlevel)	\
+	_VER_(major, minor, patchlevel) <= _VER_(__clang_major__, __clang_minor__, __clang_patchlevel__)
+#else
+#define NEED_CLANG(major, minor, patchlevel)	(0)
+#endif
+
+/*
+ *  Wrappers to pragmas to push/pop warning state and disable struct
+ *  packing macro warnings
+ */
+#if defined(__clang__) && NEED_CLANG(6, 0, 0)
+#define PRAGMA_PUSH	_Pragma("GCC diagnostic push")
+#define PRAGMA_POP	_Pragma("GCC diagnostic pop")
+#define PRAGMA_PACK_WARN_OFF \
+			_Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"")
+#define PRAGMA_NULL_PTR_MATH \
+			_Pragma("GCC diagnostic ignored \"-Wnull-pointer-arithmetic\"")
+#elif defined(__GNUC__) && NEED_GNUC(8, 0, 0)
+#define PRAGMA_PUSH	_Pragma("GCC diagnostic push")
+#define PRAGMA_POP	_Pragma("GCC diagnostic pop")
+#define PRAGMA_PACK_WARN_OFF \
+			_Pragma("GCC diagnostic ignored \"-Wpacked-not-aligned\"")
+#define PRAGMA_NULL_PTR_MATH
+#else
+#define PRAGMA_PUSH
+#define PRAGMA_POP
+#define PRAGMA_PACK_WARN_OFF
+#define PRAGMA_NULL_PTR_MATH
+#endif
+
+
 #if defined(__x86_64__) || defined(__x86_64) || defined(__i386__) || defined(__i386)
 #define FWTS_ARCH_INTEL	1
 #define FWTS_HAS_ACPI	1