This is the mail archive of the gcc-help@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]

RE: retaining unused static functions at -O1


> I have also missed this functionality in the past. If there isn't a PR about it, it would be good to open one.

Thanks Marc, this is PR68002 now. 

However, based on your suggestion, I actually have now a seemingly working patch, which I will try to clean up for submission:

Index: cgraphunit.c
===================================================================
--- cgraphunit.c	(revision 227094)
+++ cgraphunit.c	(working copy)
@@ -451,7 +451,7 @@ cgraph_node::finalize_function (tree dec
      declared inline and nested functions.  These were optimized out
      in the original implementation and it is unclear whether we want
      to change the behavior here.  */
-  if ((!opt_for_fn (decl, optimize)
+  if (((!opt_for_fn (decl, optimize) || flag_keep_static_functions)
        && !node->cpp_implicit_alias
        && !DECL_DISREGARD_INLINE_LIMITS (decl)
        && !DECL_DECLARED_INLINE_P (decl)
Index: testsuite/gcc.dg/PR68002.c
===================================================================
--- testsuite/gcc.dg/PR68002.c	(revision 0)
+++ testsuite/gcc.dg/PR68002.c	(revision 0)
@@ -0,0 +1,7 @@
+/* Ensure static functions can be kept.  */
+/* { dg-do compile } */
+/* { dg-options "-O1 -fkeep-static-functions" } */
+
+static void bar () { }
+
+/* { dg-final { scan-assembler "bar" } } */
Index: common.opt
===================================================================
--- common.opt	(revision 227094)
+++ common.opt	(working copy)
@@ -1584,6 +1584,10 @@ fkeep-inline-functions
 Common Report Var(flag_keep_inline_functions)
 Generate code for functions even if they are fully inlined
 
+fkeep-static-functions
+Common Report Var(flag_keep_static_functions)
+Generate code for static functions even if they are never called 
+
 fkeep-static-consts
 Common Report Var(flag_keep_static_consts) Init(1)
 Emit static const variables even if they are not used




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