cancel
Showing results for 
Search instead for 
Did you mean: 

Wrong code generation in many optimization options Version: 1.10.1

pj_stm
Associate III

-O2, -O3 -Ofast optimizations compiler is adding udf 255 instruction into the execution path which results in HF.

Example:

1154      				pQueryChunk->pSrcDriver = pParser->pSourceDriver;
 
080157f4:   ldr.w   r3, [r9, #20]
 
080157f8:   str.w   r3, [r11, #12]
 
080157fc:   b.n     0x801556e <httpG4WebPage+1130>
 
080157fe:   movs    r3, #0
 
08015800:   ldr.w   r2, [r9, #20]
 
08015804:   str     r2, [r3, #12]
 
08015806:   udf     #255    ; 0xff   <---------- obviously wrong
 
 
 
			if (pQueryChunk && ioIsValid(pRawChunk))
 
			{
 
				pQueryChunk->pSrcDriver = pRawChunk->pSrcDriver;
 
			}			
 
			else if (pParser)
 
			{
 
				pQueryChunk->pSrcDriver = pParser->pSourceDriver;
 
			}
 
 
 
GNU C11 (GNU Tools for STM32 10.3-2021.10.20211105-1100) version 10.3.1 20210824 (release) (arm-none-eabi)
 
	compiled by GNU C version 7.3-win32 20180312, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.18-GMP
 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
 
COLLECT_GCC_OPTIONS='-mcpu=cortex-m4' '-std=gnu11' '-g3' '-D' '_GNU_SOURCE=1' '-D' 'USE_HAL_DRIVER' '-D' '_DEBUG=1' '-D' 'DEBUG_RUN_WITHOUT_CHECKS=1' '-D' 'DEBUGFILEWRITE=0' '-D' 'DEBUG=0' '-D' 'SLOWSPIDEBUG=0' '-D' 'USE_FULL_ASSERT' '-D' '__USE_SIMPLE_SWO=0' '-D' 'USE_SWOTRACE=1' '-D' 'AMD64' '-D' 'HSE_VALUE=16000000UL' '-D' 'USE_FULL_LL_DRIVER=0' '-D' 'BOOTLOADER_VERSION=1' '-D' 'ALLOW_SOFTWARE_BKPTS=1' '-D' 'ARM_MATH_CM4' '-D' 'FORCE_CUBE_USB' '-D' 'USE_EMBEDDED_PHY=1' '-D' 'USE_USB_OTG_FS=1' '-D' 'BITMAP_LCD_ALLOWED=0' '-D' 'LCDGUI_ALLOWED=0' '-D' 'LCD_ALLOWED=0' '-D' 'GPS_ALLOWED=0' '-D' 'STM32L4S9xx' '-D' 'STM32L' '-D' 'INCLUDE_SLEEP_FUNCTIONS=1' '-D' 'COMPILE_FOR_EWB=1' '-D' 'COMPILE_USE_PL4S=1' '-c' '-Ofast' '-ffunction-sections' '-fdata-sections' '-Wall' '-v' '-fstack-usage' '-MMD' '-MP' '-MF' '-MT'  '-specs=nano.specs' '-mfpu=fpv4-sp-d16' '-mfloat-abi=hard' '-mthumb' '-o'  '-mlibarch=armv7e-m+fp' '-march=armv7e-m+fp'
 
 -march=armv7e-m -mfloat-abi=hard -mfpu=fpv4-sp-d16 -meabi=5 -o Libraries/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.o C:\Users\Piotr\AppData\Local\Temp\ccHP5ygN.s
 
GNU assembler version 2.36.1 (arm-none-eabi) using BFD version (GNU Tools for STM32 10.3-2021.10.20211105-1100) 2.36.1.20210621
 
 

It is a quite big project (~800 source files) 800k generated code. It makes IDE unusable. Only -O0 and -Og prevent from udf instructions to be added.

1 ACCEPTED SOLUTION

Accepted Solutions
pj_stm
Associate III

The problem was in another task which was ignoring mutex.

View solution in original post

3 REPLIES 3
KnarfB
Principal III

Would be nice to see a minimal example demonstrating the behaviour.

KnarfB

Nikita91
Lead II

This looks like a compiler warning because you use a NULL pointer (here it is r3)

Have a look to https://embedded.fm/blog/2017/3/6/exceptional-code

The generated code is different for different optimization level. The NULL r3 value may be correct or wrong, check your source code.

pj_stm
Associate III

The problem was in another task which was ignoring mutex.