OSDN Git Service

2006-03-10 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 10 Mar 2006 16:44:01 +0000 (16:44 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 10 Mar 2006 16:44:01 +0000 (16:44 +0000)
PR middle-end/26565
* builtins.c (get_pointer_alignment): Handle component
references for field alignment.

* gcc.dg/torture/pr26565.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111934 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr26565.c [new file with mode: 0644]

index d1f4a0c..77ce19e 100644 (file)
@@ -1,3 +1,9 @@
+2006-03-10  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/26565
+       * builtins.c (get_pointer_alignment): Handle component
+       references for field alignment.
+
 2006-03-10  J"orn Rennecke <joern.rennecke@st.com>
 
        * config.gcc (sh*-superh-elf, sh*elf (newlib)): Use newlib.h
index f6095e8..1ce6083 100644 (file)
@@ -275,15 +275,21 @@ get_pointer_alignment (tree exp, unsigned int max_align)
        case ADDR_EXPR:
          /* See what we are pointing at and look at its alignment.  */
          exp = TREE_OPERAND (exp, 0);
+         while (handled_component_p (exp))
+           {
+             if (TREE_CODE (exp) == COMPONENT_REF)
+               align = MIN (align, DECL_ALIGN (TREE_OPERAND (exp, 1)));
+             exp = TREE_OPERAND (exp, 0);
+           }
          if (TREE_CODE (exp) == FUNCTION_DECL)
-           align = FUNCTION_BOUNDARY;
+           align = MIN (align, FUNCTION_BOUNDARY);
          else if (DECL_P (exp))
-           align = DECL_ALIGN (exp);
+           align = MIN (align, DECL_ALIGN (exp));
 #ifdef CONSTANT_ALIGNMENT
          else if (CONSTANT_CLASS_P (exp))
-           align = CONSTANT_ALIGNMENT (exp, align);
+           align = MIN (align, (unsigned)CONSTANT_ALIGNMENT (exp, align));
 #endif
-         return MIN (align, max_align);
+         return align;
 
        default:
          return align;
index d8890a0..4c47054 100644 (file)
@@ -1,3 +1,8 @@
+2006-03-10  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/26565
+       * gcc.dg/torture/pr26565.c: New testcase.
+
 2006-03-09  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        PR libgfortran/26499
diff --git a/gcc/testsuite/gcc.dg/torture/pr26565.c b/gcc/testsuite/gcc.dg/torture/pr26565.c
new file mode 100644 (file)
index 0000000..9b43140
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+void *memcpy(void *dest, const void *src, __SIZE_TYPE__ n);
+
+struct timeval {
+    long tv_sec;
+};
+
+struct outdata {
+    long align;
+    char seq;
+    struct timeval tv __attribute__((packed));
+};
+
+void send_probe(struct outdata *outdata, struct timeval *tp) __attribute__((noinline));
+void send_probe(struct outdata *outdata, struct timeval *tp)
+{
+    memcpy(&outdata->tv, tp, sizeof outdata->tv);
+}
+
+struct timeval t;
+struct outdata outdata;
+
+int main()
+{
+  send_probe(&outdata, &t);
+  return 0;
+}