Commit 8dc9d89d authored by Daniel Leung's avatar Daniel Leung Committed by Fabio Baltieri
Browse files

toolchain: introduce macros to ignore -Wshadow



This introduces two macros TOOLCHAIN_IGNORE_WSHADOW_BEGIN and
TOOLCHAIN_IGNORE_WSHADOW_END which can be used inside another
macro to ignore -Wshadow for certain block of code. This is
useful for common macros that may nest upon themselves
(for example, logging).

Signed-off-by: default avatarDaniel Leung <daniel.leung@intel.com>
parent ca6adf13
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -235,7 +235,9 @@ do { \
		CBPRINTF_STATIC_PACKAGE(NULL, 0, _plen, Z_LOG_MSG_ALIGN_OFFSET, _options, \
					__VA_ARGS__); \
	} \
	TOOLCHAIN_IGNORE_WSHADOW_BEGIN \
	struct log_msg *_msg; \
	TOOLCHAIN_IGNORE_WSHADOW_END \
	Z_LOG_MSG_ON_STACK_ALLOC(_msg, Z_LOG_MSG_LEN(_plen, 0)); \
	Z_LOG_ARM64_VLA_PROTECT(); \
	if (_plen != 0) { \
+22 −0
Original line number Diff line number Diff line
@@ -115,6 +115,28 @@
#define TOOLCHAIN_HAS_C_AUTO_TYPE 0
#endif

/**
 * @def TOOLCHAIN_IGNORE_WSHADOW_BEGIN
 * @brief Begin of block to ignore -Wshadow.
 *
 * To be used inside another macro.
 * Only for toolchain supporting _Pragma("GCC diagnostic ...").
 */
#ifndef TOOLCHAIN_IGNORE_WSHADOW_BEGIN
#define TOOLCHAIN_IGNORE_WSHADOW_BEGIN
#endif

/**
 * @def TOOLCHAIN_IGNORE_WSHADOW_END
 * @brief End of block to ignore -Wshadow.
 *
 * To be used inside another macro.
 * Only for toolchain supporting _Pragma("GCC diagnostic ...").
 */
#ifndef TOOLCHAIN_IGNORE_WSHADOW_END
#define TOOLCHAIN_IGNORE_WSHADOW_END
#endif

/*
 * Ensure that __BYTE_ORDER__ and related preprocessor definitions are defined,
 * and that they match the Kconfig option that is used in the code itself to
+7 −0
Original line number Diff line number Diff line
@@ -639,5 +639,12 @@ do { \
#define FUNC_NO_STACK_PROTECTOR
#endif

#define TOOLCHAIN_IGNORE_WSHADOW_BEGIN \
	_Pragma("GCC diagnostic push") \
	_Pragma("GCC diagnostic ignored \"-Wshadow\"")

#define TOOLCHAIN_IGNORE_WSHADOW_END \
	_Pragma("GCC diagnostic pop")

#endif /* !_LINKER */
#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ */