Functions that are noreturn will needlessly preserve LR and needlessly return

Bug #1646646 reported by Gary Fuehrer
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
New
Undecided
Unassigned

Bug Description

GCC ARM embedded is generating poor assembly for this use-case:

/* Declaration 'int main(void)' is built-into ansi C compilers */

void Reset_Handler() {
    <any not-need-LR code and calls>
    main();
 G: goto G; /* or call any noreturn method */
}

And this should generate exactly the same assembly:

void __attribute__((noreturn)) Reset_Handler() {
    <any not-need-LR code and calls>
    main();
    __asm ("0: b.n 0b"); /* or halt or whatever */
}

Specifically it should generate:

<Reset_Handler>:
    <any not-need-LR code and calls>
    bl <main>
0: b.n 0b

Instead, the generated assembly is preserving LR:

<Reset_Handler>:
    push {r3, lr}
    <any not-need-LR code and calls>
    bl <main>
0: b.n 0b

And, in the latter case, it is also emitting a return:

<Reset_Handler>:
    push {r3, lr}
    <any not-need-LR code and calls>
    bl <main>
0: b.n 0b
    pop {r3, pc}

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.