diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index d60161e2f39bd75650037bce1edb51098268b416..bd846a00abad22a403d2e967deb9fa1fcfa1b38f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2013-08-01  Jan Hubicka  <jh@suse.cz>
+
+	* cgraph.h (release_function_body): Declare.
+	* tree.c (free_lang_data_in_decl): Free, parameters and return values
+	of unused delcarations.
+
 2013-08-01  Kyrylo Tkachov  <kyrylo.tkachov@arm.com>
 
 	* config/arm/arm.md (minmax_arithsi_non_canon): Emit canonical RTL form
diff --git a/gcc/cgraph.h b/gcc/cgraph.h
index 99acb62984c5ce78032a624460e1db33fec57a0d..9b76b67d2f4d05a4225503ff999e229505b41fc1 100644
--- a/gcc/cgraph.h
+++ b/gcc/cgraph.h
@@ -606,6 +606,7 @@ void debug_cgraph_node (struct cgraph_node *);
 void cgraph_remove_edge (struct cgraph_edge *);
 void cgraph_remove_node (struct cgraph_node *);
 void cgraph_release_function_body (struct cgraph_node *);
+void release_function_body (tree);
 void cgraph_node_remove_callees (struct cgraph_node *node);
 struct cgraph_edge *cgraph_create_edge (struct cgraph_node *,
 					struct cgraph_node *,
diff --git a/gcc/tree.c b/gcc/tree.c
index ab1173525c71396621f4888cf3a434d61660e62a..c9f47d26260d1f3e5de4c24ac717f1ee84e27e9c 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -4886,6 +4886,20 @@ free_lang_data_in_decl (tree decl)
 
  if (TREE_CODE (decl) == FUNCTION_DECL)
     {
+      struct cgraph_node *node;
+      if (!(node = cgraph_get_node (decl))
+	  || (!node->symbol.definition && !node->clones))
+	{
+	  if (node)
+	    cgraph_release_function_body (node);
+	  else
+	    {
+	      release_function_body (decl);
+	      DECL_ARGUMENTS (decl) = NULL;
+	      DECL_RESULT (decl) = NULL;
+	      DECL_INITIAL (decl) = error_mark_node;
+	    }
+	}
       if (gimple_has_body_p (decl))
 	{
 	  tree t;