From bca5bc4ffff48c76a925234cb79b88108a3bcf00 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 15 Jan 2025 14:06:01 -0800 Subject: [PATCH 1/9] toolchain: Add macros to disable compiler warnings These macros allow disabling compiler warnings for all compilers or only gcc or only clang. Signed-off-by: Tom Hughes --- include/zephyr/toolchain.h | 64 +++++++++++++++++++++++++++++++++ include/zephyr/toolchain/gcc.h | 15 ++++++++ include/zephyr/toolchain/llvm.h | 3 ++ 3 files changed, 82 insertions(+) diff --git a/include/zephyr/toolchain.h b/include/zephyr/toolchain.h index f8df4915736c..bc389ae55656 100644 --- a/include/zephyr/toolchain.h +++ b/include/zephyr/toolchain.h @@ -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 diff --git a/include/zephyr/toolchain/gcc.h b/include/zephyr/toolchain/gcc.h index dbff83e8bbda..e003cd2c26f7 100644 --- a/include/zephyr/toolchain/gcc.h +++ b/include/zephyr/toolchain/gcc.h @@ -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_ */ diff --git a/include/zephyr/toolchain/llvm.h b/include/zephyr/toolchain/llvm.h index a89568073051..7eea8347c6cd 100644 --- a/include/zephyr/toolchain/llvm.h +++ b/include/zephyr/toolchain/llvm.h @@ -30,6 +30,9 @@ #include +#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 From a9e39a633ea680327e1731a0660cad5069ddf705 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 10 Feb 2025 11:42:22 -0800 Subject: [PATCH 2/9] net: l2: ethernet: Fix unused function warning Building with clang warns: subsys/net/l2/ethernet/ethernet.c:178:18: error: unused function 'ethernet_check_ipv4_bcast_addr' [-Werror,-Wunused-function] enum net_verdict ethernet_check_ipv4_bcast_addr(struct net_pkt *pkt, ^ ethernet_check_ipv4_bcast_addr is called by ethernet_ip_recv, which only exists when CONFIG_NET_IPV4 or CONFIG_NET_IPV6 is defined. Signed-off-by: Tom Hughes --- subsys/net/l2/ethernet/ethernet.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/subsys/net/l2/ethernet/ethernet.c b/subsys/net/l2/ethernet/ethernet.c index c7fd6d148ff0..c11ca18c4239 100644 --- a/subsys/net/l2/ethernet/ethernet.c +++ b/subsys/net/l2/ethernet/ethernet.c @@ -171,6 +171,7 @@ static inline bool eth_is_vlan_tag_stripped(struct net_if *iface) return (net_eth_get_hw_capabilities(iface) & ETHERNET_HW_VLAN_TAG_STRIP); } +#if defined(CONFIG_NET_IPV4) /* Drop packet if it has broadcast destination MAC address but the IP * address is not multicast or broadcast address. See RFC 1122 ch 3.3.6 */ @@ -191,6 +192,7 @@ enum net_verdict ethernet_check_ipv4_bcast_addr(struct net_pkt *pkt, return NET_OK; } +#endif #if defined(CONFIG_NET_NATIVE_IP) && !defined(CONFIG_NET_RAW_MODE) static void ethernet_mcast_monitor_cb(struct net_if *iface, const struct net_addr *addr, From 66b1e0cfbf8af67e4ce4ab8089b46a7b1e713c33 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 24 Jan 2025 14:53:04 -0800 Subject: [PATCH 3/9] toolchain: Add indirection for compiler warnings In order to support new toolchains that are not compatible with gcc/clang (e.g., IAR), we need to add a level of indirection for the name of warnings. Signed-off-by: Tom Hughes --- include/zephyr/toolchain.h | 232 ++++++++++++++++++++++++++++++++ include/zephyr/toolchain/gcc.h | 25 ++++ include/zephyr/toolchain/llvm.h | 2 + 3 files changed, 259 insertions(+) diff --git a/include/zephyr/toolchain.h b/include/zephyr/toolchain.h index bc389ae55656..f3a03bc833f9 100644 --- a/include/zephyr/toolchain.h +++ b/include/zephyr/toolchain.h @@ -155,6 +155,238 @@ #define TOOLCHAIN_PRAGMA(x) #endif +/** + * @def TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER + * @brief Toolchain-specific warning for taking the address of a packed member. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER +#define TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER +#endif + +/** + * @def TOOLCHAIN_WARNING_ALLOC_SIZE_LARGER_THAN + * @brief Toolchain-specific warning for allocations larger than a given size. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_ALLOC_SIZE_LARGER_THAN +#define TOOLCHAIN_WARNING_ALLOC_SIZE_LARGER_THAN +#endif + +/** + * @def TOOLCHAIN_WARNING_ARRAY_BOUNDS + * @brief Toolchain-specific warning for array bounds violations. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_ARRAY_BOUNDS +#define TOOLCHAIN_WARNING_ARRAY_BOUNDS +#endif + +/** + * @def TOOLCHAIN_WARNING_ATTRIBUTES + * @brief Toolchain-specific warning for unknown attributes. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_ATTRIBUTES +#define TOOLCHAIN_WARNING_ATTRIBUTES +#endif + +/** + * @def TOOLCHAIN_WARNING_DANGLING_POINTER + * @brief Toolchain-specific warning for dangling pointers. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_DANGLING_POINTER +#define TOOLCHAIN_WARNING_DANGLING_POINTER +#endif + +/** + * @def TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR + * @brief Toolchain-specific warning for deleting a pointer to an object + * with a non-virtual destructor. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR +#define TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR +#endif + +/** + * @def TOOLCHAIN_WARNING_EXTRA + * @brief Toolchain-specific warning for extra warnings. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_EXTRA +#define TOOLCHAIN_WARNING_EXTRA +#endif + +/** + * @def TOOLCHAIN_WARNING_FORMAT_TRUNCATION + * @brief Toolchain-specific warning for format truncation. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_FORMAT_TRUNCATION +#define TOOLCHAIN_WARNING_FORMAT_TRUNCATION +#endif + +/** + * @def TOOLCHAIN_WARNING_INFINITE_RECURSION + * @brief Toolchain-specific warning for infinite recursion. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_INFINITE_RECURSION +#define TOOLCHAIN_WARNING_INFINITE_RECURSION +#endif + +/** + * @def TOOLCHAIN_WARNING_INTEGER_OVERFLOW + * @brief Toolchain-specific warning for integer overflow. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_INTEGER_OVERFLOW +#define TOOLCHAIN_WARNING_INTEGER_OVERFLOW +#endif + +/** + * @def TOOLCHAIN_WARNING_NONNULL + * @brief Toolchain-specific warning for null pointer arguments to functions marked with "nonnull". + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_NONNULL +#define TOOLCHAIN_WARNING_NONNULL +#endif + +/** + * @def TOOLCHAIN_WARNING_OVERFLOW + * @brief Toolchain-specific warning for integer overflow. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_OVERFLOW +#define TOOLCHAIN_WARNING_OVERFLOW +#endif + +/** + * @def TOOLCHAIN_WARNING_POINTER_ARITH + * @brief Toolchain-specific warning for pointer arithmetic. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_POINTER_ARITH +#define TOOLCHAIN_WARNING_POINTER_ARITH +#endif + +/** + * @def TOOLCHAIN_WARNING_PRAGMAS + * @brief Toolchain-specific warning for unknown pragmas. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_PRAGMAS +#define TOOLCHAIN_WARNING_PRAGMAS +#endif + +/** + * @def TOOLCHAIN_WARNING_SHADOW + * @brief Toolchain-specific warning for shadow variables. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_SHADOW +#define TOOLCHAIN_WARNING_SHADOW +#endif + +/** + * @def TOOLCHAIN_WARNING_SIZEOF_ARRAY_DECAY + * @brief Toolchain-specific warning for sizeof array decay. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_SIZEOF_ARRAY_DECAY +#define TOOLCHAIN_WARNING_SIZEOF_ARRAY_DECAY +#endif + +/** + * @def TOOLCHAIN_WARNING_STRINGOP_OVERFLOW + * @brief Toolchain-specific warning for stringop overflow. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_STRINGOP_OVERFLOW +#define TOOLCHAIN_WARNING_STRINGOP_OVERFLOW +#endif + +/** + * @def TOOLCHAIN_WARNING_STRINGOP_TRUNCATION + * @brief Toolchain-specific warning for stringop truncation. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_STRINGOP_TRUNCATION +#define TOOLCHAIN_WARNING_STRINGOP_TRUNCATION +#endif + +/** + * @def TOOLCHAIN_WARNING_UNUSED_FUNCTION + * @brief Toolchain-specific warning for unused function. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_UNUSED_FUNCTION +#define TOOLCHAIN_WARNING_UNUSED_FUNCTION +#endif + +/** + * @def TOOLCHAIN_WARNING_UNUSED_LABEL + * @brief Toolchain-specific warning for unused labels. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_UNUSED_LABEL +#define TOOLCHAIN_WARNING_UNUSED_LABEL +#endif + +/** + * @def TOOLCHAIN_WARNING_UNUSED_VARIABLE + * @brief Toolchain-specific warning for unused variables. + * + * Use this as an argument to the @ref TOOLCHAIN_DISABLE_WARNING and + * @ref TOOLCHAIN_ENABLE_WARNING family of macros. + */ +#ifndef TOOLCHAIN_WARNING_UNUSED_VARIABLE +#define TOOLCHAIN_WARNING_UNUSED_VARIABLE +#endif + /** * @def TOOLCHAIN_DISABLE_WARNING * @brief Disable the specified compiler warning for all compilers. diff --git a/include/zephyr/toolchain/gcc.h b/include/zephyr/toolchain/gcc.h index e003cd2c26f7..252bc326fb53 100644 --- a/include/zephyr/toolchain/gcc.h +++ b/include/zephyr/toolchain/gcc.h @@ -688,6 +688,31 @@ do { \ #endif /* !_LINKER */ +#define TOOLCHAIN_WARNING_ADDRESS_OF_PACKED_MEMBER "-Waddress-of-packed-member" +#define TOOLCHAIN_WARNING_ARRAY_BOUNDS "-Warray-bounds" +#define TOOLCHAIN_WARNING_ATTRIBUTES "-Wattributes" +#define TOOLCHAIN_WARNING_DANGLING_POINTER "-Wdangling-pointer" +#define TOOLCHAIN_WARNING_DELETE_NON_VIRTUAL_DTOR "-Wdelete-non-virtual-dtor" +#define TOOLCHAIN_WARNING_EXTRA "-Wextra" +#define TOOLCHAIN_WARNING_FORMAT_TRUNCATION "-Wformat-truncation" +#define TOOLCHAIN_WARNING_INFINITE_RECURSION "-Winfinite-recursion" +#define TOOLCHAIN_WARNING_INTEGER_OVERFLOW "-Winteger-overflow" +#define TOOLCHAIN_WARNING_NONNULL "-Wnonnull" +#define TOOLCHAIN_WARNING_OVERFLOW "-Woverflow" +#define TOOLCHAIN_WARNING_PRAGMAS "-Wpragmas" +#define TOOLCHAIN_WARNING_SHADOW "-Wshadow" +#define TOOLCHAIN_WARNING_UNUSED_FUNCTION "-Wunused-function" +#define TOOLCHAIN_WARNING_UNUSED_LABEL "-Wunused-label" +#define TOOLCHAIN_WARNING_UNUSED_VARIABLE "-Wunused-variable" + +/* GCC-specific warnings that aren't in clang. */ +#if defined(__GNUC__) && !defined(__clang__) +#define TOOLCHAIN_WARNING_ALLOC_SIZE_LARGER_THAN "-Walloc-size-larger-than=" +#define TOOLCHAIN_WARNING_POINTER_ARITH "-Wpointer-arith" +#define TOOLCHAIN_WARNING_STRINGOP_OVERFLOW "-Wstringop-overflow" +#define TOOLCHAIN_WARNING_STRINGOP_TRUNCATION "-Wstringop-truncation" +#endif + #define _TOOLCHAIN_DISABLE_WARNING(compiler, warning) \ TOOLCHAIN_PRAGMA(compiler diagnostic push) \ TOOLCHAIN_PRAGMA(compiler diagnostic ignored warning) diff --git a/include/zephyr/toolchain/llvm.h b/include/zephyr/toolchain/llvm.h index 7eea8347c6cd..cc131246d0a8 100644 --- a/include/zephyr/toolchain/llvm.h +++ b/include/zephyr/toolchain/llvm.h @@ -30,6 +30,8 @@ #include +#define TOOLCHAIN_WARNING_SIZEOF_ARRAY_DECAY "-Wsizeof-array-decay" + #define TOOLCHAIN_DISABLE_CLANG_WARNING(warning) _TOOLCHAIN_DISABLE_WARNING(clang, warning) #define TOOLCHAIN_ENABLE_CLANG_WARNING(warning) _TOOLCHAIN_ENABLE_WARNING(clang, warning) From aeaeab63ecbdd17aaac3940d1013d6d32fd50b97 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 10 Jan 2025 09:45:41 -0800 Subject: [PATCH 4/9] drivers: sensor: Remove unused function Building with clang warns: drivers/sensor/st/ism330dhcx/ism330dhcx.c:107:19: error: unused function 'ism330dhcx_reboot' [-Werror,-Wunused-function] static inline int ism330dhcx_reboot(const struct device *dev) Signed-off-by: Tom Hughes --- drivers/sensor/st/ism330dhcx/ism330dhcx.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/drivers/sensor/st/ism330dhcx/ism330dhcx.c b/drivers/sensor/st/ism330dhcx/ism330dhcx.c index da1cef97a047..44b8506664e6 100644 --- a/drivers/sensor/st/ism330dhcx/ism330dhcx.c +++ b/drivers/sensor/st/ism330dhcx/ism330dhcx.c @@ -104,20 +104,6 @@ static int ism330dhcx_gyro_range_to_fs_val(int32_t range) return -EINVAL; } -static inline int ism330dhcx_reboot(const struct device *dev) -{ - struct ism330dhcx_data *data = dev->data; - - if (ism330dhcx_boot_set(data->ctx, 1) < 0) { - return -EIO; - } - - /* Wait sensor turn-on time as per datasheet */ - k_busy_wait(35 * USEC_PER_MSEC); - - return 0; -} - static int ism330dhcx_accel_set_fs_raw(const struct device *dev, uint8_t fs) { struct ism330dhcx_data *data = dev->data; From 1bbce53b03316d565c48be6511a47ca38499fe98 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 10 Jan 2025 10:01:52 -0800 Subject: [PATCH 5/9] drivers: dma: Remove unused function Building with clang warns: drivers/dma/dma_emul.c:73:20: error: unused function 'dma_emul_xfer_is_error_status' [-Werror,-Wunused-function] static inline bool dma_emul_xfer_is_error_status(int status) ^ Signed-off-by: Tom Hughes --- drivers/dma/dma_emul.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/drivers/dma/dma_emul.c b/drivers/dma/dma_emul.c index bdb5245ae464..6320d1c1620b 100644 --- a/drivers/dma/dma_emul.c +++ b/drivers/dma/dma_emul.c @@ -70,11 +70,6 @@ static void dma_emul_work_handler(struct k_work *work); LOG_MODULE_REGISTER(dma_emul, CONFIG_DMA_LOG_LEVEL); -static inline bool dma_emul_xfer_is_error_status(int status) -{ - return status < 0; -} - static inline const char *const dma_emul_channel_state_to_string(enum dma_emul_channel_state state) { switch (state) { From fb229a26bbc3b767177cbd9f7e5f441083c3366b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 10 Jan 2025 09:56:40 -0800 Subject: [PATCH 6/9] drivers: gpio: pca95xx: Remove unused functions Building with clang warns: drivers/gpio/gpio_pca95xx.c:256:19: error: unused function 'update_input_reg' [-Werror,-Wunused-function] static inline int update_input_reg(const struct device *dev, uint8_t pin, ^ drivers/gpio/gpio_pca95xx.c:120:12: error: unused function 'read_port_reg' [-Werror,-Wunused-function] static int read_port_reg(const struct device *dev, uint8_t reg, ^ uint8_t pin, Signed-off-by: Tom Hughes --- drivers/gpio/gpio_pca95xx.c | 42 ------------------------------------- 1 file changed, 42 deletions(-) diff --git a/drivers/gpio/gpio_pca95xx.c b/drivers/gpio/gpio_pca95xx.c index 662a92465f3b..c08094c8bb7a 100644 --- a/drivers/gpio/gpio_pca95xx.c +++ b/drivers/gpio/gpio_pca95xx.c @@ -117,38 +117,6 @@ struct gpio_pca95xx_drv_data { #endif }; -static int read_port_reg(const struct device *dev, uint8_t reg, uint8_t pin, - uint16_t *cache, uint16_t *buf) -{ - const struct gpio_pca95xx_config * const config = dev->config; - uint8_t b_buf; - int ret; - - if (pin >= 8) { - reg++; - } - - ret = i2c_reg_read_byte_dt(&config->bus, reg, &b_buf); - if (ret != 0) { - LOG_ERR("PCA95XX[0x%X]: error reading register 0x%X (%d)", - config->bus.addr, reg, ret); - return ret; - } - - if (pin < 8) { - ((uint8_t *)cache)[LOW_BYTE_LE16_IDX] = b_buf; - } else { - ((uint8_t *)cache)[HIGH_BYTE_LE16_IDX] = b_buf; - } - - *buf = *cache; - - LOG_DBG("PCA95XX[0x%X]: Read: REG[0x%X] = 0x%X", - config->bus.addr, reg, b_buf); - - return 0; -} - /** * @brief Read both port 0 and port 1 registers of certain register function. * @@ -253,16 +221,6 @@ static int write_port_regs(const struct device *dev, uint8_t reg, return ret; } -static inline int update_input_reg(const struct device *dev, uint8_t pin, - uint16_t *buf) -{ - struct gpio_pca95xx_drv_data * const drv_data = - (struct gpio_pca95xx_drv_data * const)dev->data; - - return read_port_reg(dev, REG_INPUT_PORT0, pin, - &drv_data->reg_cache.input, buf); -} - static inline int update_input_regs(const struct device *dev, uint16_t *buf) { struct gpio_pca95xx_drv_data * const drv_data = From e8ce13738165fc247736f7ed63dbd35113a25556 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 16 Jan 2025 17:17:18 -0800 Subject: [PATCH 7/9] tests: usb: bos: Disable erroneous warning from clang tests/subsys/usb/bos/src/test_bos.c:24:22: error: variable 'dummy_descriptor' is not needed and will not be emitted [-Werror,-Wunneeded-internal-declaration] static const uint8_t dummy_descriptor[] = { ^ Signed-off-by: Tom Hughes --- tests/subsys/usb/bos/src/test_bos.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/subsys/usb/bos/src/test_bos.c b/tests/subsys/usb/bos/src/test_bos.c index e9452d86fc30..9ffba9cd5657 100644 --- a/tests/subsys/usb/bos/src/test_bos.c +++ b/tests/subsys/usb/bos/src/test_bos.c @@ -21,9 +21,12 @@ LOG_MODULE_REGISTER(test_main, LOG_LEVEL_DBG); * Compare old style USB BOS definition with section aligned */ +/* Disable erroneous warning: https://github.com/llvm/llvm-project/issues/25458. */ +TOOLCHAIN_DISABLE_CLANG_WARNING("-Wunneeded-internal-declaration") static const uint8_t dummy_descriptor[] = { 0x00, 0x01, 0x02 }; +TOOLCHAIN_ENABLE_CLANG_WARNING("-Wunneeded-internal-declaration") static struct webusb_bos_desc { struct usb_bos_descriptor bos; From 44dad4837555ea734e6e426618bc106396e5f1ee Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 10 Jan 2025 10:07:19 -0800 Subject: [PATCH 8/9] test: posix: timers: Fix unused function warning Building with clang warns: tests/posix/timers/src/clock.c:37:20: error: unused function 'tv_to_ts' [-Werror,-Wunused-function] static inline void tv_to_ts(const struct timeval *tv, struct timespec *ts) ^ tests/posix/timers/src/clock.c:51:16: error: unused function 'tp_eq' [-Werror,-Wunused-function] _decl_op(bool, tp_eq, ==); /* a == b */ ^ tests/posix/timers/src/clock.c:52:16: error: unused function 'tp_lt' [-Werror,-Wunused-function] _decl_op(bool, tp_lt, <); /* a < b */ ^ tests/posix/timers/src/clock.c:53:16: error: unused function 'tp_gt' [-Werror,-Wunused-function] _decl_op(bool, tp_gt, >); /* a > b */ ^ tests/posix/timers/src/clock.c:54:16: error: unused function 'tp_le' [-Werror,-Wunused-function] _decl_op(bool, tp_le, <=); /* a <= b */ tests/posix/timers/src/clock.c:59:20: error: unused function 'tp_diff_in_range_ns' [-Werror,-Wunused-function] static inline bool tp_diff_in_range_ns(const struct timespec *a, ^ const struct timespec *b, tests/posix/timers/src/clock.c:49:20: error: unused function 'tp_diff_in_range_ns' [-Werror,-Wunused-function] static inline bool tp_diff_in_range_ns(const struct timespec *a, ^ const struct timespec *b, Signed-off-by: Tom Hughes --- tests/posix/timers/src/clock.c | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/tests/posix/timers/src/clock.c b/tests/posix/timers/src/clock.c index 4b9665fc7973..cc30fee8cadc 100644 --- a/tests/posix/timers/src/clock.c +++ b/tests/posix/timers/src/clock.c @@ -34,12 +34,6 @@ static inline int64_t ts_to_ns(const struct timespec *ts) return ts->tv_sec * NSEC_PER_SEC + ts->tv_nsec; } -static inline void tv_to_ts(const struct timeval *tv, struct timespec *ts) -{ - ts->tv_sec = tv->tv_sec; - ts->tv_nsec = tv->tv_usec * NSEC_PER_USEC; -} - #define _tp_op(_a, _b, _op) (ts_to_ns(_a) _op ts_to_ns(_b)) #define _decl_op(_type, _name, _op) \ @@ -48,22 +42,9 @@ static inline void tv_to_ts(const struct timeval *tv, struct timespec *ts) return _tp_op(_a, _b, _op); \ } -_decl_op(bool, tp_eq, ==); /* a == b */ -_decl_op(bool, tp_lt, <); /* a < b */ -_decl_op(bool, tp_gt, >); /* a > b */ -_decl_op(bool, tp_le, <=); /* a <= b */ _decl_op(bool, tp_ge, >=); /* a >= b */ _decl_op(int64_t, tp_diff, -); /* a - b */ -/* lo <= (a - b) < hi */ -static inline bool tp_diff_in_range_ns(const struct timespec *a, const struct timespec *b, - int64_t lo, int64_t hi) -{ - int64_t diff = tp_diff(a, b); - - return diff >= lo && diff < hi; -} - ZTEST(posix_timers, test_clock_gettime) { struct timespec ts; From d5304415b7a1ca052ca09543d62608cd1c41552b Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 9 Jan 2025 16:13:12 -0800 Subject: [PATCH 9/9] cmake clang/compiler_flags.cmake: Re-enable Wunused-function for clang All warnings in the code base have been resolved. Signed-off-by: Tom Hughes --- cmake/compiler/clang/compiler_flags.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/cmake/compiler/clang/compiler_flags.cmake b/cmake/compiler/clang/compiler_flags.cmake index 8715150e5a6f..c6636d4d38ea 100644 --- a/cmake/compiler/clang/compiler_flags.cmake +++ b/cmake/compiler/clang/compiler_flags.cmake @@ -104,7 +104,6 @@ check_set_compiler_property(PROPERTY warning_extended -Wno-sometimes-uninitialized -Wno-self-assign -Wno-address-of-packed-member - -Wno-unused-function -Wno-initializer-overrides -Wno-section -Wno-unused-variable