Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toolchain: Add macros to disable compiler warnings #84063

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions include/zephyr/toolchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,70 @@
#define TOOLCHAIN_IGNORE_WSHADOW_END
#endif

/**
* @def TOOLCHAIN_PRAGMA
* @brief Helper for using pragma in macros.
*/
#ifdef TOOLCHAIN_HAS_PRAGMA_DIAG
#define TOOLCHAIN_PRAGMA(x) _Pragma(#x)
#else
#define TOOLCHAIN_PRAGMA(x)
#endif

/**
* @def TOOLCHAIN_DISABLE_WARNING
* @brief Disable the specified compiler warning for all compilers.
*/
#ifndef TOOLCHAIN_DISABLE_WARNING
#define TOOLCHAIN_DISABLE_WARNING(warning)
#endif

/**
* @def TOOLCHAIN_ENABLE_WARNING
* @brief Re-enable the specified compiler warning for all compilers.
*
* Can only be used after a call to @ref TOOLCHAIN_DISABLE_WARNING.
*/
#ifndef TOOLCHAIN_ENABLE_WARNING
#define TOOLCHAIN_ENABLE_WARNING(warning)
#endif

/**
* @def TOOLCHAIN_DISABLE_CLANG_WARNING
* @brief Disable the specified compiler warning for clang.
*/
#ifndef TOOLCHAIN_DISABLE_CLANG_WARNING
#define TOOLCHAIN_DISABLE_CLANG_WARNING(warning)
#endif

/**
* @def TOOLCHAIN_ENABLE_CLANG_WARNING
* @brief Re-enable the specified compiler warning for clang.
*
* Can only be used after a call to @ref TOOLCHAIN_DISABLE_CLANG_WARNING.
*/
#ifndef TOOLCHAIN_ENABLE_CLANG_WARNING
#define TOOLCHAIN_ENABLE_CLANG_WARNING(warning)
#endif

/**
* @def TOOLCHAIN_DISABLE_GCC_WARNING
* @brief Disable the specified compiler warning for gcc.
*/
#ifndef TOOLCHAIN_DISABLE_GCC_WARNING
#define TOOLCHAIN_DISABLE_GCC_WARNING(warning)
#endif

/**
* @def TOOLCHAIN_ENABLE_GCC_WARNING
* @brief Re-enable the specified compiler warning for gcc.
*
* Can only be used after a call to @ref TOOLCHAIN_DISABLE_GCC_WARNING.
*/
#ifndef TOOLCHAIN_ENABLE_GCC_WARNING
#define TOOLCHAIN_ENABLE_GCC_WARNING(warning)
#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
Expand Down
15 changes: 15 additions & 0 deletions include/zephyr/toolchain/gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,19 @@ do { \
_Pragma("GCC diagnostic pop")

#endif /* !_LINKER */

#define _TOOLCHAIN_DISABLE_WARNING(compiler, warning) \
TOOLCHAIN_PRAGMA(compiler diagnostic push) \
TOOLCHAIN_PRAGMA(compiler diagnostic ignored warning)

#define _TOOLCHAIN_ENABLE_WARNING(compiler, warning) TOOLCHAIN_PRAGMA(compiler diagnostic pop)

#define TOOLCHAIN_DISABLE_WARNING(warning) _TOOLCHAIN_DISABLE_WARNING(GCC, warning)
#define TOOLCHAIN_ENABLE_WARNING(warning) _TOOLCHAIN_ENABLE_WARNING(GCC, warning)

#if defined(__GNUC__) && !defined(__clang__)
#define TOOLCHAIN_DISABLE_GCC_WARNING(warning) _TOOLCHAIN_DISABLE_WARNING(GCC, warning)
#define TOOLCHAIN_ENABLE_GCC_WARNING(warning) _TOOLCHAIN_ENABLE_WARNING(GCC, warning)
#endif

#endif /* ZEPHYR_INCLUDE_TOOLCHAIN_GCC_H_ */
3 changes: 3 additions & 0 deletions include/zephyr/toolchain/llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

#include <zephyr/toolchain/gcc.h>

#define TOOLCHAIN_DISABLE_CLANG_WARNING(warning) _TOOLCHAIN_DISABLE_WARNING(clang, warning)
#define TOOLCHAIN_ENABLE_CLANG_WARNING(warning) _TOOLCHAIN_ENABLE_WARNING(clang, warning)

/*
* Provide these definitions only when minimal libc is used.
* Avoid collision with defines from include/zephyr/toolchain/zephyr_stdint.h
Expand Down
Loading