This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C] Fix PR57258: unused variable warning is emitted for volatile variables


2013/11/6 Richard Biener <richard.guenther@gmail.com>:
> 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;
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]