------- Additional Comments From bje at gcc dot gnu dot org  2004-12-02 05:43 
-------
Trivial test case:

  static int f () { return 3; } 
  int main() { return f (); }

Here, cgraph_optimize() decides to inline f() into main() and then eliminates
the node for f() from the call graph.  cgraph_expand_function() never emits
assembly for f(), so no DIE is emitted either.  The cgraph dump file summarises
the situation:

Optimized callgraph:

main/1: 13 insns (5 after inlining) needed tree inlinable
  called by: 
  calls: f/0 (inlined) 
f/0: (inline copy in main/1) 2 insns reachable tree local inlinable
  called by: main/1 (inlined) 
  calls: 

Final callgraph:

main/1: 13 insns (5 after inlining) needed inlinable asm_written
  called by: 
  calls: 

The dilemma here is that we really don't want to emit the real f(), since it is
never called in the translation unit and we don't want to waste text doing so. 
All we want is debugging information for f().

The following crude patch makes things work, but it's wrong:

Index: cgraphunit.c
===================================================================
RCS file: /home/bje/gcc-cvs/gcc/gcc/cgraphunit.c,v
retrieving revision 1.90
diff -u -p -r1.90 cgraphunit.c
--- cgraphunit.c        18 Nov 2004 00:18:43 -0000      1.90
+++ cgraphunit.c        2 Dec 2004 05:41:16 -0000
@@ -786,6 +786,14 @@ cgraph_mark_functions_to_output (void)
          && !TREE_ASM_WRITTEN (decl)
          && !DECL_EXTERNAL (decl))
        node->output = 1;
+      else if (DECL_SAVED_TREE (decl)
+              && node->global.inlined_to
+              && !node->needed
+              && node->reachable
+              && node->local.local
+              && !TREE_ASM_WRITTEN (decl)
+              && !DECL_EXTERNAL (decl))
+       node->output = 1;
       else
        {
          /* We should've reclaimed all functions that are not needed.  */
@@ -811,9 +819,6 @@ static void
 cgraph_expand_function (struct cgraph_node *node)
 {
   tree decl = node->decl;
-
-  /* We ought to not compile any inline clones.  */
-  gcc_assert (!node->global.inlined_to);
 
   if (flag_unit_at_a_time)
     announce_function (decl);

Any ideas on how to proceed?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17924

Reply via email to