]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/26565 (Unaligned accesses with __attribute__(packed) and memcpy)
authorRichard Guenther <rguenther@suse.de>
Mon, 1 May 2006 12:04:13 +0000 (12:04 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 1 May 2006 12:04:13 +0000 (12:04 +0000)
2006-05-01  Richard Guenther  <rguenther@suse.de>

PR middle-end/26565
* builtins.c (get_pointer_alignment): Handle component
references for field alignment.

From-SVN: r113411

gcc/ChangeLog
gcc/builtins.c

index 16a7906e136dad0ae77a278327ff0224cf2a2648..6150d5c8714f8761d74a71c4fafb2b3af2841707 100644 (file)
@@ -1,3 +1,9 @@
+2006-05-01  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/26565
+       * builtins.c (get_pointer_alignment): Handle component
+       references for field alignment.
+
 2006-04-25  Roger Sayle  <roger@eyesopen.com>
 
        PR target/26961
index a92f0104af46eccf675b3b1838ddf45299930551..62458c3923a445b171f55612002260ca01bba701 100644 (file)
@@ -249,14 +249,28 @@ 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);
+         inner = max_align;
+         while (handled_component_p (exp))
+           {
+             /* Fields in a structure can be packed, honour DECL_ALIGN
+                of the FIELD_DECL.  For all other references the conservative 
+                alignment is the element type alignment.  */
+             if (TREE_CODE (exp) == COMPONENT_REF)
+               inner = MIN (inner, DECL_ALIGN (TREE_OPERAND (exp, 1)));
+             else
+               inner = MIN (inner, TYPE_ALIGN (TREE_TYPE (exp)));
+             exp = TREE_OPERAND (exp, 0);
+           }
          if (TREE_CODE (exp) == FUNCTION_DECL)
            align = FUNCTION_BOUNDARY;
          else if (DECL_P (exp))
-           align = DECL_ALIGN (exp);
+           align = MIN (inner, DECL_ALIGN (exp));
 #ifdef CONSTANT_ALIGNMENT
          else if (CONSTANT_CLASS_P (exp))
-           align = CONSTANT_ALIGNMENT (exp, align);
+           align = MIN (inner, (unsigned)CONSTANT_ALIGNMENT (exp, align));
 #endif
+         else
+           align = MIN (align, inner);
          return MIN (align, max_align);
 
        default: