Skip to content

GCC-specific optimization hints not guarded against Clang and partially not guarded against IAR, causing compiler warnings #205

@Symanyshyn-IFX

Description

@Symanyshyn-IFX

Several source files in CMSIS-NN use GCC-specific optimization hints that are not properly guarded against non-GCC compilers. Building with Clang/LLVM Embedded Toolchain for Arm produces warnings, and one case also affects IAR.

Case 1 - attribute((optimize(...))) missing Clang and IAR guards

Problem:
The guard only excludes Arm Compiler (__ARMCC_VERSION). Clang
(clang) and IAR (ICCARM) are not excluded, so both compilers
receive the GCC-specific attribute.

Compilers affected:

  • Clang/LLVM Embedded Toolchain for Arm 19.1.5 - warning:
    warning: unknown attribute 'optimize' ignored [-Wunknown-attributes]
    
  • IAR C/C++ Compiler for Arm 9.70.1 - warning:
    Warning[Pe1097]: unknown attribute 'optimize'
    

Suggested fix:

#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__) && !defined(__clang__)
__attribute__((optimize("no-unroll-loops")))
#endif

Case 2 - #pragma GCC optimize(...) missing Clang guard

Files:

#if !defined(ARM_MATH_MVEI) && defined(ARM_MATH_DSP) && !defined(__ARMCC_VERSION) && !defined(__ICCARM__)

#if !defined(ARM_MATH_MVEI) && defined(ARM_MATH_DSP) && !defined(__ARMCC_VERSION) && !defined(__ICCARM__)

Problem:
The guard correctly excludes ARMCC and IAR, but does not exclude Clang,
which does not implement #pragma GCC optimize.

Compilers affected:

  • Clang/LLVM Embedded Toolchain for Arm 19.1.5 - warning:
    warning: unknown pragma ignored [-Wunknown-pragmas]
    

Suggested fix:

#if !defined(ARM_MATH_MVEI) && defined(ARM_MATH_DSP) && !defined(__ARMCC_VERSION) && !defined(__ICCARM__) && !defined(__clang__)
    #pragma GCC optimize("unroll-loops")
#endif

Environment

  • Toolchain: LLVM Embedded Toolchain for Arm 19.1.5, IAR C/C++ Compiler for Arm: 9.70.1
  • Target: Cortex-M33, Cortex-M55

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions