From: Tom Tromey Date: Mon, 8 Mar 2021 14:27:57 +0000 (-0700) Subject: Split out eval_op_alignof X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=acee94686be0601a096c5d6e09c531c41318a429;p=binutils-gdb.git Split out eval_op_alignof This splits UNOP_ALIGNOF into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey * eval.c (eval_op_alignof): New function. (evaluate_subexp_standard): Use it. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 794b88343d2..1bfac7eab26 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-03-08 Tom Tromey + + * eval.c (eval_op_alignof): New function. + (evaluate_subexp_standard): Use it. + 2021-03-08 Tom Tromey * eval.c (eval_op_ind): New function. diff --git a/gdb/eval.c b/gdb/eval.c index e1e0e05149f..729933f29a9 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1878,6 +1878,22 @@ eval_op_ind (struct type *expect_type, struct expression *exp, return value_ind (arg1); } +/* A helper function for UNOP_ALIGNOF. */ + +static struct value * +eval_op_alignof (struct type *expect_type, struct expression *exp, + enum noside noside, + struct value *arg1) +{ + struct type *type = value_type (arg1); + /* FIXME: This should be size_t. */ + struct type *size_type = builtin_type (exp->gdbarch)->builtin_int; + ULONGEST align = type_align (type); + if (align == 0) + error (_("could not determine alignment of type")); + return value_from_longest (size_type, align); +} + struct value * evaluate_subexp_standard (struct type *expect_type, struct expression *exp, int *pos, @@ -2769,16 +2785,8 @@ evaluate_subexp_standard (struct type *expect_type, return evaluate_subexp_for_sizeof (exp, pos, noside); case UNOP_ALIGNOF: - { - type = value_type ( - evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS)); - /* FIXME: This should be size_t. */ - struct type *size_type = builtin_type (exp->gdbarch)->builtin_int; - ULONGEST align = type_align (type); - if (align == 0) - error (_("could not determine alignment of type")); - return value_from_longest (size_type, align); - } + arg1 = evaluate_subexp (nullptr, exp, pos, EVAL_AVOID_SIDE_EFFECTS); + return eval_op_alignof (expect_type, exp, noside, arg1); case UNOP_CAST: (*pos) += 2;