c-common.c (handle_used_attribute): Accept static data too.
authorRichard Henderson <rth@gcc.gnu.org>
Wed, 19 Feb 2003 02:07:06 +0000 (18:07 -0800)
committerRichard Henderson <rth@gcc.gnu.org>
Wed, 19 Feb 2003 02:07:06 +0000 (18:07 -0800)
        * c-common.c (handle_used_attribute): Accept static data too.

        * gcc.dg/attr-invalid.c: Allow __used__ on static data.
        * gcc.dg/attr-used-2.c: New.

From-SVN: r63082

gcc/ChangeLog
gcc/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/attr-invalid.c
gcc/testsuite/gcc.dg/attr-used-2.c [new file with mode: 0644]

index cc6839a6fcfc9863fd384bbd877832abd74a4aca..04b7f814bd41421c2eb17e3fa6ef0eb90931e470 100644 (file)
@@ -1,4 +1,8 @@
-003-02-18  Nick Clifton  <nickc@redhat.com>
+2003-02-18  Richard Henderson  <rth@redhat.com>
+
+       * c-common.c (handle_used_attribute): Accept static data too.
+
+2003-02-18  Nick Clifton  <nickc@redhat.com>
             Aldy Hernandez  <aldyh@redhat.com>
 
         * testsuite/gcc.dg/20030218-1.c: New.
index c78692fd9591598edc39135b01c2948a0484c819..b49dc25f43dd7ffab4b7408d2273112dc7d9a361 100644 (file)
@@ -5415,16 +5415,19 @@ handle_always_inline_attribute (node, name, args, flags, no_add_attrs)
    struct attribute_spec.handler.  */
 
 static tree
-handle_used_attribute (node, name, args, flags, no_add_attrs)
-     tree *node;
+handle_used_attribute (pnode, name, args, flags, no_add_attrs)
+     tree *pnode;
      tree name;
      tree args ATTRIBUTE_UNUSED;
      int flags ATTRIBUTE_UNUSED;
      bool *no_add_attrs;
 {
-  if (TREE_CODE (*node) == FUNCTION_DECL)
-    TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (*node))
-      = TREE_USED (*node) = 1;
+  tree node = *pnode;
+
+  if (TREE_CODE (node) == FUNCTION_DECL
+      || (TREE_CODE (node) == VAR_DECL && TREE_STATIC (node)))
+    TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (node))
+      = TREE_USED (node) = 1;
   else
     {
       warning ("`%s' attribute ignored", IDENTIFIER_POINTER (name));
index 220c69643e4e75318a572105ad5d2beab7a11d0e..4c7b8b38e1cfe84a635217a12540107d58f9e4cb 100644 (file)
@@ -1,3 +1,8 @@
+2003-02-18  Richard Henderson  <rth@redhat.com>
+
+       * gcc.dg/attr-invalid.c: Allow __used__ on static data.
+       * gcc.dg/attr-used-2.c: New.
+
 2003-02-18  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/9704
index a999c267c3aba4bd98239d573a5d753b502f19c3..9cb645415480e87fbeccc7c42ac4401e3d0b8faf 100644 (file)
@@ -43,7 +43,7 @@ struct ATSYM(struct) {
   char dummy ATTR; /* { dg-warning "attribute ignored" "" } */
 } ATTR; /* { dg-warning "does not apply to types" "" } */
 
-int ATSYM(var) ATTR;  /* { dg-warning "attribute ignored" "" } */
+int ATSYM(var) ATTR;
 
 int ATSYM(fn_knrarg) (arg)
   int arg ATTR; /* { dg-warning "attribute ignored" "" } */
@@ -52,7 +52,7 @@ int ATSYM(fn_knrarg) (arg)
 int ATSYM(fn_isoarg) (int arg ATTR) { return 0; } /* { dg-warning "attribute ignored" "" } */
 
 int ATSYM(fn_vars) (void) {
-  static int svar ATTR; /* { dg-warning "attribute ignored" "" } */
+  static int svar ATTR;
   auto int lvar ATTR; /* { dg-warning "attribute ignored" "" } */
   return 0;
 }
diff --git a/gcc/testsuite/gcc.dg/attr-used-2.c b/gcc/testsuite/gcc.dg/attr-used-2.c
new file mode 100644 (file)
index 0000000..f78b94b
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-Wall -O2" } */
+
+static int xyzzy __attribute__((__used__)) = 1; 
+
+void foo()
+{
+  int x __attribute__((__used__)); /* { dg-warning "attribute ignored|unused variable" } */
+}
+
+/* { dg-final { scan-assembler "xyzzy" } } */