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_PRESENTCFLAGS += -DARM_MATH_CM7CFLAGS += -DSTM32CFLAGS += -DSTM32H7CFLAGS += -DSTM32H743xxCFLAGS += -DSTM32H743XIHxCFLAGS += -std=c11CFLAGS += -mthumbCFLAGS += -mcpu=cortex-m7CFLAGS += -mfloat-abi=softfpCFLAGS += -mfpu=fpv5-d16CFLAGS += -gCFLAGS += -fmessage-length=0CFLAGS += -ffunction-sections CFLAGS += -fno-delete-null-pointer-checksCFLAGS += -Wstringop-overflowCFLAGS += -WerrorCFLAGS += -WallCFLAGS += -WextraCFLAGS += -Wno-missing-field-initializersCFLAGS += -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.
I think you'd need to show some actual code and the actual warnings you get to get meaningful answers - else we're just guessing.
fkl_at_deif said:I experience that the number of warnings found increases with the optimisation level. -O3 finds more warnings that -O1.
I don't think that would be a surprise?
It is common that you can "get away" with some questionable coding at lower optimisation levels, but they will "bite" you at higher levels.
An obvious example would be the use of 'volatile' ...
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.
I would guess that, at higher optimisation levels, the compiler has to do more in-depth analysis of the source - so that would give it more information on which to give warnings.
Does the documentation mention that default warning levels may be affected by optimisation level ... ?
I would also expect more warnings the higher the optimisation level. That is why I wondered that I see warnings in -O1 that I haven't seen with -O3 or -Os. The manual however pin-point that some optimisations are only used in -O1 and not in higher levels. That could be the reason why.
Yes, the GCC manual mention (at least) one warning that is affected by optimisation level - found searching for "optimization level". It is strict-overflow.
fkl_at_deif said: I see warnings in -O1 that I haven't seen with -O3 or -Os
Do the warnings appear if you specifically enable them?
Do the warnings appear when I specifically enable them in -O3 and -Os?
I haven't tried that: Only -Wall and -Wextra.