Skip to content

sp register clobber in ARM inline asm incorrectly reported as error #14486

@uoohyo

Description

@uoohyo

Brief summary

Microsoft C/C++ Extension's IntelliSense (EDG parser) flags sp in a
GCC inline asm clobber list as an error (severity 8) on ARM
(ARMv7-M / Cortex-M3). The underlying concern is real —
arm-none-eabi-gcc 15.2.1 also flags the same pattern, but as a
warning (-Wdeprecated), not an error.

The problem is the severity mismatch: vscode-cpptools elevates what
GCC treats as a deprecation warning to an error-level diagnostic in the
Problems panel, making it indistinguishable from a hard compile-blocking
error.

In any CMSIS-based Cortex-M3 project, every reference to __set_PSP /
__set_MSP — the standard CMSIS helpers in core_cmFunc.h distributed
by ARM and used by every silicon vendor (STM32, NXP, Nordic, ...) — is
flagged at error severity.

Steps to reproduce

repro.c (no vendor dependency):

#include <stdint.h>

static inline void set_psp(uint32_t topOfProcStack)
{
    __asm volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) : "sp");
}

static inline void set_msp(uint32_t topOfMainStack)
{
    __asm volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) : "sp");
}

int main(void)
{
    set_psp(0x20018000U);
    set_msp(0x20018000U);
    return 0;
}

Minimal .vscode/c_cpp_properties.json:

{
    "version": 4,
    "configurations": [{
        "name": "Cortex-M3",
        "intelliSenseMode": "linux-gcc-arm",
        "compilerPath": "<path-to>/arm-none-eabi-gcc",
        "cStandard": "c11"
    }]
}

Open repro.c in VS Code → IntelliSense underlines "sp" in both
clobber lists and reports the diagnostic at error severity in the
Problems panel.

Expected behavior

A warning-level diagnostic is acceptable — GCC itself emits
-Wdeprecated for this pattern. The expected behavior is that
IntelliSense reports this at warning severity (matching GCC), not at
error severity that visually masks real compile errors.

Actual behavior

IntelliSense reports the sp token in the clobber list at
severity 8 (error). The error squiggle appears in the editor and the
Problems panel for every translation unit that pulls in CMSIS
core_cmFunc.h (i.e. essentially every Cortex-M project that calls
__set_PSP / __set_MSP).

For comparison, arm-none-eabi-gcc 15.2.1 emits the same diagnostic at
warning severity:

$ arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -Wall -Wextra -c repro.c -o repro.o
warning: listing the stack pointer register 'sp' in a clobber list is deprecated [-Wdeprecated]
note: the value of the stack pointer after an 'asm' statement must be the same as it was before the statement
(emitted twice — once each for set_psp and set_msp)

The compile completes successfully (the diagnostic is -Wdeprecated,
not -Werror=deprecated).

Configuration and Logs

Item Value
VS Code 1.121.0 (x64, commit f6cfa2ea2403534de03f069bdf160d06451ed282)
C/C++ Extension ms-vscode.cpptools 1.32.2 (win32-x64)
OS Windows 11, build 10.0.26200.8457
Compiler Arm GNU Toolchain 15.2.Rel1 — arm-none-eabi-gcc 15.2.1 (2025-12-03 release)
intelliSenseMode linux-gcc-arm
cStandard c11
Target ARMv7-M (Cortex-M3)

VS Code C/C++: Log Diagnostics and C/C++: Show Language Server Log
outputs were not captured in this initial report. They can be regenerated
and attached on maintainer request — the diagnostic is fully reproducible
on demand from the minimal example above and does not depend on any
workspace-specific state beyond the four-line c_cpp_properties.json
shown above.

Related closed issues

May be related to the same EDG behavior previously addressed for other
targets — though this issue is specifically about severity (error
vs. warning), not about the parser rejecting the register name outright
as was the case in the earlier reports:

If the EDG-side mapping for -Wdeprecated-class diagnostics on ARMv7-M
inline asm reports them at error severity instead of warning, that may
be the gap.

Notes

  • GCC 15.2.1 also warns on this pattern: arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -Wall -Wextra emits -Wdeprecated for
    the same code. The diagnostic is therefore not a false positive — but
    the severity (error vs. warning) differs from what GCC reports.
  • The [-Wdeprecated] note from GCC reads: "the value of the stack
    pointer after an 'asm' statement must be the same as it was before
    the statement" — a valid ABI concern, but one that warrants a warning,
    not an error-level block.
  • The pattern is not exotic. __set_PSP / __set_MSP are part of the
    ARM-distributed CMSIS-Core headers used by every silicon vendor for
    Cortex-M. Any CMSIS-based project hits this.
  • The diagnostic is IntelliSense-only at error severity; real builds
    with arm-none-eabi-gcc complete successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions