diff options
author | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2015-09-18 19:36:19 +0000 |
---|---|---|
committer | Manuel López-Ibáñez <manu@gcc.gnu.org> | 2015-09-18 19:36:19 +0000 |
commit | c4914de6185a913d2dbb152a15b0c43b9d70106c (patch) | |
tree | 616fcade21d35e7c06e245ee5b7578f95ca8ad86 /gcc | |
parent | edfc92491b22d1cd8f5fc1101cc148cc85f49441 (diff) | |
download | gcc-c4914de6185a913d2dbb152a15b0c43b9d70106c.zip gcc-c4914de6185a913d2dbb152a15b0c43b9d70106c.tar.gz gcc-c4914de6185a913d2dbb152a15b0c43b9d70106c.tar.bz2 |
Use explicit locations for some warnings in c-pragma.c.
gcc/cp/ChangeLog:
2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* parser.c (pragma_lex): Add loc argument. Rearrange the code to
make it more similar to the C version.
gcc/c-family/ChangeLog:
2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* c-pragma.c (handle_pragma_diagnostic): Use explicit location
when warning.
* c-pragma.h (pragma_lex): Add optional loc argument.
gcc/c/ChangeLog:
2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* c-parser.c (pragma_lex): Add loc argument.
gcc/testsuite/ChangeLog:
2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org>
* gcc.dg/pragma-diag-5.c: New test.
From-SVN: r227923
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-family/c-pragma.c | 44 | ||||
-rw-r--r-- | gcc/c-family/c-pragma.h | 2 | ||||
-rw-r--r-- | gcc/c/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/c/c-parser.c | 5 | ||||
-rw-r--r-- | gcc/cp/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/cp/parser.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pragma-diag-5.c | 6 |
9 files changed, 66 insertions, 23 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9a63169..49df8c9 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org> + + * c-pragma.c (handle_pragma_diagnostic): Use explicit location + when warning. + * c-pragma.h (pragma_lex): Add optional loc argument. + 2015-09-16 Mikhail Maltsev <maltsevm@gmail.com> * c-format.c (check_format_arg): Adjust to use common block size in all diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c index 5fb1fc2..4679555 100644 --- a/gcc/c-family/c-pragma.c +++ b/gcc/c-family/c-pragma.c @@ -704,17 +704,19 @@ handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED) static void handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy)) { - const char *kind_string, *option_string; - unsigned int option_index; - enum cpp_ttype token; - diagnostic_t kind; tree x; - struct cl_option_handlers handlers; - - token = pragma_lex (&x); + location_t loc; + enum cpp_ttype token = pragma_lex (&x, &loc); if (token != CPP_NAME) - GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>"); - kind_string = IDENTIFIER_POINTER (x); + { + warning_at (loc, OPT_Wpragmas, + "missing [error|warning|ignored|push|pop]" + " after %<#pragma GCC diagnostic%>"); + } + return; + + diagnostic_t kind; + const char *kind_string = IDENTIFIER_POINTER (x); if (strcmp (kind_string, "error") == 0) kind = DK_ERROR; else if (strcmp (kind_string, "warning") == 0) @@ -732,13 +734,26 @@ handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy)) return; } else - GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>"); + { + warning_at (loc, OPT_Wpragmas, + "expected [error|warning|ignored|push|pop]" + " after %<#pragma GCC diagnostic%>"); + return; + } - token = pragma_lex (&x); + token = pragma_lex (&x, &loc); if (token != CPP_STRING) - GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind"); - option_string = TREE_STRING_POINTER (x); + { + warning_at (loc, OPT_Wpragmas, + "missing option after %<#pragma GCC diagnostic%> kind"); + return; + } + + struct cl_option_handlers handlers; set_default_handlers (&handlers); + + unsigned int option_index; + const char *option_string = TREE_STRING_POINTER (x); for (option_index = 0; option_index < cl_options_count; option_index++) if (strcmp (cl_options[option_index].opt_text, option_string) == 0) { @@ -748,7 +763,8 @@ handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy)) global_dc); return; } - GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind"); + warning_at (loc, OPT_Wpragmas, + "unknown option after %<#pragma GCC diagnostic%> kind"); } /* Parse #pragma GCC target (xxx) to set target specific options. */ diff --git a/gcc/c-family/c-pragma.h b/gcc/c-family/c-pragma.h index aa2b471..f6e1090 100644 --- a/gcc/c-family/c-pragma.h +++ b/gcc/c-family/c-pragma.h @@ -212,7 +212,7 @@ extern void maybe_apply_pending_pragma_weaks (void); extern tree maybe_apply_renaming_pragma (tree, tree); extern void add_to_renaming_pragma_list (tree, tree); -extern enum cpp_ttype pragma_lex (tree *); +extern enum cpp_ttype pragma_lex (tree *, location_t *loc = NULL); /* Flags for use with c_lex_with_flags. The values here were picked so that 0 means to translate and join strings. */ diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 27659e2..aa6d715 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org> + + * c-parser.c (pragma_lex): Add loc argument. + 2015-09-15 Marek Polacek <polacek@redhat.com> PR c/67580 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index d5de102..2fab3f0 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -9846,12 +9846,15 @@ c_parser_pragma (c_parser *parser, enum pragma_context context) /* The interface the pragma parsers have to the lexer. */ enum cpp_ttype -pragma_lex (tree *value) +pragma_lex (tree *value, location_t *loc) { c_token *tok = c_parser_peek_token (the_parser); enum cpp_ttype ret = tok->type; *value = tok->value; + if (loc) + *loc = tok->location; + if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) ret = CPP_EOF; else diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 0f0d07d..c72e913 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org> + + * parser.c (pragma_lex): Add loc argument. Rearrange the code to + make it more similar to the C version. + 2015-09-17 Andrew Sutton <andrew.n.sutton@gmail.com> Jason Merrill <jason@redhat.com> diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4f424b6..637118c 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -34447,15 +34447,14 @@ cp_parser_pragma (cp_parser *parser, enum pragma_context context) /* The interface the pragma parsers have to the lexer. */ enum cpp_ttype -pragma_lex (tree *value) +pragma_lex (tree *value, location_t *loc) { - cp_token *tok; - enum cpp_ttype ret; - - tok = cp_lexer_peek_token (the_parser->lexer); + cp_token *tok = cp_lexer_peek_token (the_parser->lexer); + enum cpp_ttype ret = tok->type; - ret = tok->type; *value = tok->u.value; + if (loc) + *loc = tok->location; if (ret == CPP_PRAGMA_EOL || ret == CPP_EOF) ret = CPP_EOF; @@ -34463,9 +34462,9 @@ pragma_lex (tree *value) *value = cp_parser_string_literal (the_parser, false, false); else { - cp_lexer_consume_token (the_parser->lexer); if (ret == CPP_KEYWORD) ret = CPP_NAME; + cp_lexer_consume_token (the_parser->lexer); } return ret; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f959a789..95a19a7 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-09-18 Manuel López-Ibáñez <manu@gcc.gnu.org> + + * gcc.dg/pragma-diag-5.c: New test. + 2015-09-18 Uros Bizjak <ubizjak@gmail.com> PR middle-end/67619 diff --git a/gcc/testsuite/gcc.dg/pragma-diag-5.c b/gcc/testsuite/gcc.dg/pragma-diag-5.c new file mode 100644 index 0000000..64fe97f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pragma-diag-5.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +#pragma GCC diagnostic /* { dg-warning "24:missing" "missing" { xfail *-*-* } } */ + +#pragma GCC diagnostic warn /* { dg-warning "24:expected" } */ + +#pragma GCC diagnostic ignored "-Wfoo" /* { dg-warning "32:unknown" } */ |