This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

attribute __used__ on static data


I was surprised to find this afternoon that we accept this on
functions, but not data.  If we intend to do cool things with
static data with unit-at-a-time compilation, it seems like a
good idea to go ahead and accept this now.


r~


        * 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.

Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.400
diff -c -p -d -u -r1.400 c-common.c
--- c-common.c	1 Feb 2003 18:59:42 -0000	1.400
+++ c-common.c	19 Feb 2003 02:04:15 -0000
@@ -5415,16 +5415,19 @@ handle_always_inline_attribute (node, na
    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: testsuite/gcc.dg/attr-invalid.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/attr-invalid.c,v
retrieving revision 1.2
diff -c -p -d -u -r1.2 attr-invalid.c
--- testsuite/gcc.dg/attr-invalid.c	6 Feb 2002 20:40:17 -0000	1.2
+++ testsuite/gcc.dg/attr-invalid.c	19 Feb 2003 02:04:15 -0000
@@ -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;
 }
Index: testsuite/gcc.dg/attr-used-2.c
===================================================================
RCS file: testsuite/gcc.dg/attr-used-2.c
diff -N testsuite/gcc.dg/attr-used-2.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.dg/attr-used-2.c	19 Feb 2003 02:04:15 -0000
@@ -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" } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]