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/c-exp.y | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'gdb/c-exp.y') diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 9e2f808..3cee544 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -173,7 +173,7 @@ static void c_print_token (FILE *file, int type, YYSTYPE value); %token NAME_OR_INT %token OPERATOR -%token STRUCT CLASS UNION ENUM SIZEOF UNSIGNED COLONCOLON +%token STRUCT CLASS UNION ENUM SIZEOF ALIGNOF UNSIGNED COLONCOLON %token TEMPLATE %token ERROR %token NEW DELETE @@ -307,6 +307,10 @@ exp : SIZEOF exp %prec UNARY { write_exp_elt_opcode (pstate, UNOP_SIZEOF); } ; +exp : ALIGNOF '(' type_exp ')' %prec UNARY + { write_exp_elt_opcode (pstate, UNOP_ALIGNOF); } + ; + exp : exp ARROW name { write_exp_elt_opcode (pstate, STRUCTOP_PTR); write_exp_string (pstate, $3); @@ -2329,6 +2333,8 @@ static const struct token ident_tokens[] = {"struct", STRUCT, OP_NULL, 0}, {"signed", SIGNED_KEYWORD, OP_NULL, 0}, {"sizeof", SIZEOF, OP_NULL, 0}, + {"_Alignof", ALIGNOF, OP_NULL, 0}, + {"alignof", ALIGNOF, OP_NULL, FLAG_CXX}, {"double", DOUBLE_KEYWORD, OP_NULL, 0}, {"false", FALSEKEYWORD, OP_NULL, FLAG_CXX}, {"class", CLASS, OP_NULL, FLAG_CXX}, -- cgit v1.1