re PR c/34985 (Warning "defined but not used" despite __attribute__((__used__)))
authorManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 29 Jul 2008 10:00:25 +0000 (10:00 +0000)
committerManuel López-Ibáñez <manu@gcc.gnu.org>
Tue, 29 Jul 2008 10:00:25 +0000 (10:00 +0000)
2008-07-29  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.

From-SVN: r138235

gcc/ChangeLog
gcc/c-decl.c
gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pr34985.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr34985.c [new file with mode: 0644]

index 3766bb6f42f05e16c3a26b1b6fe52d5a7d1faa0a..6533ff34a7afcf3fd8aefdb136a328f3ad4b27a5 100644 (file)
@@ -1,3 +1,8 @@
+2008-07-29  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR 34985
+       * c-decl.c (merge_decls): Merge USED flags.
+       
 2008-07-29  Kaz Kojima  <kkojima@gcc.gnu.org>
 
        * config/sh/sh.c (sh_gimplify_va_arg_expr): Unshare the addr,
index bdb6819935167b14cfec047dfbb603c8e9683fd7..7929aa8e2baf9f733f642f1d145e5a2d97951c47 100644 (file)
@@ -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.  */
   {
index bbb23ee197659ea3cc56b1d15410314b5199fa44..b44108402d4ee2c9c10f2d1fd9f5b509d6263883 100644 (file)
@@ -1,3 +1,8 @@
+2008-07-29  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR 34985
+       * decl.c (duplicate_decls): Merge USED flags.
+       
 2008-07-27  Jason Merrill  <jason@redhat.com>
 
        PR c++/36943
index 2d9ccba3a5cf8b3afc28f27139187da06e666e87..248b9b71a053146de7d14adee28b76338eecd118 100644 (file)
@@ -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;
index e6ec66ef5ba9c27500fea0f4e2e9a6497379759c..ed53441e077c2e6c3fcaac4390fe8cfd16260bc6 100644 (file)
@@ -1,3 +1,9 @@
+2008-07-29  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       PR 34985
+       * gcc.dg/pr34985.c: New.
+       * g++.dg/warn/pr34985.C: New.
+       
 2008-07-29  Daniel Kraft  <d@domob.eu>
 
        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 (file)
index 0000000..5643750
--- /dev/null
@@ -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 (file)
index 0000000..5643750
--- /dev/null
@@ -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" } } */