From 007e1530347330d4dbba387c4e35aae05bc06498 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 20 Apr 2018 13:40:29 -0600 Subject: Handle alignof and _Alignof This adds alignof and _Alignof to the C/C++ expression parser, and adds new tests to test the features. The tests are written to try to ensure that gdb's knowledge of alignment rules stays in sync with the compiler's. 2018-04-30 Tom Tromey PR exp/17095: * NEWS: Update. * std-operator.def (UNOP_ALIGNOF): New operator. * expprint.c (dump_subexp_body_standard) : New. * eval.c (evaluate_subexp_standard) : New. * c-lang.c (c_op_print_tab): Add alignof. * c-exp.y (ALIGNOF): New token. (exp): Add "ALIGNOF" production. (ident_tokens): Add _Alignof and alignof. 2018-04-30 Tom Tromey PR exp/17095: * gdb.dwarf2/dw2-align.exp: New file. * gdb.cp/align.exp: New file. * gdb.base/align.exp: New file. * lib/gdb.exp (gdb_int128_helper): New proc. (has_int128_c, has_int128_cxx): New caching procs. --- gdb/eval.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'gdb/eval.c') diff --git a/gdb/eval.c b/gdb/eval.c index ad66f7c..2fdfdf9 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2667,6 +2667,19 @@ evaluate_subexp_standard (struct type *expect_type, } return evaluate_subexp_for_sizeof (exp, pos, noside); + case UNOP_ALIGNOF: + { + struct type *type + = value_type (evaluate_subexp (NULL_TYPE, 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); + } + case UNOP_CAST: (*pos) += 2; type = exp->elts[pc + 1].type; -- cgit v1.1