This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [Patch, Testsuite, ARM] Improve test gcc.target/arm/handler-align.c
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Greta Yorsh <Greta dot Yorsh at arm dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, "mikestump at comcast dot net" <mikestump at comcast dot net>
- Date: Mon, 18 Jun 2012 17:56:12 +0100
- Subject: Re: [Patch, Testsuite, ARM] Improve test gcc.target/arm/handler-align.c
- References: <000d01cd4d68$8b595f00$a20c1d00$@Yorsh@arm.com>
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 <Greta.Yorsh@arm.com>
>
> * 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)