tinyusb
tinyusb copied to clipboard
Build failed when optimization -O2 is used
Operating System
Windows 10
Board
pca10056, fomu,
Firmware
examples/device/cdc_msc or any other device build
What happened ?
Build fails when optimization is changed from -Os to -O2.
In several places get_driver() (which can return NULL) is used without checking for NULL dereference.
It could be that it is false positive but maybe not.
I'm using other compiler (xc32-gcc for microchip) that allows to have -Os only in PRO version (not free) so I'm stuck with -O2,
which for arm/riscv/pic32 produces same warning about NULL dereference which is promoted to error.
How to reproduce ?
change -Os to -O2 in make.mk
Debug Log
arm
LINK _build/pca10056/cdc_msc.elf
............./tinyusb/src/device/usbd.c: In function 'configuration_reset':
............./tinyusb/src/device/usbd.c:454:18: error: potential null pointer dereference [-Werror=null-dereference]
454 | get_driver(i)->reset(rhport);
| ^
compilation terminated due to -Wfatal-errors.
lto1.exe: all warnings being treated as errors
riscv
$ make BOARD=fomu V=1
CFLAGS -flto -march=rv32i -mabi=ilp32 -nostdlib -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -ggdb -fdata-sections -ffunction-sections -fsingle-precision-constant -fno-strict-aliasing -Wdouble-promotion -Wstrict-prototypes -Wstrict-overflow -Wall -Wextra -Werror -Wfatal-errors -Werror-implicit-function-declaration -Wfloat-equal -Wundef -Wshadow -Wwrite-strings -Wsign-compare -Wmissing-format-attribute -Wunreachable-code -Wcast-align -Wcast-function-type -Wcast-qual -Wnull-dereference -O2 -Itinyusb/hw/bsp/fomu/include -Itinyusb/hw/bsp/fomu -Isrc -Itinyusb/hw -Itinyusb/src
LDFLAGS -flto -march=rv32i -mabi=ilp32 -nostdlib -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -ggdb -fdata-sections -ffunction-sections -fsingle-precision-constant -fno-strict-aliasing -Wdouble-promotion -Wstrict-prototypes -Wstrict-overflow -Wall -Wextra -Werror -Wfatal-errors -Werror-implicit-function-declaration -Wfloat-equal -Wundef -Wshadow -Wwrite-strings -Wsign-compare -Wmissing-format-attribute -Wunreachable-code -Wcast-align -Wcast-function-type -Wcast-qual -Wnull-dereference -O2 -Itinyusb/hw/bsp/fomu/include -Itinyusb/hw/bsp/fomu -Isrc -Itinyusb/hw -Itinyusb/src -Wl,-T,tinyusb/hw/bsp/fomu/fomu.ld -Wl,-Map=.map -Wl,-cref -Wl,-gc-sections -specs=nosys.specs -specs=nano.specs
ASFLAGS -flto -march=rv32i -mabi=ilp32 -nostdlib -DCFG_TUSB_MCU=OPT_MCU_VALENTYUSB_EPTRI -ggdb -fdata-sections -ffunction-sections -fsingle-precision-constant -fno-strict-aliasing -Wdouble-promotion -Wstrict-prototypes -Wstrict-overflow -Wall -Wextra -Werror -Wfatal-errors -Werror-implicit-function-declaration -Wfloat-equal -Wundef -Wshadow -Wwrite-strings -Wsign-compare -Wmissing-format-attribute -Wunreachable-code -Wcast-align -Wcast-function-type -Wcast-qual -Wnull-dereference -O2 -Itinyusb/hw/bsp/fomu/include -Itinyusb/hw/bsp/fomu -Isrc -Itinyusb/hw -Itinyusb/src
AS crt0-vexriscv_asm.o
CC dcd_eptri.o
CC fomu.o
CC board.o
CC main.o
CC msc_disk.o
CC usb_descriptors.o
CC tusb.o
CC tusb_fifo.o
CC usbd.o
.........../tinyusb/src/device/usbd.c: In function 'configuration_reset':
.........../tinyusb/src/device/usbd.c:454:18: error: potential null pointer dereference [-Werror=null-dereference]
get_driver(i)->reset(rhport);
~~~~~~~~~~~~~^~~~~~~
compilation terminated due to -Wfatal-errors.
cc1.exe: all warnings being treated as errors
make: *** [../../rules.mk:130: _build/fomu/obj/src/device/usbd.o] Error 1
Screenshots
No response