diff --git a/include/zephyr/logging/log_msg.h b/include/zephyr/logging/log_msg.h index 038ce9c894..f49fab7cdf 100644 --- a/include/zephyr/logging/log_msg.h +++ b/include/zephyr/logging/log_msg.h @@ -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) { \ diff --git a/include/zephyr/toolchain.h b/include/zephyr/toolchain.h index e88111d957..e46c19689d 100644 --- a/include/zephyr/toolchain.h +++ b/include/zephyr/toolchain.h @@ -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 diff --git a/include/zephyr/toolchain/gcc.h b/include/zephyr/toolchain/gcc.h index f81cb0a309..8f313b14a2 100644 --- a/include/zephyr/toolchain/gcc.h +++ b/include/zephyr/toolchain/gcc.h @@ -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_ */