public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079]
@ 2022-12-22 10:32 Jakub Jelinek
  2022-12-22 21:44 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2022-12-22 10:32 UTC (permalink / raw)
  To: Joseph S. Myers, Jason Merrill, Marek Polacek; +Cc: gcc-patches

Hi!

On the following testcase, we warn with -Wunused-value twice, once
in the FEs and later on cgraphunit again with slightly different
wording.

The following patch fixes that by registering a warning suppression in the
FEs when we warn and not warning in cgraphunit anymore if that happened.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2022-12-22  Jakub Jelinek  <jakub@redhat.com>

	PR c/108079
gcc/
	* cgraphunit.cc (check_global_declaration): Don't warn for unused
	variables which have OPT_Wunused_variable warning suppressed.
gcc/c/
	* c-decl.cc (pop_scope): Suppress OPT_Wunused_variable warning
	after diagnosing it.
gcc/cp/
	* decl.cc (poplevel): Suppress OPT_Wunused_variable warning
	after diagnosing it.
gcc/testsuite/
	* c-c++-common/Wunused-var-18.c: New test.

--- gcc/cgraphunit.cc.jj	2022-10-18 10:38:48.000000000 +0200
+++ gcc/cgraphunit.cc	2022-12-21 15:14:34.687939477 +0100
@@ -1122,6 +1122,7 @@ check_global_declaration (symtab_node *s
       && (TREE_CODE (decl) != FUNCTION_DECL
 	  || (!DECL_STATIC_CONSTRUCTOR (decl)
 	      && !DECL_STATIC_DESTRUCTOR (decl)))
+      && (! VAR_P (decl) || !warning_suppressed_p (decl, OPT_Wunused_variable))
       /* Otherwise, ask the language.  */
       && lang_hooks.decls.warn_unused_global (decl))
     warning_at (DECL_SOURCE_LOCATION (decl),
--- gcc/c/c-decl.cc.jj	2022-12-19 11:08:31.500766238 +0100
+++ gcc/c/c-decl.cc	2022-12-21 14:52:40.251919370 +0100
@@ -1310,7 +1310,10 @@ pop_scope (void)
 	      && scope != external_scope)
 	    {
 	      if (!TREE_USED (p))
-		warning (OPT_Wunused_variable, "unused variable %q+D", p);
+		{
+		  warning (OPT_Wunused_variable, "unused variable %q+D", p);
+		  suppress_warning (p, OPT_Wunused_variable);
+		}
 	      else if (DECL_CONTEXT (p) == current_function_decl)
 		warning_at (DECL_SOURCE_LOCATION (p),
 			    OPT_Wunused_but_set_variable,
--- gcc/cp/decl.cc.jj	2022-12-21 09:03:45.437566855 +0100
+++ gcc/cp/decl.cc	2022-12-21 14:51:07.043265263 +0100
@@ -693,6 +693,7 @@ poplevel (int keep, int reverse, int fun
 		else
 		  warning_at (DECL_SOURCE_LOCATION (decl),
 			      OPT_Wunused_variable, "unused variable %qD", decl);
+		suppress_warning (decl, OPT_Wunused_variable);
 	      }
 	    else if (DECL_CONTEXT (decl) == current_function_decl
 		     // For -Wunused-but-set-variable leave references alone.
--- gcc/testsuite/c-c++-common/Wunused-var-18.c.jj	2022-12-21 15:28:03.112273963 +0100
+++ gcc/testsuite/c-c++-common/Wunused-var-18.c	2022-12-21 15:27:05.246107581 +0100
@@ -0,0 +1,10 @@
+/* PR c/108079 */
+/* { dg-do compile } */
+/* { dg-options "-Wunused-variable" } */
+
+int
+main ()
+{
+  static int x;	/* { dg-warning "unused variable 'x'" } */
+		/* { dg-bogus "'x' defined but not used" "" { target *-*-* } .-1 } */
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079]
  2022-12-22 10:32 [PATCH] c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079] Jakub Jelinek
@ 2022-12-22 21:44 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2022-12-22 21:44 UTC (permalink / raw)
  To: Jakub Jelinek, Joseph S. Myers, Marek Polacek; +Cc: gcc-patches

On 12/22/22 05:32, Jakub Jelinek wrote:
> Hi!
> 
> On the following testcase, we warn with -Wunused-value twice, once
> in the FEs and later on cgraphunit again with slightly different
> wording.
> 
> The following patch fixes that by registering a warning suppression in the
> FEs when we warn and not warning in cgraphunit anymore if that happened.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

OK.

> 2022-12-22  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c/108079
> gcc/
> 	* cgraphunit.cc (check_global_declaration): Don't warn for unused
> 	variables which have OPT_Wunused_variable warning suppressed.
> gcc/c/
> 	* c-decl.cc (pop_scope): Suppress OPT_Wunused_variable warning
> 	after diagnosing it.
> gcc/cp/
> 	* decl.cc (poplevel): Suppress OPT_Wunused_variable warning
> 	after diagnosing it.
> gcc/testsuite/
> 	* c-c++-common/Wunused-var-18.c: New test.
> 
> --- gcc/cgraphunit.cc.jj	2022-10-18 10:38:48.000000000 +0200
> +++ gcc/cgraphunit.cc	2022-12-21 15:14:34.687939477 +0100
> @@ -1122,6 +1122,7 @@ check_global_declaration (symtab_node *s
>         && (TREE_CODE (decl) != FUNCTION_DECL
>   	  || (!DECL_STATIC_CONSTRUCTOR (decl)
>   	      && !DECL_STATIC_DESTRUCTOR (decl)))
> +      && (! VAR_P (decl) || !warning_suppressed_p (decl, OPT_Wunused_variable))
>         /* Otherwise, ask the language.  */
>         && lang_hooks.decls.warn_unused_global (decl))
>       warning_at (DECL_SOURCE_LOCATION (decl),
> --- gcc/c/c-decl.cc.jj	2022-12-19 11:08:31.500766238 +0100
> +++ gcc/c/c-decl.cc	2022-12-21 14:52:40.251919370 +0100
> @@ -1310,7 +1310,10 @@ pop_scope (void)
>   	      && scope != external_scope)
>   	    {
>   	      if (!TREE_USED (p))
> -		warning (OPT_Wunused_variable, "unused variable %q+D", p);
> +		{
> +		  warning (OPT_Wunused_variable, "unused variable %q+D", p);
> +		  suppress_warning (p, OPT_Wunused_variable);
> +		}
>   	      else if (DECL_CONTEXT (p) == current_function_decl)
>   		warning_at (DECL_SOURCE_LOCATION (p),
>   			    OPT_Wunused_but_set_variable,
> --- gcc/cp/decl.cc.jj	2022-12-21 09:03:45.437566855 +0100
> +++ gcc/cp/decl.cc	2022-12-21 14:51:07.043265263 +0100
> @@ -693,6 +693,7 @@ poplevel (int keep, int reverse, int fun
>   		else
>   		  warning_at (DECL_SOURCE_LOCATION (decl),
>   			      OPT_Wunused_variable, "unused variable %qD", decl);
> +		suppress_warning (decl, OPT_Wunused_variable);
>   	      }
>   	    else if (DECL_CONTEXT (decl) == current_function_decl
>   		     // For -Wunused-but-set-variable leave references alone.
> --- gcc/testsuite/c-c++-common/Wunused-var-18.c.jj	2022-12-21 15:28:03.112273963 +0100
> +++ gcc/testsuite/c-c++-common/Wunused-var-18.c	2022-12-21 15:27:05.246107581 +0100
> @@ -0,0 +1,10 @@
> +/* PR c/108079 */
> +/* { dg-do compile } */
> +/* { dg-options "-Wunused-variable" } */
> +
> +int
> +main ()
> +{
> +  static int x;	/* { dg-warning "unused variable 'x'" } */
> +		/* { dg-bogus "'x' defined but not used" "" { target *-*-* } .-1 } */
> +}
> 
> 	Jakub
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-22 21:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-22 10:32 [PATCH] c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079] Jakub Jelinek
2022-12-22 21:44 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).