From 8b6ab677a214c9ae86ab4644af573b93bfd84b03 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 1 Dec 2015 15:44:08 +0000 Subject: [PATCH] re PR middle-end/68582 (-Wunused-function doesn't warn about unused static __attribute__((noreturn)) functions) 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. From-SVN: r231116 --- gcc/ChangeLog | 6 ++++++ gcc/cgraphunit.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/c-c++-common/pr68582.c | 25 +++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/pr68582.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5b631cf8fd8..7dd3a789560 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-12-01 Marek Polacek + + PR middle-end/68582 + * cgraphunit.c (check_global_declaration): Only depend on TREE_THIS_VOLATILE + for VAR_DECLs. + 2015-12-01 Richard Sandiford PR tree-optimization/68474 diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c index f73d9a78e03..4ce5f9bdd2e 100644 --- a/gcc/cgraphunit.c +++ b/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 a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 78d31efefaa..addc4812794 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-12-01 Marek Polacek + + PR middle-end/68582 + * c-c++-common/pr68582.c: New test. + 2015-12-01 Richard Sandiford PR tree-optimization/68474 diff --git a/gcc/testsuite/c-c++-common/pr68582.c b/gcc/testsuite/c-c++-common/pr68582.c new file mode 100644 index 00000000000..95ca9a4f3b7 --- /dev/null +++ b/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 (); +} -- 2.30.2