From: jbeulich Date: Fri, 11 Dec 2015 15:53:24 +0000 (+0000) Subject: avoid alignment of static variables affecting stack's X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c5f556750802b91d68cb7f5e548eb35a82eb224;p=thirdparty%2Fgcc.git avoid alignment of static variables affecting stack's Function (or more narrow) scope static variables (as well as others not placed on the stack) should also not have any effect on the stack alignment. I noticed the issue first with Linux'es dynamic_pr_debug() construct using an 8-byte aligned sub-file-scope local variable. According to my checking bad behavior started with 4.6.x (4.5.3 was still okay), but generated code got quite a bit worse as of 4.9.0. gcc/ 2015-12-11 Jan Beulich * cfgexpand.c (expand_one_var): Exit early for static and external variables when adjusting stack alignment related. gcc/testsuite/ 2015-12-11 Jan Beulich * gcc.c-torture/execute/stkalign.c: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@231569 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cb9b10ceb418..b52b9aae8d1f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-12-11 Jan Beulich + + * cfgexpand.c (expand_one_var): Exit early for static and + external variables when adjusting stack alignment related. + 2015-12-11 Dominik Vogt * config/s390/s390.c (s390_rtx_costs) diff --git a/gcc/cfgexpand.c b/gcc/cfgexpand.c index 7fe02a900bc9..7f4eba2c226e 100644 --- a/gcc/cfgexpand.c +++ b/gcc/cfgexpand.c @@ -1550,6 +1550,9 @@ expand_one_var (tree var, bool toplevel, bool really_expand) if (TREE_TYPE (var) != error_mark_node && TREE_CODE (var) == VAR_DECL) { + if (is_global_var (var)) + return 0; + /* Because we don't know if VAR will be in register or on stack, we conservatively assume it will be on stack even if VAR is eventually put into register after RA pass. For non-automatic diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 541228af5a17..1372d8413054 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-12-11 Jan Beulich + + * gcc.c-torture/execute/stkalign.c: New. + 2015-12-11 Tsvetkova Alexandra * gcc.target/i386/mpx/memmove-1.c: New test. diff --git a/gcc/testsuite/gcc.c-torture/execute/stkalign.c b/gcc/testsuite/gcc.c-torture/execute/stkalign.c new file mode 100644 index 000000000000..e8761b936aae --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/stkalign.c @@ -0,0 +1,26 @@ +/* { dg-options "-fno-inline" } */ + +#include + +#define ALIGNMENT 64 + +unsigned test(unsigned n, unsigned p) +{ + static struct { char __attribute__((__aligned__(ALIGNMENT))) c; } s; + unsigned x; + + assert(__alignof__(s) == ALIGNMENT); + asm ("" : "=g" (x), "+m" (s) : "0" (&x)); + + return n ? test(n - 1, x) : (x ^ p); +} + +int main (int argc, char *argv[] __attribute__((unused))) +{ + unsigned int x = test(argc, 0); + + x |= test(argc + 1, 0); + x |= test(argc + 2, 0); + + return !(x & (ALIGNMENT - 1)); +}