Functions that are noreturn will needlessly preserve LR and needlessly return
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_
<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}