summaryrefslogtreecommitdiff
path: root/gcc/builtins.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2011-04-14 12:07:57 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2011-04-14 12:07:57 +0000
commit0c883ef3de95b2304dcc490559cf646ff927d225 (patch)
tree8d1c24f7892e87a4ef9d15d2ffc7a8758db7b114 /gcc/builtins.c
parentbd5ba09ffaca7ff99fa2dedc8bcfb504ec08ec5d (diff)
downloadgcc-0c883ef3de95b2304dcc490559cf646ff927d225.tar.gz
2011-04-14 Richard Guenther <rguenther@suse.de>
* tree.h (get_object_alignment_1): Declare. * builtins.c (get_object_alignment_1): Split out worker from ... (get_object_alignment): ... here. * fold-const.c (get_pointer_modulus_and_residue): Use get_object_alignment_1. * gcc.dg/fold-bitand-4.c: Move ... * c-c++-common/fold-bitand-4.c: ... here. Adjust slightly. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@172424 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r--gcc/builtins.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 7ae3833163a..81f7ec6bdc1 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -268,7 +268,7 @@ called_as_built_in (tree node)
Don't return more than MAX_ALIGN no matter what. */
unsigned int
-get_object_alignment (tree exp, unsigned int max_align)
+get_object_alignment_1 (tree exp, unsigned HOST_WIDE_INT *bitposp)
{
HOST_WIDE_INT bitsize, bitpos;
tree offset;
@@ -320,8 +320,7 @@ get_object_alignment (tree exp, unsigned int max_align)
align = MAX (pi->align * BITS_PER_UNIT, align);
}
else if (TREE_CODE (addr) == ADDR_EXPR)
- align = MAX (align, get_object_alignment (TREE_OPERAND (addr, 0),
- max_align));
+ align = MAX (align, get_object_alignment (TREE_OPERAND (addr, 0), ~0U));
bitpos += mem_ref_offset (exp).low * BITS_PER_UNIT;
}
else if (TREE_CODE (exp) == TARGET_MEM_REF)
@@ -345,8 +344,7 @@ get_object_alignment (tree exp, unsigned int max_align)
align = MAX (pi->align * BITS_PER_UNIT, align);
}
else if (TREE_CODE (addr) == ADDR_EXPR)
- align = MAX (align, get_object_alignment (TREE_OPERAND (addr, 0),
- max_align));
+ align = MAX (align, get_object_alignment (TREE_OPERAND (addr, 0), ~0U));
if (TMR_OFFSET (exp))
bitpos += TREE_INT_CST_LOW (TMR_OFFSET (exp)) * BITS_PER_UNIT;
if (TMR_INDEX (exp) && TMR_STEP (exp))
@@ -364,7 +362,7 @@ get_object_alignment (tree exp, unsigned int max_align)
/* If there is a non-constant offset part extract the maximum
alignment that can prevail. */
- inner = max_align;
+ inner = ~0U;
while (offset)
{
tree next_offset;
@@ -411,6 +409,21 @@ get_object_alignment (tree exp, unsigned int max_align)
align = MIN (align, inner);
bitpos = bitpos & (align - 1);
+ *bitposp = bitpos;
+ return align;
+}
+
+/* Return the alignment in bits of EXP, an object.
+ Don't return more than MAX_ALIGN no matter what. */
+
+unsigned int
+get_object_alignment (tree exp, unsigned int max_align)
+{
+ unsigned HOST_WIDE_INT bitpos = 0;
+ unsigned int align;
+
+ align = get_object_alignment_1 (exp, &bitpos);
+
/* align and bitpos now specify known low bits of the pointer.
ptr & (align - 1) == bitpos. */