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]

[PATCH] Fix PRs c/17178 and c/17820


When Zack committed one of his c-decl rewrites, he had forgot that
the middle-end (toplev.c) already warned about static variables.
The code in pop_scope in c-decl.c should take that into account and
only warn on variables which are not in either the global or file
scopes.

OK? Bootstrapped and tested on powerpc-apple-darwin with no
regressions.

Thanks,
Andrew Pinski

Testcase:

static int a = 10; /* { dg-warning "defined but not used" } */

ChangeLog:

	PR c/17178, PR c/17820
	* c-decl.c (pop_scope): Do not warn about unused static
	variables as they warned in the middle-end.

	PR c/17178
	* gcc.dg/unused-4.c: Adjust to be correct.


Index: testsuite/gcc.dg/unused-4.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/unused-4.c,v retrieving revision 1.3 diff -u -p -r1.3 unused-4.c --- testsuite/gcc.dg/unused-4.c 23 Mar 2004 23:47:53 -0000 1.3 +++ testsuite/gcc.dg/unused-4.c 3 Oct 2004 23:12:16 -0000 @@ -1,6 +1,6 @@ /* { dg-do compile } */ /* { dg-options "-Wunused -O3" } */

-static const int i = 0;		/* { dg-warning "unused variable" } */
+static const int i = 0;
 static void f() { }		/* { dg-warning "defined but not used" } */
 static inline void g() { }
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.593
diff -u -p -r1.593 c-decl.c
--- c-decl.c	1 Oct 2004 15:11:09 -0000	1.593
+++ c-decl.c	3 Oct 2004 23:12:21 -0000
@@ -767,10 +767,8 @@ pop_scope (void)
 	      && !DECL_IN_SYSTEM_HEADER (p)
 	      && DECL_NAME (p)
 	      && !DECL_ARTIFICIAL (p)
-	      && (scope != file_scope
-		  || (TREE_STATIC (p) && !TREE_PUBLIC (p)
-		      && !TREE_THIS_VOLATILE (p)))
-	      && scope != external_scope)
+	      && scope != file_scope
+	      && scope != external_scope)
 	    warning ("%Junused variable %qD", p, p);

if (b->inner_comp)


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