This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PR 34985 Warning "defined but not used" despite __attribute__((__used__))
- From: "Manuel López-Ibáñez" <lopezibanez at gmail dot com>
- To: gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 23 Jul 2008 08:38:37 +0200
- Subject: PR 34985 Warning "defined but not used" despite __attribute__((__used__))
This patch fixes PR 34985. The problem here is that the USED flag was
not being copied from the old to the new decl when merging two decls.
Bootstrapped and regression tested on x86_64-unknown-linux-gnu.
OK to commit?
2008-07-23 Manuel Lopez-Ibanez <manu@gcc.gnu.org
PR 34985
* c-decl.c (merge_decls): Merge USED flags.
cp/
* decl.c (duplicate_decls): Merge USED flags.
testsuite/
* gcc.dg/pr34985.c: New.
* g++.dg/warn/pr34985.C: New
Index: gcc/testsuite/gcc.dg/pr34985.c
===================================================================
--- gcc/testsuite/gcc.dg/pr34985.c (revision 0)
+++ gcc/testsuite/gcc.dg/pr34985.c (revision 0)
@@ -0,0 +1,9 @@
+/* PR34985: Warning "defined but not used" despite __attribute__((__used__)) */
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wextra -O2" } */
+static void xxyyzz (void);
+static void __attribute__((__used__)) xxyyzz(void)
+{
+}
+
+/* { dg-final { scan-assembler "xxyyzz" } } */
Index: gcc/testsuite/g++.dg/warn/pr34985.C
===================================================================
--- gcc/testsuite/g++.dg/warn/pr34985.C (revision 0)
+++ gcc/testsuite/g++.dg/warn/pr34985.C (revision 0)
@@ -0,0 +1,9 @@
+/* PR34985: Warning "defined but not used" despite __attribute__((__used__)) */
+/* { dg-do compile } */
+/* { dg-options "-Wall -Wextra -O2" } */
+static void xxyyzz (void);
+static void __attribute__((__used__)) xxyyzz(void)
+{
+}
+
+/* { dg-final { scan-assembler "xxyyzz" } } */
Index: gcc/cp/decl.c
===================================================================
--- gcc/cp/decl.c (revision 138044)
+++ gcc/cp/decl.c (working copy)
@@ -2055,10 +2055,16 @@ duplicate_decls (tree newdecl, tree oldd
gcc_assert (DECL_LANG_SPECIFIC (olddecl)
!= DECL_LANG_SPECIFIC (newdecl));
ggc_free (DECL_LANG_SPECIFIC (olddecl));
}
+ /* Merge the USED information. */
+ if (TREE_USED (olddecl))
+ TREE_USED (newdecl) = 1;
+ else if (TREE_USED (newdecl))
+ TREE_USED (olddecl) = 1;
+
if (TREE_CODE (newdecl) == FUNCTION_DECL)
{
int function_size;
function_size = sizeof (struct tree_decl_common);
Index: gcc/c-decl.c
===================================================================
--- gcc/c-decl.c (revision 138044)
+++ gcc/c-decl.c (working copy)
@@ -1870,10 +1870,16 @@ merge_decls (tree newdecl, tree olddecl,
}
}
extern_changed = DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl);
+ /* Merge the USED information. */
+ if (TREE_USED (olddecl))
+ TREE_USED (newdecl) = 1;
+ else if (TREE_USED (newdecl))
+ TREE_USED (olddecl) = 1;
+
/* Copy most of the decl-specific fields of NEWDECL into OLDDECL.
But preserve OLDDECL's DECL_UID and DECL_CONTEXT. */
{
unsigned olddecl_uid = DECL_UID (olddecl);
tree olddecl_context = DECL_CONTEXT (olddecl);