This patch adds dynamic stack alignment for Thumb1.
The motivating issue is micompilation of the following code, when targeting a
CPU, which implements only Thumb-1, like cortex-m0.
struct foo {
alignas(16) char buf[12];
int i;
int *ip;
foo() : ip(&i) {}
};
extern void g(foo &);
void f() {
foo myFoo;
g(myFoo);
}When initialising the ip member, the address of i is calculated using bitwise OR:
push {r7, lr}
.pad #40
sub sp, #40
movs r1, #12
mov r0, sp
orrs r1, r0
str r1, [sp, #16]which is obviously incorrect when the starting address of that object (resp. the
stack pointer) happens to be aligned at 8 or 4 byte boundary.
When compiling for ARM or Thumb2, the stack is realigned and the problem does
not occur.