2013/11/6 Richard Biener <[email protected]>:
> You miss a testcase.
>
> Also why should the warning be omitted for unused automatic
> volatile variables? They cannot be used in any way.
>
> Richard.
Thanks. I've updated the patch with a test case.
c/ChangeLog
PR 57258
* c-decl.c (pop_scope): Don't emit unused variable warnings for
accessed volatile variables.
testsuite/ChangeLog
* gcc.dg/Wunused-var-4.c: New test.
Mingjie
Index: c/c-decl.c
===================================================================
--- c/c-decl.c (revision 204285)
+++ c/c-decl.c (working copy)
@@ -1187,11 +1187,17 @@ pop_scope (void)
&& scope != external_scope)
{
if (!TREE_USED (p))
- warning (OPT_Wunused_variable, "unused variable %q+D", p);
+ {
+ if (!TREE_THIS_VOLATILE (p) || !DECL_INITIAL (p))
+ warning (OPT_Wunused_variable, "unused variable %q+D", p);
+ }
else if (DECL_CONTEXT (p) == current_function_decl)
- warning_at (DECL_SOURCE_LOCATION (p),
- OPT_Wunused_but_set_variable,
- "variable %qD set but not used", p);
+ {
+ if (!TREE_THIS_VOLATILE (p))
+ warning_at (DECL_SOURCE_LOCATION (p),
+ OPT_Wunused_but_set_variable,
+ "variable %qD set but not used", p);
+ }
}
if (b->inner_comp)
/* Test -Wunused. Bug 57258. */
/* { dg-do compile } */
/* { dg-options "-Wunused" } */
void
f (void)
{
volatile int a = 0;
volatile int b; /* { dg-warning "unused variable" } */
volatile int c;
int d; /* { dg-warning "set but not used" } */
c = 0;
d = 0;
}