On Tue, Dec 1, 2015 at 3:47 PM, Marek Polacek <pola...@redhat.com> wrote: > We were failing to give "defined but not used" warning for functions marked > with the attribute noreturn/volatile. The problem is that for functions the > TREE_THIS_VOLATILE flag means something different than for decls. The fix is > to check the flag only for VAR_DECLs, as suggested by Richi in the PR. > > Bootstrapped/regtested on x86_64-linux, ok for trunk?
Ok. Thanks. Richard. > 2015-12-01 Marek Polacek <pola...@redhat.com> > > PR middle-end/68582 > * cgraphunit.c (check_global_declaration): Only depend on > TREE_THIS_VOLATILE > for VAR_DECLs. > > * c-c++-common/pr68582.c: New test. > > diff --git gcc/cgraphunit.c gcc/cgraphunit.c > index f73d9a7..4ce5f9b 100644 > --- gcc/cgraphunit.c > +++ gcc/cgraphunit.c > @@ -956,7 +956,7 @@ check_global_declaration (symtab_node *snode) > && ! DECL_ABSTRACT_ORIGIN (decl) > && ! TREE_PUBLIC (decl) > /* A volatile variable might be used in some non-obvious way. */ > - && ! TREE_THIS_VOLATILE (decl) > + && (! VAR_P (decl) || ! TREE_THIS_VOLATILE (decl)) > /* Global register variables must be declared to reserve them. */ > && ! (TREE_CODE (decl) == VAR_DECL && DECL_REGISTER (decl)) > /* Global ctors and dtors are called by the runtime. */ > diff --git gcc/testsuite/c-c++-common/pr68582.c > gcc/testsuite/c-c++-common/pr68582.c > index e69de29..95ca9a4 100644 > --- gcc/testsuite/c-c++-common/pr68582.c > +++ gcc/testsuite/c-c++-common/pr68582.c > @@ -0,0 +1,25 @@ > +/* PR middle-end/68582 */ > +/* { dg-do compile } */ > +/* { dg-options "-Wunused-function" } */ > + > +/* We failed to give the warning for functions with TREE_THIS_VOLATILE set. > */ > + > +static void > +fn1 (void) /* { dg-warning "defined but not used" } */ > +{ > + __builtin_abort (); > +} > + > +__attribute__ ((noreturn)) > +static void > +fn2 (void) /* { dg-warning "defined but not used" } */ > +{ > + __builtin_abort (); > +} > + > +__attribute__ ((volatile)) > +static void > +fn3 (void) /* { dg-warning "defined but not used" } */ > +{ > + __builtin_abort (); > +} > > Marek