aboutsummaryrefslogtreecommitdiff
path: root/gcc/cgraphunit.cc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2023-03-10 10:10:24 +0100
committerJakub Jelinek <jakub@redhat.com>2023-03-10 10:10:24 +0100
commit2c63cc7268fd5615997989f153e9405d0f5aaa50 (patch)
treea69a983a22dcf7ae8e273865b1dbb204a11ccb91 /gcc/cgraphunit.cc
parenta1d5c729ceeb112af26e3298314a0de3058f1d82 (diff)
downloadgcc-2c63cc7268fd5615997989f153e9405d0f5aaa50.zip
gcc-2c63cc7268fd5615997989f153e9405d0f5aaa50.tar.gz
gcc-2c63cc7268fd5615997989f153e9405d0f5aaa50.tar.bz2
c, c++, cgraphunit: Prevent duplicated -Wunused-value warnings [PR108079]
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. 2023-03-10 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.
Diffstat (limited to 'gcc/cgraphunit.cc')
-rw-r--r--gcc/cgraphunit.cc1
1 files changed, 1 insertions, 0 deletions
diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc
index a972900..e12764f 100644
--- a/gcc/cgraphunit.cc
+++ b/gcc/cgraphunit.cc
@@ -1120,6 +1120,7 @@ check_global_declaration (symtab_node *snode)
&& (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),