From 1c84b79889a10503e5adf0e78d0509a88ca08868 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 5 Oct 2016 00:21:41 +0000 Subject: [PATCH] explow.c (allocate_dynamic_stack_space): Call do_pending_stack_adjust before handling flag_split_stack. gcc/: * explow.c (allocate_dynamic_stack_space): Call do_pending_stack_adjust before handling flag_split_stack. gcc/testsuite/: * gcc.dg/split-7.c: New test. From-SVN: r240764 --- gcc/ChangeLog | 5 ++++ gcc/explow.c | 4 +-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/split-7.c | 55 ++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/split-7.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 60aeafb0a16..ad08f0f771f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-10-04 Ian Lance Taylor + + * explow.c (allocate_dynamic_stack_space): Call + do_pending_stack_adjust before handling flag_split_stack. + 2016-10-04 David Malcolm * genattrtab.c (make_internal_attr): Supply dummy column number to diff --git a/gcc/explow.c b/gcc/explow.c index d8f9dd2e7de..b56aea69477 100644 --- a/gcc/explow.c +++ b/gcc/explow.c @@ -1357,6 +1357,8 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, current_function_has_unbounded_dynamic_stack_size = 1; } + do_pending_stack_adjust (); + final_label = NULL; final_target = NULL_RTX; @@ -1414,8 +1416,6 @@ allocate_dynamic_stack_space (rtx size, unsigned size_align, emit_label (available_label); } - do_pending_stack_adjust (); - /* We ought to be called always on the toplevel and stack ought to be aligned properly. */ gcc_assert (!(stack_pointer_delta diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 673b6f7b98c..17259812b48 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-04 Ian Lance Taylor + + * gcc.dg/split-7.c: New test. + 2016-10-04 Martin Sebor * gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Cast int argument to diff --git a/gcc/testsuite/gcc.dg/split-7.c b/gcc/testsuite/gcc.dg/split-7.c new file mode 100644 index 00000000000..4933e9cfb2a --- /dev/null +++ b/gcc/testsuite/gcc.dg/split-7.c @@ -0,0 +1,55 @@ +/* { dg-do run } */ +/* { dg-require-effective-target split_stack } */ +/* { dg-options "-fsplit-stack -O2" } */ +/* { dg-options "-fsplit-stack -O2 -mno-accumulate-outgoing-args" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */ + +/* A case that used to fail on 32-bit x86 when optimizing and not + using -maccumulate-args. The stack adjustment of the alloca got + mixed up with the arguments pushed on the stack to the function + before the call of alloca. */ + +#include + +typedef struct { const char* s; int l; } s; + +typedef unsigned long long align16 __attribute__ ((aligned(16))); + +s gobats (const void *, int) __attribute__ ((noinline)); + +s +gobats (const void* p __attribute__ ((unused)), + int l __attribute__ ((unused))) +{ + s v; + v.s = 0; + v.l = 0; + return v; +} + +void check_aligned (void *p) __attribute__ ((noinline)); + +void +check_aligned (void *p) +{ + if (((__SIZE_TYPE__) p & 0xf) != 0) + abort (); +} + +void gap (void *) __attribute__ ((noinline)); + +void gap (void *p) +{ + align16 a; + check_aligned (&a); +} + +int +main (int argc, char **argv) +{ + s *space; + gobats(0, 16); + space = (s *) alloca(sizeof(s) + 1); + *space = (s){0, 16}; + gap(space); + return 0; +} -- 2.30.2