On 18/06/12 16:39, Greta Yorsh wrote:
> This test checks that the stack pointer is handled correctly in
> prologue/epilogue of Cortex-M interrupt handlers. An interrupt handler may
> be called when stack is not double-word aligned. The prologue of the
> interrupt handler aligns the stack pointer and the epilogue restores the
> original stack pointer.
>
> However, in this test, the stack is always double-word aligned when the
> handler function foo is called. As a result, the test is not very effective,
> for example it passes even if the epilogue does not restore the stack
> pointer. This patch forces the stack pointer to be not double-word aligned
> on the call to foo.
>
> Tested on qemu -cpu cortex-m3.
>
> Ok for trunk?
>
> Thanks,
> Greta
>
> ChangeLog:
>
> gcc/testsuite
>
> 2012-06-18 Greta Yorsh <[email protected]>
>
> * gcc.target/arm/handler-align.c (main): Force the stack pointer
> to be not double-word aligned on the call to the interrupt handler.
>
>
Please add a new test for this; the existing test is still valid.
I'd also prefer a test that didn't mess directly with SP within a
function -- this looks very unsafe, even if it works today.
R.
> test-handler-align.v1.patch.txt
>
>
> diff --git a/gcc/testsuite/gcc.target/arm/handler-align.c
> b/gcc/testsuite/gcc.target/arm/handler-align.c
> index 6c5187b..b0efa58 100644
> --- a/gcc/testsuite/gcc.target/arm/handler-align.c
> +++ b/gcc/testsuite/gcc.target/arm/handler-align.c
> @@ -29,8 +29,15 @@ int main()
> /* Check stack pointer before/after calling the interrupt
> * handler. Not equal means that handler doesn't restore
> * stack correctly. */
> save_sp = sp;
> - foo();
> +
> + /* The stack is always double-word aligned here. To test interrupt
> handling,
> + force the stack to be not double-word aligned. */
> + asm volatile ("sub\tsp, sp, #4" : : : "memory" );
> + foo ();
> + /* Restore the stack. */
> + asm volatile ("add\t sp, sp, #4" : : : "memory" );
> +
> /* Abort here instead of return non-zero. Due to wrong sp, lr value,
> * returning from main may not work. */
> if (save_sp != sp)