2007-10-05 Diego Novillo * lto-function-out.c (output_constructor): Handle constructor elts with NULL indices. (output_expr_operand): Check whether the variable is in the global scope. (lto_output): Only handle statics that are in the global scope. * tree-nested.c (get_trampoline_type): Set DECL_CONTEXT for the new field. Backport 2007-07-26 Doug Kwan * dwarf2out.c: (may_reference_to_unsued) : Renamed from reference_to_unsued as it is now more conservative than before. Replace unreachable assert into a return that tells caller that tree may reference an unused DECL. (rtl_for_decl_init): Rename callee to may_reference_to_usused. testsuite/ChangeLog.lto: * lib/gcc-dg.exp: Enable -flto at -O2. Index: lto-function-out.c =================================================================== --- lto-function-out.c (revision 129034) +++ lto-function-out.c (working copy) @@ -1118,7 +1118,7 @@ output_constructor (struct output_block FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value) { - if (TREE_CODE (purpose) == RANGE_EXPR) + if (purpose && TREE_CODE (purpose) == RANGE_EXPR) { output_record_start (ob, NULL, NULL, LTO_constructor_range); /* Need the types here to reconstruct the ranges. */ @@ -1278,7 +1278,7 @@ output_expr_operand (struct output_block break; case VAR_DECL: - if (TREE_STATIC (expr) || DECL_EXTERNAL (expr)) + if (DECL_CONTEXT (expr) == NULL_TREE) { bool new; output_record_start (ob, NULL, NULL, LTO_var_decl1); @@ -2191,10 +2191,11 @@ lto_output (void) if (node->analyzed && cgraph_is_master_clone (node, false)) output_function (node->decl); - /* Process the static vars that have initializers or + /* Process the global static vars that have initializers or constructors. */ FOR_EACH_STATIC_INITIALIZER (vnode) - output_constructor_or_init (vnode->decl); + if (DECL_CONTEXT (vnode->decl) == NULL_TREE) + output_constructor_or_init (vnode->decl); /* Put back the assembly section that was there before we started writing lto info. */ Index: testsuite/lib/gcc-dg.exp =================================================================== --- testsuite/lib/gcc-dg.exp (revision 129034) +++ testsuite/lib/gcc-dg.exp (working copy) @@ -42,7 +42,7 @@ if ![info exists TORTURE_OPTIONS] { set TORTURE_OPTIONS [list \ { -O0 } \ { -O1 } \ - { -O2 } \ + { -O2 -flto } \ { -O3 -fomit-frame-pointer } \ { -O3 -fomit-frame-pointer -funroll-loops } \ { -O3 -fomit-frame-pointer -funroll-all-loops -finline-functions } \ Index: dwarf2out.c =================================================================== --- dwarf2out.c (revision 129034) +++ dwarf2out.c (working copy) @@ -10374,9 +10374,10 @@ add_const_value_attribute (dw_die_ref di /* Determine whether the evaluation of EXPR references any variables or functions which aren't otherwise used (and therefore may not be output). */ + static tree -reference_to_unused (tree * tp, int * walk_subtrees, - void * data ATTRIBUTE_UNUSED) +may_reference_to_unused (tree * tp, int * walk_subtrees, + void * data ATTRIBUTE_UNUSED) { if (! EXPR_P (*tp) && ! GIMPLE_STMT_P (*tp) && ! CONSTANT_CLASS_P (*tp)) *walk_subtrees = 0; @@ -10388,7 +10389,12 @@ reference_to_unused (tree * tp, int * wa return NULL_TREE; else if (!cgraph_global_info_ready && (TREE_CODE (*tp) == VAR_DECL || TREE_CODE (*tp) == FUNCTION_DECL)) - gcc_unreachable (); + { + /* We don't know if a DECL is really unsued until we have seen + the complete call graph. With no reliable information, we need to + be conservative. */ + return *tp; + } else if (DECL_P (*tp) && TREE_CODE (*tp) == VAR_DECL) { struct varpool_node *node = varpool_node (*tp); @@ -10444,7 +10450,7 @@ rtl_for_decl_init (tree init, tree type) immediate RTL constant, expand it now. We must be careful not to reference variables which won't be output. */ else if (initializer_constant_valid_p (init, type) - && ! walk_tree (&init, reference_to_unused, NULL, NULL)) + && ! walk_tree (&init, may_reference_to_unused, NULL, NULL)) { /* Convert vector CONSTRUCTOR initializers to VECTOR_CST if possible. */ Index: tree-nested.c =================================================================== --- tree-nested.c (revision 129034) +++ tree-nested.c (working copy) @@ -429,6 +429,7 @@ get_trampoline_type (void) TYPE_NAME (record) = get_identifier ("__builtin_trampoline"); TYPE_FIELDS (record) = t; layout_type (record); + DECL_CONTEXT (t) = record; return record; }