Message ID | 20160208055538.GI22967@bubble.grove.modra.org |
---|---|
State | New |
Headers | show |
On 02/07/2016 10:55 PM, Alan Modra wrote: > This test was added by git commit 7c5f55675 (svn 231569) > > Here's the log message from that commit: > 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. > > However, the test assumes that a local var will normally not be 64-bit > aligned, causing it to fail on many targets. So the test needs to > pass if the local var *is* normally 64-bit aligned. Done as follows. > test2() is a duplicate of test() without the alignment on the static > vars. Fails on x86_64 -m64 and -m32 if 7c5f55675 is reverted and > passes now for powerpc64-linux. I expect sparc will pass too, so have > reverted Eric's change. > > OK to apply? > > PR testsuite/68886 > * gcc.c-torture/execute/stkalign.c: Revise test. OK. jeff
diff --git a/gcc/testsuite/gcc.c-torture/execute/stkalign.c b/gcc/testsuite/gcc.c-torture/execute/stkalign.c index 2f8d041..e10a1d2 100644 --- a/gcc/testsuite/gcc.c-torture/execute/stkalign.c +++ b/gcc/testsuite/gcc.c-torture/execute/stkalign.c @@ -1,5 +1,6 @@ -/* { dg-xfail-run-if "invalid assumption" { sparc*-*-* && lp64 } "*" "" } */ /* { dg-options "-fno-inline" } */ +/* Check that stack alignment is not affected by variables not placed + on the stack. */ #include <assert.h> @@ -16,12 +17,28 @@ unsigned test(unsigned n, unsigned p) return n ? test(n - 1, x) : (x ^ p); } +unsigned test2(unsigned n, unsigned p) +{ + static struct { char c; } s; + unsigned x; + + assert(__alignof__(s) != ALIGNMENT); + asm ("" : "=g" (x), "+m" (s) : "0" (&x)); + + return n ? test2(n - 1, x) : (x ^ p); +} + int main (int argc, char *argv[] __attribute__((unused))) { - unsigned int x = test(argc, 0); + unsigned int x, y; + x = test(argc, 0); x |= test(argc + 1, 0); x |= test(argc + 2, 0); - return !(x & (ALIGNMENT - 1)); + y = test2(argc, 0); + y |= test2(argc + 1, 0); + y |= test2(argc + 2, 0); + + return (x & (ALIGNMENT - 1)) == 0 && (y & (ALIGNMENT - 1)) != 0 ? 1 : 0; }