aboutsummaryrefslogtreecommitdiff
path: root/gcc/ada/gcc-interface/utils.c
diff options
context:
space:
mode:
authorEric Botcazou <ebotcazou@adacore.com>2019-12-03 10:12:17 +0000
committerEric Botcazou <ebotcazou@gcc.gnu.org>2019-12-03 10:12:17 +0000
commitcbcf36686e215a8a4bb5e824f8d8e40226b79757 (patch)
tree37c7de8a67ad9294186af9bfd72b264bfa9b4c9a /gcc/ada/gcc-interface/utils.c
parentdd2dae9438ccebc83d561b375506cc3334acfa04 (diff)
downloadgcc-cbcf36686e215a8a4bb5e824f8d8e40226b79757.zip
gcc-cbcf36686e215a8a4bb5e824f8d8e40226b79757.tar.gz
gcc-cbcf36686e215a8a4bb5e824f8d8e40226b79757.tar.bz2
utils.c (fold_convert_size): New function.
* gcc-interface/utils.c (fold_convert_size): New function. (fold_bit_position): Invoke it to do further folding. From-SVN: r278929
Diffstat (limited to 'gcc/ada/gcc-interface/utils.c')
-rw-r--r--gcc/ada/gcc-interface/utils.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c
index e14645a..80c0716 100644
--- a/gcc/ada/gcc-interface/utils.c
+++ b/gcc/ada/gcc-interface/utils.c
@@ -2349,19 +2349,27 @@ merge_sizes (tree last_size, tree first_bit, tree size, bool special, bool max)
return new_size;
}
+/* Convert the size expression EXPR to TYPE and fold the result. */
+
+static tree
+fold_convert_size (tree type, tree expr)
+{
+ /* We assume that size expressions do not wrap around. */
+ if (TREE_CODE (expr) == MULT_EXPR || TREE_CODE (expr) == PLUS_EXPR)
+ return size_binop (TREE_CODE (expr),
+ fold_convert_size (type, TREE_OPERAND (expr, 0)),
+ fold_convert_size (type, TREE_OPERAND (expr, 1)));
+
+ return fold_convert (type, expr);
+}
+
/* Return the bit position of FIELD, in bits from the start of the record,
and fold it as much as possible. This is a tree of type bitsizetype. */
static tree
fold_bit_position (const_tree field)
{
- tree offset = DECL_FIELD_OFFSET (field);
- if (TREE_CODE (offset) == MULT_EXPR || TREE_CODE (offset) == PLUS_EXPR)
- offset = size_binop (TREE_CODE (offset),
- fold_convert (bitsizetype, TREE_OPERAND (offset, 0)),
- fold_convert (bitsizetype, TREE_OPERAND (offset, 1)));
- else
- offset = fold_convert (bitsizetype, offset);
+ tree offset = fold_convert_size (bitsizetype, DECL_FIELD_OFFSET (field));
return size_binop (PLUS_EXPR, DECL_FIELD_BIT_OFFSET (field),
size_binop (MULT_EXPR, offset, bitsize_unit_node));
}