summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-07-20 08:31:26 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2012-07-20 08:31:26 +0000
commit4083990a79c25e1699dbb815bc1a7afcff51a382 (patch)
tree0186cf52294cb90d2959dc4e34f45c417db61a60
parentc6092377a1db71be8e3a1f22caea143953d84f36 (diff)
downloadgcc-4083990a79c25e1699dbb815bc1a7afcff51a382.tar.gz
2012-07-20 Richard Guenther <rguenther@suse.de>
* builtins.c (get_object_alignment_2): Correct offset handling when using type alignment of a MEM_REF kind base. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@189704 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/builtins.c22
2 files changed, 20 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 16cb34dcdff..2c4c2735823 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-20 Richard Guenther <rguenther@suse.de>
+
+ * builtins.c (get_object_alignment_2): Correct offset handling
+ when using type alignment of a MEM_REF kind base.
+
2012-07-20 Kirill Yukhin <kirill.yukhin@intel.com>
PR target/53877
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 4fb3d53aa58..a8318e8f3fd 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -346,12 +346,10 @@ get_object_alignment_2 (tree exp, unsigned int *alignp,
known_alignment
= get_pointer_alignment_1 (addr, &ptr_align, &ptr_bitpos);
- bitpos += ptr_bitpos;
align = MAX (ptr_align, align);
- if (TREE_CODE (exp) == MEM_REF
- || TREE_CODE (exp) == TARGET_MEM_REF)
- bitpos += mem_ref_offset (exp).low * BITS_PER_UNIT;
+ /* The alignment of the pointer operand in a TARGET_MEM_REF
+ has to take the variable offset parts into account. */
if (TREE_CODE (exp) == TARGET_MEM_REF)
{
if (TMR_INDEX (exp))
@@ -369,9 +367,19 @@ get_object_alignment_2 (tree exp, unsigned int *alignp,
/* When EXP is an actual memory reference then we can use
TYPE_ALIGN of a pointer indirection to derive alignment.
Do so only if get_pointer_alignment_1 did not reveal absolute
- alignment knowledge. */
- if (!addr_p && !known_alignment)
- align = MAX (TYPE_ALIGN (TREE_TYPE (exp)), align);
+ alignment knowledge and if using that alignment would
+ improve the situation. */
+ if (!addr_p && !known_alignment
+ && TYPE_ALIGN (TREE_TYPE (exp)) > align)
+ align = TYPE_ALIGN (TREE_TYPE (exp));
+ else
+ {
+ /* Else adjust bitpos accordingly. */
+ bitpos += ptr_bitpos;
+ if (TREE_CODE (exp) == MEM_REF
+ || TREE_CODE (exp) == TARGET_MEM_REF)
+ bitpos += mem_ref_offset (exp).low * BITS_PER_UNIT;
+ }
}
else if (TREE_CODE (exp) == STRING_CST)
{