From c4914de6185a913d2dbb152a15b0c43b9d70106c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Fri, 18 Sep 2015 19:36:19 +0000 Subject: [PATCH] Use explicit locations for some warnings in c-pragma.c. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc/cp/ChangeLog: 2015-09-18 Manuel López-Ibáñez * 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 * 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 * c-parser.c (pragma_lex): Add loc argument. gcc/testsuite/ChangeLog: 2015-09-18 Manuel López-Ibáñez * gcc.dg/pragma-diag-5.c: New test. From-SVN: r227923 --- gcc/c-family/ChangeLog | 6 ++++ gcc/c-family/c-pragma.c | 44 +++++++++++++++++++--------- gcc/c-family/c-pragma.h | 2 +- gcc/c/ChangeLog | 4 +++ gcc/c/c-parser.c | 5 +++- gcc/cp/ChangeLog | 5 ++++ gcc/cp/parser.c | 13 ++++---- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/pragma-diag-5.c | 6 ++++ 9 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pragma-diag-5.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9a631698c1c..49df8c9ed76 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2015-09-18 Manuel López-Ibáñez + + * 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 * 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 5fb1fc270eb..4679555ac29 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 aa2b4717572..f6e10900a63 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 27659e231c3..aa6d715288d 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,7 @@ +2015-09-18 Manuel López-Ibáñez + + * c-parser.c (pragma_lex): Add loc argument. + 2015-09-15 Marek Polacek PR c/67580 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index d5de1028ddc..2fab3f0ebe4 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 0f0d07dae17..c72e913e1b3 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2015-09-18 Manuel López-Ibáñez + + * parser.c (pragma_lex): Add loc argument. Rearrange the code to + make it more similar to the C version. + 2015-09-17 Andrew Sutton Jason Merrill diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 4f424b64f42..637118c2b27 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 f959a789f55..95a19a78181 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-09-18 Manuel López-Ibáñez + + * gcc.dg/pragma-diag-5.c: New test. + 2015-09-18 Uros Bizjak 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 00000000000..64fe97fc3f0 --- /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" } */ -- 2.30.2