From: Tom Tromey Date: Mon, 9 Jul 2012 14:20:52 +0000 (+0000) Subject: * c-exp.y (check_parameter_typelist): New function. X-Git-Tag: gdb_7_5-2012-07-18-branchpoint~63 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e314d62968dfb4ae82c70dbe68d9d4ec929deb7e;p=external%2Fbinutils.git * c-exp.y (check_parameter_typelist): New function. (parameter_typelist): Call it. * eval.c (make_params): Handle '(void)' case. * gdbtypes.c (lookup_function_type_with_arguments): Handle '(void)' case. testsuite * gdb.base/whatis.exp: Add error checks for improper 'void' uses. * gdb.base/callfuncs.exp: Add cast-based test. * gdb.base/callfuncs.c (voidfunc): New function. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index cab30f7..0d1c151 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2012-07-09 Tom Tromey + + * c-exp.y (check_parameter_typelist): New function. + (parameter_typelist): Call it. + * eval.c (make_params): Handle '(void)' case. + * gdbtypes.c (lookup_function_type_with_arguments): Handle + '(void)' case. + 2012-07-07 Jan Kratochvil * common/linux-ptrace.c: Include gdb_assert.h. diff --git a/gdb/c-exp.y b/gdb/c-exp.y index 14fd53d..0613799 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -165,6 +165,7 @@ void yyerror (char *); /* YYSTYPE gets defined by %union */ static int parse_number (char *, int, int, YYSTYPE *); static struct stoken operator_stoken (const char *); +static void check_parameter_typelist (VEC (type_ptr) *); %} %type exp exp1 type_exp start variable qualified_name lcurly @@ -1227,9 +1228,11 @@ typename: TYPENAME parameter_typelist: nonempty_typelist + { check_parameter_typelist ($1); } | nonempty_typelist ',' DOTDOTDOT { VEC_safe_push (type_ptr, $1, NULL); + check_parameter_typelist ($1); $$ = $1; } ; @@ -1444,6 +1447,37 @@ operator_stoken (const char *op) return st; }; +/* Validate a parameter typelist. */ + +static void +check_parameter_typelist (VEC (type_ptr) *params) +{ + struct type *type; + int ix; + + for (ix = 0; VEC_iterate (type_ptr, params, ix, type); ++ix) + { + if (type != NULL && TYPE_CODE (check_typedef (type)) == TYPE_CODE_VOID) + { + if (ix == 0) + { + if (VEC_length (type_ptr, params) == 1) + { + /* Ok. */ + break; + } + VEC_free (type_ptr, params); + error (_("parameter types following 'void'")); + } + else + { + VEC_free (type_ptr, params); + error (_("'void' invalid as parameter type")); + } + } + } +} + /* Take care of parsing a number (anything that starts with a digit). Set yylval and return the token type; update lexptr. LEN is the number of characters in it. */ diff --git a/gdb/eval.c b/gdb/eval.c index 13f997f..7d3a8b9 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -769,11 +769,23 @@ make_params (int num_types, struct type **param_types) TYPE_CODE (type) = TYPE_CODE_METHOD; TYPE_VPTR_FIELDNO (type) = -1; TYPE_CHAIN (type) = type; - if (num_types > 0 && param_types[num_types - 1] == NULL) + if (num_types > 0) { - --num_types; - TYPE_VARARGS (type) = 1; + if (param_types[num_types - 1] == NULL) + { + --num_types; + TYPE_VARARGS (type) = 1; + } + else if (TYPE_CODE (check_typedef (param_types[num_types - 1])) + == TYPE_CODE_VOID) + { + --num_types; + /* Caller should have ensured this. */ + gdb_assert (num_types == 0); + TYPE_PROTOTYPED (type) = 1; + } } + TYPE_NFIELDS (type) = num_types; TYPE_FIELDS (type) = (struct field *) TYPE_ZALLOC (type, sizeof (struct field) * num_types); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index cb25e71..8142ab9 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -474,10 +474,21 @@ lookup_function_type_with_arguments (struct type *type, struct type *fn = make_function_type (type, (struct type **) 0); int i; - if (nparams > 0 && param_types[nparams - 1] == NULL) + if (nparams > 0) { - --nparams; - TYPE_VARARGS (fn) = 1; + if (param_types[nparams - 1] == NULL) + { + --nparams; + TYPE_VARARGS (fn) = 1; + } + else if (TYPE_CODE (check_typedef (param_types[nparams - 1])) + == TYPE_CODE_VOID) + { + --nparams; + /* Caller should have ensured this. */ + gdb_assert (nparams == 0); + TYPE_PROTOTYPED (fn) = 1; + } } TYPE_NFIELDS (fn) = nparams; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index cb0918b..2f249a9 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2012-07-09 Tom Tromey + + * gdb.base/whatis.exp: Add error checks for improper 'void' uses. + * gdb.base/callfuncs.exp: Add cast-based test. + * gdb.base/callfuncs.c (voidfunc): New function. + 2012-07-08 Doug Evans * gdb.dwarf2/dw4-sig-type-unused.S: Fix typo. diff --git a/gdb/testsuite/gdb.base/callfuncs.c b/gdb/testsuite/gdb.base/callfuncs.c index b4ab7d5..7fb5061 100644 --- a/gdb/testsuite/gdb.base/callfuncs.c +++ b/gdb/testsuite/gdb.base/callfuncs.c @@ -641,6 +641,13 @@ struct struct_with_fnptr function_struct = { doubleit }; struct struct_with_fnptr *function_struct_ptr = &function_struct; +int * +voidfunc (void) +{ + static int twentythree = 23; + return &twentythree; +} + /* Gotta have a main to be able to generate a linked, runnable executable, and also provide a useful place to set a breakpoint. */ diff --git a/gdb/testsuite/gdb.base/callfuncs.exp b/gdb/testsuite/gdb.base/callfuncs.exp index 66abee9..daaad1a 100644 --- a/gdb/testsuite/gdb.base/callfuncs.exp +++ b/gdb/testsuite/gdb.base/callfuncs.exp @@ -539,3 +539,6 @@ if {![target_info exists gdb,nosignals] && ![istarget "*-*-uclinux*"]} { # handling vs. local labels `.L'... as `Lcallfunc' starts with `L'. gdb_test "print callfunc (Lcallfunc, 5)" " = 12" + +# Regression test for function pointer cast. +gdb_test "print *((int *(*) (void)) voidfunc)()" " = 23" diff --git a/gdb/testsuite/gdb.base/whatis.exp b/gdb/testsuite/gdb.base/whatis.exp index 9365485..18edc4c 100644 --- a/gdb/testsuite/gdb.base/whatis.exp +++ b/gdb/testsuite/gdb.base/whatis.exp @@ -499,3 +499,11 @@ gdb_test "whatis int (*)(int, int)" \ gdb_test "whatis int (*)(const int *, ...)" \ "type = int \\(\\*\\)\\(const int \\*, \\.\\.\\.\\)" \ "whatis applied to pointer to function taking const int ptr and varargs and returning int" + +gdb_test "whatis int (*)(void, int, int)" \ + "parameter types following 'void'" \ + "whatis applied to function with types trailing 'void'" + +gdb_test "whatis int (*)(int, void, int)" \ + "'void' invalid as parameter type" \ + "whatis applied to function with 'void' parameter type"