zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.93k stars 6.65k forks source link

Update macros statements to allow -Werror=undef use #81337

Open rkhouryUBILITE opened 1 week ago

rkhouryUBILITE commented 1 week ago

Bug description:

After enabling -Werror=undef, a set of undefined configurations appear while building various zephyr apps. The error would look like this:

[build] /workspaces/zephyr/zephyrproject/zephyr/drivers/serial/uart_ns16550.c:946:5: error: "CONFIG_UART_INTERRUPT_DRIVEN" is not defined, evaluates to 0 [-Werror=undef]
[build]   946 | #if CONFIG_UART_INTERRUPT_DRIVEN
[build]       |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
[build] cc1: some warnings being treated as errors

To reproduce:

Simply add -Werror=undef to the compiler flags.

KConfig configurations that suffers from this issue:

zephyr/zephyrproject/zephyr/drivers/serial/uart_ns16550.c:946 #if CONFIG_UART_INTERRUPT_DRIVEN

zephyr/zephyrproject/zephyr/arch/riscv/core/switch.S:84 #if CONFIG_INSTRUMENT_THREAD_SWITCHING

zephyr/zephyrproject/zephyr/subsys/net/buf.c:39 #if CONFIG_NET_BUF_WARN_ALLOC_INTERVAL > 0

zephyr/zephyrproject/zephyr/subsys/bluetooth/host/hci_core.h:251 zephyr/zephyrproject/zephyr/subsys/bluetooth/host/scan.c:758 and 874 #if CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0

zephyr/zephyrproject/zephyr/subsys/bluetooth/controller/ll_sw/ull.c:1311 and 1510 zephyr/zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:8630 and 9081 #if CONFIG_BT_CTLR_USER_EVT_RANGE > 0

zephyr/zephyrproject/zephyr/subsys/bluetooth/controller/hci/hci.c:108, 444, 1768, 3838, 3919, 4002, 6054, 6287, 6441, 6545, 7283 #if CONFIG_BT_CTLR_DUP_FILTER_LEN > 0

zephyr/zephyrproject/zephyr/subsys/logging/log_msg.c:48 #if CONFIG_LOG_THREAD_ID_PREFIX

Issue fix:

Fixing the issue the same way it is fixed here: https://github.com/zephyrproject-rtos/zephyr/pull/64912

github-actions[bot] commented 1 week ago

Hi @rkhouryUBILITE! We appreciate you submitting your first issue for our open-source project. 🌟

Even though I'm a bot, I can assure you that the whole community is genuinely grateful for your time and effort. 🤖💙

alwa-nordic commented 1 week ago

As a start I suggest we run the regex search replace: ^(\s*)#if \s*(CONFIG_[A-Z_]+)\s*$ to $1#if defined($2). This will resolve 556 instances of this problem.