This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Detection of warning depend on optimisation

Hello arm

I use the arm v9-2019-q4-major toolchain. I compile for the STM32H743 (also seen in the setting)

I compile using the following settings. CFLAG contains compiler settings.

CFLAGS  += -D__FPU_PRESENT
CFLAGS  += -DARM_MATH_CM7
CFLAGS  += -DSTM32
CFLAGS  += -DSTM32H7
CFLAGS  += -DSTM32H743xx
CFLAGS  += -DSTM32H743XIHx
CFLAGS  += -std=c11
CFLAGS  += -mthumb
CFLAGS  += -mcpu=cortex-m7
CFLAGS  += -mfloat-abi=softfp
CFLAGS  += -mfpu=fpv5-d16
CFLAGS  += -g
CFLAGS  += -fmessage-length=0
CFLAGS  += -ffunction-sections
CFLAGS  += -fno-delete-null-pointer-checks

CFLAGS  += -Wstringop-overflow

CFLAGS  += -Werror
CFLAGS  += -Wall
CFLAGS  += -Wextra

CFLAGS  += -Wno-missing-field-initializers
CFLAGS  += -Wdouble-promotion

I wonder why I experience different warnings in my code depending on the optimisation?

I have tried with -O0, -O1, -O2, -O3 and -Os.

I find (relevant) warnings - eg warning of variables that might be used non initialised - with -O1, that is not found when compiling using higher levels?

I experience that the number of warnings found increases with the optimisation level. -O3 finds more warnings that -O1.

Best regards Frank.

Parents
  • Actually it is some code (quite a lot to be honest) ported from another target.

    I can't post it all here, and I don't have the time to try to make an example with less code.

    The warnings I remember to have experienced, is variables that might be used uninitialised (found with -O1 and not with -O2, -O3 and -Os)

    " '<my variable>' may be used uninitialized in this function [-Werror=maybe-uninitialized]"

    and possible array index out of bound with -O3 only.

    "array subscript 237 is above array bounds of 'const DU8 (*[142][3])[20]' {aka 'const unsigned char (*[142][3])[20]'} [-Werror=array-bounds]"

    But if hat is expected behaviour, then my question is answered.

Reply
  • Actually it is some code (quite a lot to be honest) ported from another target.

    I can't post it all here, and I don't have the time to try to make an example with less code.

    The warnings I remember to have experienced, is variables that might be used uninitialised (found with -O1 and not with -O2, -O3 and -Os)

    " '<my variable>' may be used uninitialized in this function [-Werror=maybe-uninitialized]"

    and possible array index out of bound with -O3 only.

    "array subscript 237 is above array bounds of 'const DU8 (*[142][3])[20]' {aka 'const unsigned char (*[142][3])[20]'} [-Werror=array-bounds]"

    But if hat is expected behaviour, then my question is answered.

Children