public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Correct c-torture stkalign test
@ 2016-02-08  5:55 Alan Modra
  2016-02-12 18:02 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Modra @ 2016-02-08  5:55 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jan Hubicka, Eric Botcazou

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.

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;
 }

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Correct c-torture stkalign test
  2016-02-08  5:55 Correct c-torture stkalign test Alan Modra
@ 2016-02-12 18:02 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2016-02-12 18:02 UTC (permalink / raw)
  To: Alan Modra, gcc-patches; +Cc: Jan Hubicka, Eric Botcazou

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-12 18:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-08  5:55 Correct c-torture stkalign test Alan Modra
2016-02-12 18:02 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).