[PATCH] Disable -Wunused warning for artificial decls (PR sanitizer/66452)

Richard Biener rguenther@suse.de
Mon Jun 8 10:23:00 GMT 2015


On Mon, 8 Jun 2015, Marek Polacek wrote:

> This PR is about a bogus -Wunused-variable warning about an internal
> structure (*.Lubsan_data*), exposed by the debug-early merge.
> 
> I think the "defined but not used" warning should not be allowed for
> the compiler-generated entities.
> 
> Bootstrapped/regtested on x86_64-linux, ok for trunk?

Ok.

Thanks,
Richard.

> 2015-06-08  Marek Polacek  <polacek@redhat.com>
> 
> 	PR sanitizer/66452
> 	* toplev.c (check_global_declaration): Don't warn about artificial
> 	decls.
> 
> 	* g++.dg/ubsan/pr66452.C: New test.
> 
> diff --git gcc/testsuite/g++.dg/ubsan/pr66452.C gcc/testsuite/g++.dg/ubsan/pr66452.C
> index e69de29..473543c 100644
> --- gcc/testsuite/g++.dg/ubsan/pr66452.C
> +++ gcc/testsuite/g++.dg/ubsan/pr66452.C
> @@ -0,0 +1,16 @@
> +// PR sanitizer/66452
> +// { dg-do compile }
> +// { dg-options "-Wall -fsanitize=undefined" }
> +
> +class A {
> +public:
> +  A(int);
> +};
> +class B {
> +  A m_fn1() const;
> +};
> +A B::m_fn1() const {
> +  for (int i = 0;i;)
> +    ;
> +  return 0;
> +}
> diff --git gcc/toplev.c gcc/toplev.c
> index fd2ac4e..eb8b8ac 100644
> --- gcc/toplev.c
> +++ gcc/toplev.c
> @@ -534,6 +534,7 @@ check_global_declaration (tree decl)
>  	 to handle multiple external decls in different scopes.  */
>        && ! (DECL_NAME (decl) && TREE_USED (DECL_NAME (decl)))
>        && ! DECL_EXTERNAL (decl)
> +      && ! DECL_ARTIFICIAL (decl)
>        && ! TREE_PUBLIC (decl)
>        /* A volatile variable might be used in some non-obvious way.  */
>        && ! TREE_THIS_VOLATILE (decl)
> 
> 	Marek
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Dilip Upmanyu, Graham Norton, HRB 21284 (AG Nuernberg)



More information about the Gcc-patches mailing list