From 84628aa83614d863abb3a6c04f14e1b9bdd8d6aa Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 18 Oct 2010 17:55:25 +0200 Subject: [PATCH] re PR c/46015 (-Wunused-but-set-variable warns for arrays used in gotos) PR c/46015 * c-parser.c (c_parser_statement_after_labels): Call mark_exp_read on computed goto argument. * semantics.c (finish_goto_stmt): Call mark_rvalue_use on computed goto destination. * c-c++-common/Wunused-var-13.c: New test. From-SVN: r165643 --- gcc/ChangeLog | 6 +++++ gcc/c-parser.c | 7 ++++-- gcc/cp/ChangeLog | 6 +++++ gcc/cp/semantics.c | 1 + gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/c-c++-common/Wunused-var-13.c | 27 +++++++++++++++++++++ 6 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/Wunused-var-13.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 55303f25220..e409c9dc9a3 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2010-10-18 Jakub Jelinek + + PR c/46015 + * c-parser.c (c_parser_statement_after_labels): Call mark_exp_read + on computed goto argument. + 2010-10-18 Richard Guenther PR tree-optimization/45967 diff --git a/gcc/c-parser.c b/gcc/c-parser.c index 8338e9d3285..bde882c7099 100644 --- a/gcc/c-parser.c +++ b/gcc/c-parser.c @@ -4151,9 +4151,12 @@ c_parser_statement_after_labels (c_parser *parser) } else if (c_parser_next_token_is (parser, CPP_MULT)) { + tree val; + c_parser_consume_token (parser); - stmt = c_finish_goto_ptr (loc, - c_parser_expression (parser).value); + val = c_parser_expression (parser).value; + mark_exp_read (val); + stmt = c_finish_goto_ptr (loc, val); } else c_parser_error (parser, "expected identifier or %<*%>"); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 9073ccb6ea3..8374750dff9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2010-10-18 Jakub Jelinek + + PR c/46015 + * semantics.c (finish_goto_stmt): Call mark_rvalue_use on computed + goto destination. + 2010-10-17 Nicola Pero Merge from apple/trunk branch on FSF servers. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 787c72c17fc..ae3bf90295d 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -537,6 +537,7 @@ finish_goto_stmt (tree destination) TREE_USED (destination) = 1; else { + destination = mark_rvalue_use (destination); if (!processing_template_decl) { destination = cp_convert (ptr_type_node, destination); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6a2738f6aa0..d066a8d0da1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2010-10-18 Jakub Jelinek + + PR c/46015 + * c-c++-common/Wunused-var-13.c: New test. + 2010-10-18 Richard Guenther PR tree-optimization/45967 diff --git a/gcc/testsuite/c-c++-common/Wunused-var-13.c b/gcc/testsuite/c-c++-common/Wunused-var-13.c new file mode 100644 index 00000000000..3afd873b646 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wunused-var-13.c @@ -0,0 +1,27 @@ +/* PR c/46015 */ +/* { dg-options "-Wunused" } */ +/* { dg-do compile } */ + +int +f1 (int i) +{ + static void *labs[2] = { &&lab1, &&lab2 }; + goto *(labs[i & 1]); + +lab1: + return 1; +lab2: + return 2; +} + +int +f2 (int i) +{ + void *labs[2] = { &&lab1, &&lab2 }; + goto *labs[i & 1]; + +lab1: + return 1; +lab2: + return 2; +}