]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/cgraphunit.c
PR middle-end/46949
[thirdparty/gcc.git] / gcc / cgraphunit.c
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);
     }
 }