On Wed, Sep 17, 2014 at 09:30:31AM +0100, Richard Earnshaw wrote: > "=&r" is correct for an early-clobbered scratch. > > R.
In that case... How is the attached patch for trunk? I've bootstrapped it on AArch64 with -fstack-protector-strong and -frename-registers in the BOOT_CFLAGS without seeing any issues. OK? Thanks, James --- gcc/ 2014-09-15 James Greenhalgh <james.greenha...@arm.com> * config/aarch64/aarch64.md (stack_protect_test_<mode>): Mark scratch register as an output to placate register renaming. gcc/testsuite/ 2014-09-15 James Greenhalgh <james.greenha...@arm.com> * gcc.target/aarch64/stack_protector_set_1.c: New. * gcc.target/aarch64/stack_protector_set_2.c: Likewise.
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index c60038a9015d614f40f6d9e3fd228ad3e2b247a8..f15a516bb0559c86bea7512f91d60dc179ec9149 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -4031,7 +4031,7 @@ (define_insn "stack_protect_test_<mode>" (unspec:PTR [(match_operand:PTR 1 "memory_operand" "m") (match_operand:PTR 2 "memory_operand" "m")] UNSPEC_SP_TEST)) - (clobber (match_scratch:PTR 3 "&r"))] + (clobber (match_scratch:PTR 3 "=&r"))] "" "ldr\t%<w>3, %x1\;ldr\t%<w>0, %x2\;eor\t%<w>0, %<w>3, %<w>0" [(set_attr "length" "12") diff --git a/gcc/testsuite/gcc.target/aarch64/stack_protector_set_1.c b/gcc/testsuite/gcc.target/aarch64/stack_protector_set_1.c new file mode 100644 index 0000000..df0d26b --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/stack_protector_set_1.c @@ -0,0 +1,15 @@ +/* { dg-do assemble } */ +/* { dg-options "-fstack-protector-strong -O1 -frename-registers" } */ + +extern int bar (const char *s, int *argc); +extern int baz (const char *s); + +char +foo (const char *s) +{ + int argc; + int ret; + if ( !bar (s, &argc)) + ret = baz (s); + return *s; +} diff --git a/gcc/testsuite/gcc.target/aarch64/stack_protector_set_2.c b/gcc/testsuite/gcc.target/aarch64/stack_protector_set_2.c new file mode 100644 index 0000000..b94a2d6 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/stack_protector_set_2.c @@ -0,0 +1,17 @@ +/* { dg-do assemble } */ +/* { dg-options "-fstack-protector-strong -O1 -frename-registers" } */ + +typedef unsigned int uint32_t; +struct ctx +{ + uint32_t A; +}; + +void * +buffer_copy (const struct ctx *ctx, void *resbuf) +{ + uint32_t buffer[4]; + buffer[0] = (ctx->A); + __builtin_memcpy (resbuf, buffer, 16); + return resbuf; +}