cancel
Showing results for 
Search instead for 
Did you mean: 

Warning: "unknown attribute 'optimize'" (CubeIDE VSCode 3.8.0 & clang & CubeMX 6.17.0)

FluxPower42
Associate III

Hi ST-Team,

context:
- STM32H753ZI NUCLEO Board
- VSCode with STM32CubeIDE Extension
- Clang Compiler

after follow updates

  • STM32CubeIDE VSCode from v3.7.0 to v3.8.0
  • STM32CubeMx from v6.16.1 to v6.17.0
    incl. MCU Package H7 from v1.12.1 to v1.13.0
    incl. Azure RTOS for H7 from v3.4.0 to v3.5.0

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:

2026-03-09_16-41-11.png

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


3 REPLIES 3
Pavel A.
Super User

Since clang by default pretends to be GCC and defines __GNUC__ ...

 

#if defined(__GNUC__) && __has_attribute(optimize)
.......

 

Opened issue on github.

Thanks.

 

Julien D
ST Employee

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__).

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

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.