Hi,

On Thu, 31 Mar 2011, Richard Guenther wrote:

> > In the meanwhile, is the below version okay?
> 
> If it bootstraps & tests ok then yes.  The java parts look obvious.

So, we indeed can't remove the other calls to 
canonicalize_constructor_val, because of local ctors.  And fortran has a 
similar problem with java.  Instead of fixing up all these places of 
resetting cfun (where otherwise the frontends don't deal at all with it, 
it's mostly just set from the various cgraph routines), I decided to 
simply clear this at the appropriate place in 
cgraph_finalize_compilation_unit.

Regstrapping in progress again.  Still okay if that works?


Ciao,
Michael.
-- 
        * cgraphbuild.c (record_reference): Canonicalize constructor
        values.
        * gimple-fold.c (canonicalize_constructor_val): Accept being called
        without function context.
        * cgraphunit.c (cgraph_finalize_compilation_unit): Clear
        current_function_decl and cfun.

Index: cgraphbuild.c
===================================================================
--- cgraphbuild.c.orig  2011-04-03 11:28:45.000000000 +0200
+++ cgraphbuild.c       2011-04-03 11:31:21.000000000 +0200
@@ -53,6 +53,12 @@ record_reference (tree *tp, int *walk_su
   tree decl;
   struct record_reference_ctx *ctx = (struct record_reference_ctx *)data;
 
+  t = canonicalize_constructor_val (t);
+  if (!t)
+    t = *tp;
+  else if (t != *tp)
+    *tp = t;
+
   switch (TREE_CODE (t))
     {
     case VAR_DECL:
Index: gimple-fold.c
===================================================================
--- gimple-fold.c.orig  2011-04-03 11:28:45.000000000 +0200
+++ gimple-fold.c       2011-04-03 11:31:21.000000000 +0200
@@ -106,7 +106,7 @@ can_refer_decl_in_current_unit_p (tree d
   return true;
 }
 
-/* CVAL is value taken from DECL_INITIAL of variable.  Try to transorm it into
+/* CVAL is value taken from DECL_INITIAL of variable.  Try to transform it into
    acceptable form for is_gimple_min_invariant.   */
 
 tree
@@ -131,10 +131,9 @@ canonicalize_constructor_val (tree cval)
              || TREE_CODE (base) == FUNCTION_DECL)
          && !can_refer_decl_in_current_unit_p (base))
        return NULL_TREE;
-      if (base && TREE_CODE (base) == VAR_DECL)
+      if (cfun && base && TREE_CODE (base) == VAR_DECL)
        add_referenced_var (base);
-      /* We never have the chance to fixup types in global initializers
-         during gimplification.  Do so here.  */
+      /* Fixup types in global initializers.  */
       if (TREE_TYPE (TREE_TYPE (cval)) != TREE_TYPE (TREE_OPERAND (cval, 0)))
        cval = build_fold_addr_expr (TREE_OPERAND (cval, 0));
     }
Index: cgraphunit.c
===================================================================
--- cgraphunit.c.orig   2011-04-03 11:41:46.000000000 +0200
+++ cgraphunit.c        2011-04-03 11:50:01.000000000 +0200
@@ -1066,6 +1066,11 @@ cgraph_finalize_compilation_unit (void)
 {
   timevar_push (TV_CGRAPH);
 
+  /* If we're here there's no current function anymore.  Some frontends
+     are lazy in clearing these.  */
+  current_function_decl = NULL;
+  set_cfun (NULL);
+
   /* Do not skip analyzing the functions if there were errors, we
      miss diagnostics for following functions otherwise.  */
 

Reply via email to