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

Re-enable -Wunused-function for clang #83830

Draft
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

thughes
Copy link
Contributor

@thughes thughes commented Jan 10, 2025

Re-enable the -Wunused-function warning when building with clang. Unlike gcc, clang generates warnings before optimizations, so it catches more.

Depends on #84063

@thughes thughes force-pushed the fix-unused-function-warnings branch 3 times, most recently from a394858 to 758302f Compare January 17, 2025 19:50
@thughes thughes changed the title Fix unused function warnings Re-enable -Wunused-function for clang Jan 17, 2025
@thughes thughes force-pushed the fix-unused-function-warnings branch from 758302f to f35aa62 Compare January 25, 2025 00:36
These macros allow disabling compiler warnings for all compilers or only
gcc or only clang.

Signed-off-by: Tom Hughes <[email protected]>
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 <[email protected]>
@thughes thughes force-pushed the fix-unused-function-warnings branch from f35aa62 to a86cec3 Compare February 7, 2025 18:49
Building with clang warns:

subsys/net/ip/ipv6_nbr.c:137:31: error: unused function
'get_nbr_from_data' [-Werror,-Wunused-function]
static inline struct net_nbr *get_nbr_from_data(struct net_ipv6_nbr_data
                              ^                 *data)

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

subsys/net/lib/coap/coap_link_format.c:39:20: error: unused function
'append_be16' [-Werror,-Wunused-function]
static inline bool append_be16(struct coap_packet *cpkt, uint16_t data)

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

subsys/net/lib/http/http_hpack.c:21:20: error: unused function
'http_hpack_key_is_dynamic' [-Werror,-Wunused-function]
static inline bool http_hpack_key_is_dynamic(uint32_t key)
                   ^

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

subsys/net/ip/utils.c:600:24: error: unused function 'pkt_calc_chksum'
[-Werror,-Wunused-function]
static inline uint16_t pkt_calc_chksum(struct net_pkt *pkt, uint16_t sum)
                       ^

pkt_calc_chksum is called by net_calc_chksum, which only exists when
CONFIG_NET_NATIVE_IP is defined.

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

drivers/modem/modem_cmd_handler.c:102:31: error: unused function
'read_rx_allocator' [-Werror,-Wunused-function]
static inline struct net_buf *read_rx_allocator(k_timeout_t timeout,
                              ^

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

drivers/sensor/st/iis2iclx/iis2iclx.c:68:19: error: unused function
'iis2iclx_reboot' [-Werror,-Wunused-function]
static inline int iis2iclx_reboot(const struct device *dev)
                  ^

Signed-off-by: Tom Hughes <[email protected]>
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 <[email protected]>
Building with clang warns:

drivers/sensor/st/lsm9ds0_mfd/lsm9ds0_mfd.c:42:19: error: unused
function 'lsm9ds0_mfd_accel_set_odr_raw' [-Werror,-Wunused-function]
static inline int lsm9ds0_mfd_accel_set_odr_raw(const struct device *dev,
                  ^

lsm9ds0_mfd_accel_set_odr_raw is only used by code that was guarded by
defined(CONFIG_LSM9DS0_MFD_ACCEL_SAMPLING_RATE_RUNTIME) in addition to
!defined(LSM9DS0_MFD_ACCEL_DISABLED).

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

drivers/sensor/st/lsm6dso/lsm6dso.c:89:19: error: unused function
'lsm6dso_reboot' [-Werror,-Wunused-function]
static inline int lsm6dso_reboot(const struct device *dev)
                  ^

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

drivers/sensor/st/lsm6dso16is/lsm6dso16is.c:83:19: error: unused
function 'lsm6dso16is_reboot' [-Werror,-Wunused-function]
static inline int lsm6dso16is_reboot(const struct device *dev)
                  ^

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

drivers/flash/spi_nor.c:306:20: error: unused function
'delay_until_exit_dpd_ok' [-Werror,-Wunused-function]
static inline void delay_until_exit_dpd_ok(const struct device *const dev)
                   ^

delay_until_exit_dpd_ok is only used when ANY_INST_HAS_DPD is defined.

Signed-off-by: Tom Hughes <[email protected]>
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 <[email protected]>
Building with clang warns:

tests/net/udp/src/main.c:112:31: error: unused function 'if_get_addr'
[-Werror,-Wunused-function]
static inline struct in_addr *if_get_addr(struct net_if *iface)
                              ^

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

tests/net/arp/src/main.c:152:31: error: unused function 'if_get_addr'
[-Werror,-Wunused-function]
static inline struct in_addr *if_get_addr(struct net_if *iface)
                              ^

Signed-off-by: Tom Hughes <[email protected]>
Building with clang warns:

tests/net/shell/src/main.c:110:31: error: unused function 'if_get_addr'
[-Werror,-Wunused-function]
static inline struct in_addr *if_get_addr(struct net_if *iface)
                              ^

Signed-off-by: Tom Hughes <[email protected]>
@thughes thughes force-pushed the fix-unused-function-warnings branch from a86cec3 to f7e531b Compare February 7, 2025 23:35
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 <[email protected]>
@thughes thughes force-pushed the fix-unused-function-warnings branch 3 times, most recently from 3f959ef to 0bbc5c8 Compare February 10, 2025 22:56
Building with clang warns:

drivers/ieee802154/ieee802154_dw1000.c:277:24: error: unused function
'dwt_reg_read_u16' [-Werror,-Wunused-function]
static inline uint16_t dwt_reg_read_u16(const struct device *dev,
                       ^

Signed-off-by: Tom Hughes <[email protected]>
@thughes thughes force-pushed the fix-unused-function-warnings branch from 0bbc5c8 to 519d89d Compare February 11, 2025 17:37
Building with clang warns:

drivers/sensor/st/lis2dw12/lis2dw12.c:194:23: error: unused
function 'sensor_ms2_to_mg' [-Werror,-Wunused-function]
static inline int32_t sensor_ms2_to_mg(const struct sensor_value *ms2)
                      ^

Move the function to include/zephyr/drivers/sensor.h with the other
sensor_ms2_to* functions.

Signed-off-by: Tom Hughes <[email protected]>
@thughes thughes force-pushed the fix-unused-function-warnings branch from 519d89d to 575bc6d Compare February 11, 2025 18:05
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 <[email protected]>
The warning emitted is:

tests/net/lib/http_server/core/src/main.c:1400:19: error: variable
'http1_header_capture_common_response' is not needed and will not be
emitted [-Werror,-Wunneeded-internal-declaration]
static const char http1_header_capture_common_response[]
                  ^                             = "HTTP/1.1 200\r\n"

However, this variable is needed at compile-time since it's referenced
via sizeof(). This appears to be the same as this clang bug:
llvm/llvm-project#25458.

This warning only started being emitted when I re-enabled the
-Wunused-function warning for clang.

Signed-off-by: Tom Hughes <[email protected]>
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 <[email protected]>
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, &lt;);      /* a &lt; b */
               ^
tests/posix/timers/src/clock.c:53:16: error: unused function 'tp_gt'
[-Werror,-Wunused-function]
_decl_op(bool, tp_gt, &gt;);      /* a &gt; b */
               ^
tests/posix/timers/src/clock.c:54:16: error: unused function 'tp_le'
[-Werror,-Wunused-function]
_decl_op(bool, tp_le, &lt;=);     /* a &lt;= 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 <[email protected]>
All warnings in the code base have been resolved.

Signed-off-by: Tom Hughes <[email protected]>
@thughes thughes force-pushed the fix-unused-function-warnings branch from 575bc6d to 481d2f5 Compare February 11, 2025 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant