2026-03-09 8:57 AM - last edited on 2026-03-12 3:06 AM by Andrew Neil
Hi ST-Team,
context:
- STM32H753ZI NUCLEO Board
- VSCode with STM32CubeIDE Extension
- Clang Compiler
after follow updates
we get now following warning if a file is including the header
\Drivers\CMSIS\Device\ST\STM32H7xx\Include\system_stm32h7xx.h
[build] [6/206] Building C object CMakeFiles/STM32_NUCLEO-H753ZI.dir/AZURE_RTOS/App/app_azure_rtos.c.obj
[build] In file included from D:/dev/Prj/Clean_STM32H7_Project__02/AZURE_RTOS/App/app_azure_rtos.c:28:
[build] In file included from D:/dev/Prj/Clean_STM32H7_Project__02/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h:124:
[build] In file included from D:/dev/Prj/Clean_STM32H7_Project__02/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h753xx.h:232:
[build] D:/dev/Prj/Clean_STM32H7_Project__02/cmake/stm32cubemx/../../Drivers/CMSIS/Device/ST/STM32H7xx/Include/system_stm32h7xx.h:88:49: warning: unknown attribute 'optimize' ignored [-Wunknown-attributes]
[build] 88 | extern void ExitRun0Mode(void) __attribute__((optimize("Os")));
[build] | ^~~~~~~~~~~~~~
[build] 1 warning generated. Comparing the versions of system_stm32h7xx.h shows following:
We use the "CMake" and "ST Arm Clang" settings in STM32CubeMX
under "Project Manager / Project / Default Compiler / Linker".
After generating the project we open the folder with VSCode with active STM32CubeIDE Extension.
But clang can not work with the new __attribute__((optimize("Os")) but defines the __GNUC__ macro for compatibility reasons. Therefore we get a warning.
@st Please solve this issue - Thanks
Bet regards Timo
2026-03-09 12:04 PM - edited 2026-03-09 12:14 PM
Since clang by default pretends to be GCC and defines __GNUC__ ...
#if defined(__GNUC__) && __has_attribute(optimize)
.......
Thanks.
2026-03-10 6:38 AM
The optimize attribute is a GNU attribute and is not supported by Clang.
However, in system_stm32h7xx.h, the check for using this attribute is based on __ARMCC_VERSION, which is defined only for ARM compilers. Waiting for a fix you could also insert this check: !defined(__clang__).
2026-03-10 6:04 PM - edited 2026-03-10 6:33 PM
Proposed a fix via github issue, against cmsis-device-h7 release 1.10.7 here.
Use the standard preprocessor function __has_attribute rather than check for specific compilers.
More to this.... My AI assistant says that
[quote]
" placing __attribute__(optimize) only on the function prototype in a header is not guaranteed to work.
For reliable behavior, you should place the attribute on the function definition in the C file, not just the declaration.
Why the attribute must be on the definition
GCC applies optimization attributes at the point where the function is compiled, which is the definition, not the declaration.
If the definition lacks the attribute ..... Then GCC will simply ignore the attribute from the prototype
[end quote]
I understand that it was tempting to apply the attribute(optimize) in the single place in the .h file instead of all the variants of system_stm32h7xx.....c.