[tree-ssa] C++ inlining vs current_function_decl

law@redhat.com law@redhat.com
Tue Apr 15 21:16:00 GMT 2003



A few weeks ago I mentioned a problem I had run into when enabling
the tree-ssa optimizers for C++ code.  Specifically:

  C++ inlining can clobber "current_function_decl".

  The inliner calls cp_cannot_inline_tree_fn, which in turn may call
  instantiate_decl, which may call start_function which in turn 
  resets current_function_decl.  However, no code restores the original
  value of current_function_decl.

  This can cause problems with the tree-ssa optimizers, particularly the
  code to create new variables (they get created in the wrong funtion).


Jason mentioned that instantiate_decl attempts to avoid clobbering
state and that the behavior of global_bindings_p may be at fault.

I tweaked global_bindings_p, but that resulted in a whole new set
of problems with failure to emit assembly code for some ctors/dtors.
Presumably, the use of global_bindings_p within finish_file depends
on the current behavior of global_bindings_p.

So instead I made a slight tweak to instantiate_decl to perform the
check we need.

This fixes a boatload of problems when running C++ code through the
tree-ssa optimizers.

	* pt.c (instantiate_decl): If CFUN is null, then we will
	need to push to the toplevel.

Index: pt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/pt.c,v
retrieving revision 1.591.2.26
diff -c -3 -p -r1.591.2.26 pt.c
*** pt.c	9 Apr 2003 19:28:30 -0000	1.591.2.26
--- pt.c	15 Apr 2003 21:14:34 -0000
*************** instantiate_decl (d, defer_ok)
*** 10927,10933 ****
        goto out;
      }
  
!   need_push = !global_bindings_p ();
    if (need_push)
      push_to_top_level ();
  
--- 10927,10933 ----
        goto out;
      }
  
!   need_push = !cfun || !global_bindings_p ();
    if (need_push)
      push_to_top_level ();
  







More information about the Gcc-patches mailing list