From f9eb0973edb2b4eed4cdbba7105b8af7afe5b547 Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Thu, 30 Jan 2020 14:09:41 -0700 Subject: [PATCH] Mark switch expression as used to avoid bogus warning PR c/88660 * c-parser.c (c_parser_switch_statement): Make sure to request marking the switch expr as used. PR c/88660 * gcc.dg/pr88660.c: New test. --- gcc/c/ChangeLog | 6 ++++++ gcc/c/c-parser.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr88660.c | 13 +++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr88660.c diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9497365a569..995f315a803 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2020-01-30 Jeff Law + + PR c/88660 + * c-parser.c (c_parser_switch_statement): Make sure to request + marking the switch expr as used. + 2020-01-22 Joseph Myers PR c/93348 diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 6164017de02..1e8f2f7108d 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -6607,7 +6607,7 @@ c_parser_switch_statement (c_parser *parser, bool *if_p) && c_token_starts_typename (c_parser_peek_2nd_token (parser))) explicit_cast_p = true; ce = c_parser_expression (parser); - ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, false); + ce = convert_lvalue_to_rvalue (switch_cond_loc, ce, true, true); expr = ce.value; /* ??? expr has no valid location? */ parens.skip_until_found_close (parser); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4503016a73e..90eb0b2ffba 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-01-30 Jeff Law PR lto/93384 diff --git a/gcc/testsuite/gcc.dg/pr88660.c b/gcc/testsuite/gcc.dg/pr88660.c new file mode 100644 index 00000000000..09a2d3270bd --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr88660.c @@ -0,0 +1,13 @@ +/* { dg-do-compile } */ +/* { dg-options "-O -Wunused-but-set-variable" } */ + +int main(void) +{ + const int i = 0; + switch(i) + { + default: break; + } +} + + -- 2.30.2