Commit 09a1e889 by Shujing Zhao Committed by Shujing Zhao

re PR c/44517 (improve diagnostic for mispelled typename in function declaration)

gcc/
2010-06-25  Shujing Zhao  <pearly.zhao@oracle.com>

        PR c/44517
        * c-parser.c (c_parser_parms_list_declarator): Return NULL if one of
        parameters are not good.
        (c_parser_parameter_declaration): Error unknown type name if the type
        name can't start declaration specifiers.

gcc/testsuite/
2010-06-25  Shujing Zhao  <pearly.zhao@oracle.com>

        PR c/44517
        * gcc.dg/noncompile/pr44517.c: New.
        * gcc.dg/noncompile/990416-1.c: Adjust expected error.

From-SVN: r161363
parent 418f840c
2010-06-25 Shujing Zhao <pearly.zhao@oracle.com>
PR c/44517
* c-parser.c (c_parser_parms_list_declarator): Return NULL if one of
parameters are not good.
(c_parser_parameter_declaration): Error unknown type name if the type
name can't start declaration specifiers.
2010-06-25 Joseph Myers <joseph@codesourcery.com> 2010-06-25 Joseph Myers <joseph@codesourcery.com>
* gcc.c (translate_options): Don't mention +e in comment. * gcc.c (translate_options): Don't mention +e in comment.
......
...@@ -2706,7 +2706,7 @@ c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs) ...@@ -2706,7 +2706,7 @@ c_parser_parms_declarator (c_parser *parser, bool id_list_ok, tree attrs)
static struct c_arg_info * static struct c_arg_info *
c_parser_parms_list_declarator (c_parser *parser, tree attrs) c_parser_parms_list_declarator (c_parser *parser, tree attrs)
{ {
bool good_parm = false; bool bad_parm = false;
/* ??? Following the old parser, forward parameter declarations may /* ??? Following the old parser, forward parameter declarations may
use abstract declarators, and if no real parameter declarations use abstract declarators, and if no real parameter declarations
follow the forward declarations then this is not diagnosed. Also follow the forward declarations then this is not diagnosed. Also
...@@ -2758,11 +2758,10 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ...@@ -2758,11 +2758,10 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
/* Parse a parameter. */ /* Parse a parameter. */
struct c_parm *parm = c_parser_parameter_declaration (parser, attrs); struct c_parm *parm = c_parser_parameter_declaration (parser, attrs);
attrs = NULL_TREE; attrs = NULL_TREE;
if (parm != NULL) if (parm == NULL)
{ bad_parm = true;
good_parm = true; else
push_parm_decl (parm); push_parm_decl (parm);
}
if (c_parser_next_token_is (parser, CPP_SEMICOLON)) if (c_parser_next_token_is (parser, CPP_SEMICOLON))
{ {
tree new_attrs; tree new_attrs;
...@@ -2774,20 +2773,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ...@@ -2774,20 +2773,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
{ {
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (good_parm) if (bad_parm)
return get_parm_info (false);
else
{ {
struct c_arg_info *ret get_pending_sizes ();
= XOBNEW (&parser_obstack, struct c_arg_info); return NULL;
ret->parms = 0;
ret->tags = 0;
ret->types = 0;
ret->others = 0;
ret->pending_sizes = 0;
ret->had_vla_unspec = 0;
return ret;
} }
else
return get_parm_info (false);
} }
if (!c_parser_require (parser, CPP_COMMA, if (!c_parser_require (parser, CPP_COMMA,
"expected %<;%>, %<,%> or %<)%>")) "expected %<;%>, %<,%> or %<)%>"))
...@@ -2802,20 +2794,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs) ...@@ -2802,20 +2794,13 @@ c_parser_parms_list_declarator (c_parser *parser, tree attrs)
if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN)) if (c_parser_next_token_is (parser, CPP_CLOSE_PAREN))
{ {
c_parser_consume_token (parser); c_parser_consume_token (parser);
if (good_parm) if (bad_parm)
return get_parm_info (true);
else
{ {
struct c_arg_info *ret get_pending_sizes ();
= XOBNEW (&parser_obstack, struct c_arg_info); return NULL;
ret->parms = 0;
ret->tags = 0;
ret->types = 0;
ret->others = 0;
ret->pending_sizes = 0;
ret->had_vla_unspec = 0;
return ret;
} }
else
return get_parm_info (true);
} }
else else
{ {
...@@ -2841,10 +2826,22 @@ c_parser_parameter_declaration (c_parser *parser, tree attrs) ...@@ -2841,10 +2826,22 @@ c_parser_parameter_declaration (c_parser *parser, tree attrs)
bool dummy = false; bool dummy = false;
if (!c_parser_next_token_starts_declspecs (parser)) if (!c_parser_next_token_starts_declspecs (parser))
{ {
c_token *token = c_parser_peek_token (parser);
if (parser->error)
return NULL;
c_parser_set_source_position_from_token (token);
if (token->type == CPP_NAME
&& c_parser_peek_2nd_token (parser)->type != CPP_COMMA
&& c_parser_peek_2nd_token (parser)->type != CPP_CLOSE_PAREN)
{
error ("unknown type name %qE", token->value);
parser->error = true;
}
/* ??? In some Objective-C cases '...' isn't applicable so there /* ??? In some Objective-C cases '...' isn't applicable so there
should be a different message. */ should be a different message. */
c_parser_error (parser, else
"expected declaration specifiers or %<...%>"); c_parser_error (parser,
"expected declaration specifiers or %<...%>");
c_parser_skip_to_end_of_parameter (parser); c_parser_skip_to_end_of_parameter (parser);
return NULL; return NULL;
} }
......
2010-06-25 Shujing Zhao <pearly.zhao@oracle.com>
PR c/44517
* gcc.dg/noncompile/pr44517.c: New.
* gcc.dg/noncompile/990416-1.c: Adjust expected error.
2010-06-24 Steve Ellcey <sje@cup.hp.com> 2010-06-24 Steve Ellcey <sje@cup.hp.com>
PR testsuite/43283 PR testsuite/43283
......
...@@ -2,11 +2,11 @@ extern void *memcpy (void *, const void *, __SIZE_TYPE__); ...@@ -2,11 +2,11 @@ extern void *memcpy (void *, const void *, __SIZE_TYPE__);
typedef int word_type; typedef int word_type;
static void static void
copy_reg (unsigned int reg, frame_state *udata, /* { dg-error "parse|syntax|expected" } */ copy_reg (unsigned int reg, frame_state *udata, /* { dg-error "unknown type name" } */
frame_state *target_udata) /* { dg-error "expected" } */ frame_state *target_udata) /* { dg-error "unknown type name" } */
{ {
word_type *preg = get_reg_addr (reg, udata, 0); /* { dg-error "undeclared|function|without a cast" } */ word_type *preg = ge_reg_addr (reg, udata, 0);
word_type *ptreg = get_reg_addr (reg, target_udata, 0); /* { dg-error "undeclared|without a cast" } */ word_type *ptreg = ge_reg_addr (reg, target_udata, 0);
memcpy (ptreg, preg, __builtin_dwarf_reg_size (reg)); memcpy (ptreg, preg, __builtin_dwarf_reg_size (reg));
} }
/* PR c/44517: Improve diagnostic for misspelled typename in function declaration. */
int f1(int x, pid_t y, long z, in t) {
/* { dg-error "unknown type name 'pid_t'" "" { target *-*-* } 2 } */
/* { dg-error "unknown type name 'in'" "" { target *-*-* } 2 } */
return x + y + z + t;
}
int f2(int x, lon y, long z, ...){ /* { dg-error "unknown type name 'lon'" } */
return;
}
void f3(int n, int a[n], pid_t x); /* { dg-error "unknown type name 'pid_t'" } */
void f4() {}
void f5(int a, *b); /* { dg-error "expected declaration specifiers or" } */
void f6(int a, b); /* { dg-error "expected declaration specifiers or" } */
void f7(int a, goto b); /* { dg-error "expected declaration specifiers or" } */
void f8(int a, in goto); /* { dg-error "unknown type name 'in'" } */
void f9(int a, in 1); /* { dg-error "unknown type name 'in'" } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment