From e27fb29c0dec9ef1cf32fe44ecbf7a6fcc3f09a9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez?= Date: Tue, 29 Jul 2008 10:00:25 +0000 Subject: [PATCH] re PR c/34985 (Warning "defined but not used" despite __attribute__((__used__))) 2008-07-29 Manuel Lopez-Ibanez 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. From-SVN: r138235 --- gcc/ChangeLog | 5 +++++ gcc/c-decl.c | 6 ++++++ gcc/cp/ChangeLog | 5 +++++ gcc/cp/decl.c | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/warn/pr34985.C | 9 +++++++++ gcc/testsuite/gcc.dg/pr34985.c | 9 +++++++++ 7 files changed, 46 insertions(+) create mode 100644 gcc/testsuite/g++.dg/warn/pr34985.C create mode 100644 gcc/testsuite/gcc.dg/pr34985.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3766bb6f42f..6533ff34a7a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2008-07-29 Manuel Lopez-Ibanez + + PR 34985 + * c-decl.c (merge_decls): Merge USED flags. + 2008-07-29 Kaz Kojima * config/sh/sh.c (sh_gimplify_va_arg_expr): Unshare the addr, diff --git a/gcc/c-decl.c b/gcc/c-decl.c index bdb68199351..7929aa8e2ba 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -1862,6 +1862,12 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) 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. */ { diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index bbb23ee1976..b44108402d4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2008-07-29 Manuel Lopez-Ibanez + + PR 34985 + * decl.c (duplicate_decls): Merge USED flags. + 2008-07-27 Jason Merrill PR c++/36943 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 2d9ccba3a5c..248b9b71a05 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2056,6 +2056,12 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) 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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e6ec66ef5ba..ed53441e077 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-07-29 Manuel Lopez-Ibanez + + PR 34985 + * gcc.dg/pr34985.c: New. + * g++.dg/warn/pr34985.C: New. + 2008-07-29 Daniel Kraft PR fortran/36403 diff --git a/gcc/testsuite/g++.dg/warn/pr34985.C b/gcc/testsuite/g++.dg/warn/pr34985.C new file mode 100644 index 00000000000..56437509d9f --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr34985.C @@ -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" } } */ diff --git a/gcc/testsuite/gcc.dg/pr34985.c b/gcc/testsuite/gcc.dg/pr34985.c new file mode 100644 index 00000000000..56437509d9f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr34985.c @@ -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" } } */ -- 2.30.2