* expr.c (highest_pow2_factor_for_type): Rename into
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Mar 2004 06:48:51 +0000 (06:48 +0000)
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Mar 2004 06:48:51 +0000 (06:48 +0000)
highest_pow2_factor_for_target.  Use DECL_ALIGN instead of
TYPE_ALIGN when the target is a COMPONENT_REF.
(expand_assignment): Ajust call to highest_pow2_factor_for_type.

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

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20040308-1.c [new file with mode: 0644]

index 0ca4fbf..f080f05 100644 (file)
@@ -1,3 +1,10 @@
+2004-03-08  Eric Botcazou  <ebotcazou@act-europe.fr>
+
+       * expr.c (highest_pow2_factor_for_type): Rename into
+       highest_pow2_factor_for_target.  Use DECL_ALIGN instead of
+       TYPE_ALIGN when the target is a COMPONENT_REF.
+       (expand_assignment): Ajust call to highest_pow2_factor_for_type.
+
 2004-03-08  Alan Modra  <amodra@bigpond.net.au>
 
        * config/rs6000/rs6000.c: Formatting fix.
index 9bd2740..d526750 100644 (file)
@@ -156,7 +156,7 @@ static rtx store_field (rtx, HOST_WIDE_INT, HOST_WIDE_INT, enum machine_mode,
 static rtx var_rtx (tree);
 
 static unsigned HOST_WIDE_INT highest_pow2_factor (tree);
-static unsigned HOST_WIDE_INT highest_pow2_factor_for_type (tree, tree);
+static unsigned HOST_WIDE_INT highest_pow2_factor_for_target (tree, tree);
 
 static int is_aligning_offset (tree, tree);
 static rtx expand_increment (tree, int, int);
@@ -3800,8 +3800,8 @@ expand_assignment (tree to, tree from, int want_value)
            }
 
          to_rtx = offset_address (to_rtx, offset_rtx,
-                                  highest_pow2_factor_for_type (TREE_TYPE (to),
-                                                                offset));
+                                  highest_pow2_factor_for_target (to,
+                                                                  offset));
        }
 
       if (GET_CODE (to_rtx) == MEM)
@@ -6049,17 +6049,22 @@ highest_pow2_factor (tree exp)
   return 1;
 }
 
-/* Similar, except that it is known that the expression must be a multiple
-   of the alignment of TYPE.  */
+/* Similar, except that the alignment requirements of TARGET are
+   taken into account.  Assume it is at least as aligned as its
+   type, unless it is a COMPONENT_REF in which case the layout of
+   the structure gives the alignment.  */
 
 static unsigned HOST_WIDE_INT
-highest_pow2_factor_for_type (tree type, tree exp)
+highest_pow2_factor_for_target (tree target, tree exp)
 {
-  unsigned HOST_WIDE_INT type_align, factor;
+  unsigned HOST_WIDE_INT target_align, factor;
 
   factor = highest_pow2_factor (exp);
-  type_align = TYPE_ALIGN (type) / BITS_PER_UNIT;
-  return MAX (factor, type_align);
+  if (TREE_CODE (target) == COMPONENT_REF)
+    target_align = DECL_ALIGN (TREE_OPERAND (target, 1)) / BITS_PER_UNIT;
+  else
+    target_align = TYPE_ALIGN (TREE_TYPE (target)) / BITS_PER_UNIT;
+  return MAX (factor, target_align);
 }
 \f
 /* Return an object on the placeholder list that matches EXP, a
index 99035b4..57c2eda 100644 (file)
@@ -1,3 +1,7 @@
+2004-03-08  Eric Botcazou  <ebotcazou@act-europe.fr>
+
+       * gcc.c-torture/execute/20040308-1.c: New test.
+
 2004-03-07  Roger Sayle  <roger@eyesopen.com>
 
        * gcc.c-torture/execute/20040307-1.c: New test case.
diff --git a/gcc/testsuite/gcc.c-torture/execute/20040308-1.c b/gcc/testsuite/gcc.c-torture/execute/20040308-1.c
new file mode 100644 (file)
index 0000000..4c63535
--- /dev/null
@@ -0,0 +1,21 @@
+/* This used to fail on SPARC with an unaligned memory access.  */
+
+void foo(int n)
+{
+  struct S {
+    int i[n];
+    unsigned int b:1;
+    int i2;
+  } __attribute__ ((packed)) __attribute__ ((aligned (4)));
+
+  struct S s;
+
+  s.i2 = 0;
+}
+
+int main(void)
+{
+  foo(4);
+  
+  return 0;
+}