raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.78k stars 949 forks source link

warnings: declaration of 'flash_range_erase' shadows a global declaration #1468

Closed hathach closed 6 months ago

hathach commented 1 year ago

I got a folowing warning

pico-sdk/src/rp2_common/hardware_flash/flash.c:71:30: error: declaration of 'flash_range_erase' shadows a global declaration [-Werror=shadow]
   71 |     rom_flash_range_erase_fn flash_range_erase = (rom_flash_range_erase_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_RANGE_ERASE);
      |                              ^~~~~~~~~~~~~~~~~

warnings seems legit since both the function and pointer are named flash_range_erase same as flash_range_program. Maybe I miss something ?

void __no_inline_not_in_flash_func(flash_range_erase)(uint32_t flash_offs, size_t count) {
//                                 ^^^^^^^^^^^^^^^^^
#ifdef PICO_FLASH_SIZE_BYTES
    hard_assert(flash_offs + count <= PICO_FLASH_SIZE_BYTES);
#endif
    invalid_params_if(FLASH, flash_offs & (FLASH_SECTOR_SIZE - 1));
    invalid_params_if(FLASH, count & (FLASH_SECTOR_SIZE - 1));
    rom_connect_internal_flash_fn connect_internal_flash = (rom_connect_internal_flash_fn)rom_func_lookup_inline(ROM_FUNC_CONNECT_INTERNAL_FLASH);
    rom_flash_exit_xip_fn flash_exit_xip = (rom_flash_exit_xip_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_EXIT_XIP);
    rom_flash_range_erase_fn flash_range_erase = (rom_flash_range_erase_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_RANGE_ERASE);
//                           ^^^^^^^^^^^^^^^^^
    rom_flash_flush_cache_fn flash_flush_cache = (rom_flash_flush_cache_fn)rom_func_lookup_inline(ROM_FUNC_FLASH_FLUSH_CACHE);
    assert(connect_internal_flash && flash_exit_xip && flash_range_erase && flash_flush_cache);
    flash_init_boot2_copyout();

    // No flash accesses after this point
    __compiler_memory_barrier();

    connect_internal_flash();
    flash_exit_xip();
    flash_range_erase(flash_offs, count, FLASH_BLOCK_SIZE, FLASH_BLOCK_ERASE_CMD);
    flash_flush_cache(); // Note this is needed to remove CSn IO force as well as cache flushing
    flash_enable_xip_via_boot2();
}

https://github.com/raspberrypi/pico-sdk/blob/6a7db34ff63345a7badec79ebea3aaef1712f374/src/rp2_common/hardware_flash/flash.c#L63C36-L84

MillionsSuperStar commented 1 year ago

I'm also having this issue with tinyusb, exactly the same.

kilograham commented 1 year ago

we can fix that, but since i haven't seen the warning:

what compiler? how are you building?

hathach commented 1 year ago

we can fix that, but since i haven't seen the warning:

what compiler? how are you building?

Sorry, forgot to mention way to reproduce the issue. I encounter this when add unique_id as serial number to my tinyusb example. Compiling with gcc 11.2. You can reproduce it by clone tinyusb master and re-enable -Wshadow (I have to temporarily disable it) as follow commit

https://github.com/hathach/tinyusb/compare/master...pico-sdk-1468

CI failed with the warnings when trying to compile with any of device example e.g cdc_msc. https://github.com/hathach/tinyusb/actions/runs/5787485903/job/15684511076#step:8:125

kilograham commented 6 months ago

has been merged into develop a while back