PX4 / PX4-Autopilot

PX4 Autopilot Software
https://px4.io
BSD 3-Clause "New" or "Revised" License
8.48k stars 13.5k forks source link

`arm-none-eabi-gcc` 13.2.0 fails for some boards due to a redundant `nullptr` check in `spi.cpp` #22740

Open andrejpodzimek opened 8 months ago

andrejpodzimek commented 8 months ago

Describe problem solved by the proposed feature

When building on ArchLinux with current tool chain, -Werror fails due to a new (probably recently introduced) warning in platforms/common/spi.cpp:

/home/andrej/inst/PX4-Autopilot/platforms/common/spi.cpp: In function 'int px4_find_spi_bus(uint32_t)':
/home/andrej/inst/PX4-Autopilot/platforms/common/spi.cpp:90:59: error: the address of 'px4_spi_buses' will never be NULL [-Werror=address]
   90 |         for (int i = 0; ((px4_spi_bus_t *) px4_spi_buses) != nullptr && i < SPI_BUS_MAX_BUS_ITEMS; ++i) {
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

Describe your preferred solution

To make the warning non-fatal, one can add -Wno-error=address behind -Werror in cmake/px4_add_common_flags.cmake. The affected boards build just fine in that case, with a non-fatal warning.

Describe possible alternatives

The obvious quick workaround (removal of ((px4_spi_bus_t *) px4_spi_buses) != nullptr) makes it build too, but that doesn’t mean it’s working (or correct). I’m not sure if there’s (e.g.) a platform where px4_spi_buses can be a nullptr. There probably is one, or else the check wouldn’t be there… This needs to be double-checked by someone familiar with the broader context.

Additional context

No response

battlesnake commented 3 months ago

Can confirm this on GCC arm-none-eabi v13.2.1, building for a STM32H743

For now, I'll wrap the block in pragmas to disable the warning