This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: retaining unused static functions at -O1
- From: "VandeVondele Joost" <joost dot vandevondele at mat dot ethz dot ch>
- To: "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Sat, 17 Oct 2015 12:37:07 +0000
- Subject: RE: retaining unused static functions at -O1
- Authentication-results: sourceware.org; auth=none
- References: <908103EDB4893A42920B21D3568BFD9339EE9EB6 at MBX13 dot d dot ethz dot ch>,<alpine dot DEB dot 2 dot 20 dot 1510170938260 dot 2029 at laptop-mg dot saclay dot inria dot fr>
> 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