This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: PR c/34921 Misalign stack variable referenced by nested function


Alignment of structure type for nested function is not copied from it's
field.

gcc/
2008-01-22  Joey Ye  <joey.ye@intel.com>

	* tree-nested.c (insert_field_into_struct): Set type alignment
	to field alignment if the former is less than the latter.

gcc/testsuite/
2008-01-22  Joey Ye  <joey.ye@intel.com>

	* gcc.dg/nested-func-align.c: New test case.

Thanks - Joey

Index: gcc/tree-nested.c
===================================================================
--- gcc/tree-nested.c	(revision 131342)
+++ gcc/tree-nested.c	(working copy)
@@ -183,6 +183,10 @@
 
   TREE_CHAIN (field) = *p;
   *p = field;
+
+  /* Set correct alignment for frame struct type */
+  if (TYPE_ALIGN (type) < DECL_ALIGN (field))
+    TYPE_ALIGN (type) = DECL_ALIGN (field);
 }
 
 /* Build or return the RECORD_TYPE that describes the frame state that
is
Index: gcc/testsuite/gcc.dg/nested-func-align.c
===================================================================
--- gcc/testsuite/gcc.dg/nested-func-align.c	(revision 0)
+++ gcc/testsuite/gcc.dg/nested-func-align.c	(revision 0)
@@ -0,0 +1,42 @@
+/* Test for alignment handling when a variable is accessed by nested
function.
+   */
+/* Origin: Joey Ye <joey.ye@intel.com> */
+/* { dg-options "" } */
+
+#include <stdio.h>
+#include <stdlib.h>
+typedef int aligned __attribute__((aligned(16)));
+int global;
+
+void
+check (int *i)
+{
+  *i = 20;
+  if ((((long) i) & (__alignof__(aligned) - 1)) != 0)
+    {
+      printf("\nUnalign address (%d): %p!\n",
+             __alignof__(aligned), i);
+      abort ();
+    }
+}
+
+void
+foo (void)
+{
+  aligned jj;
+  void bar ()
+    {
+      jj = -20;
+    }
+  jj = 0;
+  bar ();
+  check (&jj);
+}
+
+int
+main()
+{
+  foo ();
+  return 0;
+}
+


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]