From: Marek Polacek Date: Fri, 13 Nov 2015 14:05:59 +0000 (+0000) Subject: re PR c/68320 (internal compiler error: in declspecs_add_type) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ec8b536ffd7056c0f82c309da713352e6e4deed5;p=gcc.git re PR c/68320 (internal compiler error: in declspecs_add_type) PR c/68320 * c-parser.c (c_parser_for_statement): Treat unknown tokens as IDs. * gcc.dg/pr68320.c: New test. From-SVN: r230322 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9b1fdc9343d..8824f1845cb 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2015-11-13 Marek Polacek + + PR c/68320 + * c-parser.c (c_parser_for_statement): Treat unknown tokens as IDs. + 2015-11-13 David Malcolm * c-typeck.c: Include spellcheck.h. diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index c01d651b297..82d5ce5f9ff 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -5757,12 +5757,12 @@ c_parser_for_statement (c_parser *parser, bool ivdep) { c_token *token = c_parser_peek_token (parser); tree decl = lookup_name (token->value); - if (decl == NULL_TREE) - ; + if (decl == NULL_TREE || VAR_P (decl)) + /* If DECL is null, we don't know what this token might be. Treat + it as an ID for better diagnostics; we'll error later on. */ + token->id_kind = C_ID_ID; else if (TREE_CODE (decl) == TYPE_DECL) token->id_kind = C_ID_TYPENAME; - else if (VAR_P (decl)) - token->id_kind = C_ID_ID; } token_indent_info next_tinfo diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 539b58037dc..35e568c882b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-11-13 Marek Polacek + + PR c/68320 + * gcc.dg/pr68320.c: New test. + 2015-11-13 Nathan Sidwell * c-c++-common/goacc/data-default-1.c: Correct expected diff --git a/gcc/testsuite/gcc.dg/pr68320.c b/gcc/testsuite/gcc.dg/pr68320.c new file mode 100644 index 00000000000..7060af8993e --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr68320.c @@ -0,0 +1,67 @@ +/* PR c/68320 */ +/* { dg-do compile } */ +/* { dg-options "" } */ + +void +fn1 (void) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + ; + T x; /* { dg-error "unknown type name" } */ +} + +void +fn2 (int i) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + i = 5; + T x; /* { dg-error "unknown type name" } */ +} + +void +fn3 (void) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + { + } + T *x; /* { dg-error "unknown type name" } */ +} + +void +fn4 (void) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + ; + T, T; /* { dg-error "undeclared" } */ +} + +void +fn5 (void) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + ; + T = 10; /* { dg-error "undeclared" } */ +} + +void +fn6 (void) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + ; + T[0]; /* { dg-error "undeclared" } */ +} + +void +fn7 (void) +{ + for (typedef int T;;) /* { dg-error "declaration of non-variable" } */ + if (1) + ; + T (); /* { dg-warning "implicit declaration" } */ +}