Keil Logo

ARMCC: Option --use_frame_pointer may generate wrong code

Information in this knowledgebase article applies to:

  • ARMCC C/C++ Compiler V5 all versions


When using the Arm compiler version 5 with option --use_frame_pointer, wrong code might be generated under certain circumstances for Cortex-M microcontroller. This wrong code might cause sporadic run-time crashes or hardfaults. Here is an example:

int foo(void)
    int w = 4;
    int x = 5;
    int y = 6;
    int z = 7;
    return w + x + y + z;

This generates the following code:

        0x00000000:    e92d4810    -..H    PUSH     {r4,r11,lr}
        0x00000004:    f10d0b08    ....    ADD      r11,sp,#8
        0x00000008:    2404        .$      MOVS     r4,#4
        0x0000000a:    2105        .!      MOVS     r1,#5
        0x0000000c:    2206        ."      MOVS     r2,#6
        0x0000000e:    2307        .#      MOVS     r3,#7
        0x00000010:    1860        '.      ADDS     r0,r4,r1
        0x00000012:    4410        .D      ADD      r0,r0,r2
        0x00000014:    4418        .D      ADD      r0,r0,r3
        0x00000016:    46dd        .F      MOV      sp,r11
        0x00000018:    b082        ..      SUB      sp,sp,#8
        0x0000001a:    e8bd8810    ....    POP      {r4,r11,pc}

If an interrupt occurs between the MOV instruction at address 0x00000016 and the SUB instruction at address 0x00000018, the interrupt stacking can corrupt values that will be loaded to r4 and r11 by the POP instruction at address 0x0000001a. That is because they lie below the address that is in the SP register when the interrupt occurs.

This compiler option cannot be selected with a checkbox in µVision. It must be specified manually in the dialog Options for Target - C/C++ under Misc Controls.


This is an error in the code generation of the Arm compiler version 5 (armcc.exe).


Do not use the option --use_frame_pointer for Cortex-M controller. This option does not provide benefits for execution time or code density. The µVision debugger also does not need this option to display the Call Stack of the application correctly.


This is a known problem. At this time, we don't know if this issue will be fixed in a version later than 5.06u6.


Last Reviewed: Wednesday, May 29, 2019

Did this article provide the answer you needed?
Not Sure
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.