]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/46949 (ICE when weakref is used on a definition (internal compiler...
authorJan Hubicka <jh@suse.cz>
Thu, 27 Jan 2011 16:16:34 +0000 (17:16 +0100)
committerJan Hubicka <hubicka@gcc.gnu.org>
Thu, 27 Jan 2011 16:16:34 +0000 (16:16 +0000)
PR middle-end/46949
* cgraphunit.c (process_common_attributes): Fix use of remove_attribute.
(process_function_and_variable_attributes): Check defined weakrefs.
* gcc.dg/attr-weakref-4.c: New testcase

From-SVN: r169332

gcc/ChangeLog
gcc/cgraphunit.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/attr-weakref-4.c [new file with mode: 0644]

index 3bee8dd54f638e24bedb9188868dd26dde3405c5..8f9e86a69c8aeaf02cf446580bad3faeaabf4f51 100644 (file)
@@ -1,3 +1,9 @@
+2011-01-27  Jan Hubicka  <jh@suse.cz>
+
+       PR middle-end/46949
+       * cgraphunit.c (process_common_attributes): Fix use of remove_attribute.
+       (process_function_and_variable_attributes): Check defined weakrefs.
+
 2011-01-27  Martin Jambor  <mjambor@suse.cz>
 
        PR tree-optimization/47228
index 2245164c3eb81fe785b158c2eb8a76ffd22a5fdf..848eba6530403ca81cc0f35c79fbdfe7acf5fb3e 100644 (file)
@@ -804,7 +804,8 @@ process_common_attributes (tree decl)
                  "%<weakref%> attribute should be accompanied with"
                  " an %<alias%> attribute");
       DECL_WEAK (decl) = 0;
-      remove_attribute ("weakref", DECL_ATTRIBUTES (decl));
+      DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
+                                                DECL_ATTRIBUTES (decl));
     }
 }
 
@@ -860,6 +861,16 @@ process_function_and_variable_attributes (struct cgraph_node *first,
          else if (node->local.finalized)
             cgraph_mark_needed_node (node);
        }
+      if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
+         && node->local.finalized)
+       {
+         warning_at (DECL_SOURCE_LOCATION (node->decl), OPT_Wattributes,
+                     "%<weakref%> attribute ignored"
+                     " because function is defined");
+         DECL_WEAK (decl) = 0;
+         DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
+                                                    DECL_ATTRIBUTES (decl));
+       }
       process_common_attributes (decl);
     }
   for (vnode = varpool_nodes; vnode != first_var; vnode = vnode->next)
@@ -887,6 +898,17 @@ process_function_and_variable_attributes (struct cgraph_node *first,
          else if (vnode->finalized)
            varpool_mark_needed_node (vnode);
        }
+      if (lookup_attribute ("weakref", DECL_ATTRIBUTES (decl))
+         && vnode->finalized
+         && DECL_INITIAL (decl))
+       {
+         warning_at (DECL_SOURCE_LOCATION (vnode->decl), OPT_Wattributes,
+                     "%<weakref%> attribute ignored"
+                     " because variable is initialized");
+         DECL_WEAK (decl) = 0;
+         DECL_ATTRIBUTES (decl) = remove_attribute ("weakref",
+                                                     DECL_ATTRIBUTES (decl));
+       }
       process_common_attributes (decl);
     }
 }
index acaa86287d91bc738add30a8063538f1c8c58358..4638e57ce61cc817468f921f1746ab406ff0232e 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-27  Jan Hubicka  <jh@suse.cz>
+
+       PR middle-end/46949
+       * gcc.dg/attr-weakref-4.c: New testcase
+
 2011-01-27  Martin Jambor  <mjambor@suse.cz>
 
        PR tree-optimization/47228
diff --git a/gcc/testsuite/gcc.dg/attr-weakref-4.c b/gcc/testsuite/gcc.dg/attr-weakref-4.c
new file mode 100644 (file)
index 0000000..df5fdeb
--- /dev/null
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-require-weak "" } */
+static void __attribute__((weakref("bar"))) foo(void) { } /* { dg-warning "attribute ignored because function is defined" } */
+static int __attribute__((weakref)) a=0; /* { dg-warning "attribute ignored because variable is initialized" } */