Hi, this patch changes most of current calls to cgraph_node to calls to cgraph_get_node. The function should never return NULL in he contexts of the callers below and either the probability is so low that it does not warrant an assert (like cgraph_get_node (current_function_decl) or the result is immediately dereferenced and so would segfault anyway. Bootstrapped and tested separately on x86_64-linux without any problems, tests on other platforms (together with the other patches) in progress. OK for trunk? Thanks, Martin 2011-04-06 Martin Jambor * except.c (set_nothrow_function_flags): Call cgraph_get_node instead of cgraph_node. * final.c (rest_of_clean_state): Likewise. * gimple-iterator.c (update_call_edge_frequencies): Likewise. * passes.c (pass_init_dump_file): Likewise. (execute_all_ipa_transforms): Likewise. (function_called_by_processed_nodes_p): Likewise. * predict.c (maybe_hot_frequency_p): Likewise. (probably_never_executed_bb_p): Likewise. (compute_function_frequency): Likewise. * tree-nested.c (check_for_nested_with_variably_modified): Likewise. (unnest_nesting_tree_1): Likewise. (lower_nested_functions): Likewise. * tree-optimize.c (execute_fixup_cfg): Likewise. (tree_rest_of_compilation): Likewise. * tree-profile.c (gimple_gen_ic_func_profiler): Likewise. * tree-sra.c (ipa_early_sra): Likewise. * tree-ssa-loop-ivopts.c (computation_cost): Likewise. * config/i386/i386.c (ix86_compute_frame_layout): Likewise. * ipa.c (record_cdtor_fn): Likewise. * ipa-inline.c (cgraph_early_inlining): Likewise. (compute_inline_parameters_for_current): Likewise. * ipa-prop.c (ipa_make_edge_direct_to_target): Likewise. * ipa-pure-const.c (local_pure_const): Likewise. * ipa-split.c (split_function): Likewise. (execute_split_functions): Likewise. * cgraphbuild.c (build_cgraph_edges): Likewise. (rebuild_cgraph_edges): Likewise. (cgraph_rebuild_references): Likewise. (remove_cgraph_callee_edges): Likewise. * cgraphunit.c (cgraph_mark_if_needed): Likewise. (verify_cgraph_node): Likewise. (cgraph_analyze_functions): Likewise. (cgraph_preserve_function_body_p): Likewise. (save_inline_function_body): Likewise. (save_inline_function_body): Likewise. * tree-inline.c (copy_bb): Likewise. (optimize_inline_calls): Likewise. Index: src/gcc/except.c =================================================================== --- src.orig/gcc/except.c +++ src/gcc/except.c @@ -1879,11 +1879,11 @@ set_nothrow_function_flags (void) } } if (crtl->nothrow - && (cgraph_function_body_availability (cgraph_node + && (cgraph_function_body_availability (cgraph_get_node (current_function_decl)) >= AVAIL_AVAILABLE)) { - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); struct cgraph_edge *e; for (e = node->callers; e; e = e->next_caller) e->can_throw_external = false; Index: src/gcc/final.c =================================================================== --- src.orig/gcc/final.c +++ src/gcc/final.c @@ -4283,7 +4283,7 @@ rest_of_clean_state (void) else { const char *aname; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); aname = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl))); Index: src/gcc/gimple-iterator.c =================================================================== --- src.orig/gcc/gimple-iterator.c +++ src/gcc/gimple-iterator.c @@ -84,7 +84,7 @@ update_call_edge_frequencies (gimple_seq to avoid calling them if we never see any calls. */ if (cfun_node == NULL) { - cfun_node = cgraph_node (current_function_decl); + cfun_node = cgraph_get_node (current_function_decl); bb_freq = (compute_call_stmt_bb_frequency (current_function_decl, bb)); } Index: src/gcc/passes.c =================================================================== --- src.orig/gcc/passes.c +++ src/gcc/passes.c @@ -1343,7 +1343,7 @@ pass_init_dump_file (struct opt_pass *pa if (dump_file && current_function_decl) { const char *dname, *aname; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); dname = lang_hooks.decl_printable_name (current_function_decl, 2); aname = (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl))); @@ -1475,7 +1475,7 @@ execute_all_ipa_transforms (void) struct cgraph_node *node; if (!cfun) return; - node = cgraph_node (current_function_decl); + node = cgraph_get_node (current_function_decl); if (node->ipa_transforms_to_apply) { @@ -2029,7 +2029,9 @@ bool function_called_by_processed_nodes_p (void) { struct cgraph_edge *e; - for (e = cgraph_node (current_function_decl)->callers; e; e = e->next_caller) + for (e = cgraph_get_node (current_function_decl)->callers; + e; + e = e->next_caller) { if (e->caller->decl == current_function_decl) continue; Index: src/gcc/predict.c =================================================================== --- src.orig/gcc/predict.c +++ src/gcc/predict.c @@ -113,7 +113,7 @@ static const struct predictor_info predi static inline bool maybe_hot_frequency_p (int freq) { - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); if (!profile_info || !flag_branch_probabilities) { if (node->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED) @@ -203,7 +203,8 @@ probably_never_executed_bb_p (const_basi if (profile_info && flag_branch_probabilities) return ((bb->count + profile_info->runs / 2) / profile_info->runs) == 0; if ((!profile_info || !flag_branch_probabilities) - && cgraph_node (current_function_decl)->frequency == NODE_FREQUENCY_UNLIKELY_EXECUTED) + && (cgraph_get_node (current_function_decl)->frequency + == NODE_FREQUENCY_UNLIKELY_EXECUTED)) return true; return false; } @@ -2225,7 +2226,7 @@ void compute_function_frequency (void) { basic_block bb; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); if (DECL_STATIC_CONSTRUCTOR (current_function_decl) || MAIN_NAME_P (DECL_NAME (current_function_decl))) node->only_called_at_startup = true; Index: src/gcc/tree-nested.c =================================================================== --- src.orig/gcc/tree-nested.c +++ src/gcc/tree-nested.c @@ -693,7 +693,7 @@ walk_all_functions (walk_stmt_fn callbac static bool check_for_nested_with_variably_modified (tree fndecl, tree orig_fndecl) { - struct cgraph_node *cgn = cgraph_node (fndecl); + struct cgraph_node *cgn = cgraph_get_node (fndecl); tree arg; for (cgn = cgn->nested; cgn ; cgn = cgn->next_nested) @@ -2523,13 +2523,13 @@ finalize_nesting_tree (struct nesting_in static void unnest_nesting_tree_1 (struct nesting_info *root) { - struct cgraph_node *node = cgraph_node (root->context); + struct cgraph_node *node = cgraph_get_node (root->context); /* For nested functions update the cgraph to reflect unnesting. We also delay finalizing of these functions up to this point. */ if (node->origin) { - cgraph_unnest_node (cgraph_node (root->context)); + cgraph_unnest_node (node); cgraph_finalize_function (root->context, true); } } @@ -2583,7 +2583,7 @@ lower_nested_functions (tree fndecl) struct nesting_info *root; /* If there are no nested functions, there's nothing to do. */ - cgn = cgraph_node (fndecl); + cgn = cgraph_get_node (fndecl); if (!cgn->nested) return; Index: src/gcc/tree-optimize.c =================================================================== --- src.orig/gcc/tree-optimize.c +++ src/gcc/tree-optimize.c @@ -247,12 +247,13 @@ execute_fixup_cfg (void) edge_iterator ei; if (ENTRY_BLOCK_PTR->count) - count_scale = (cgraph_node (current_function_decl)->count * REG_BR_PROB_BASE - + ENTRY_BLOCK_PTR->count / 2) / ENTRY_BLOCK_PTR->count; + count_scale = ((cgraph_get_node (current_function_decl)->count + * REG_BR_PROB_BASE + ENTRY_BLOCK_PTR->count / 2) + / ENTRY_BLOCK_PTR->count); else count_scale = REG_BR_PROB_BASE; - ENTRY_BLOCK_PTR->count = cgraph_node (current_function_decl)->count; + ENTRY_BLOCK_PTR->count = cgraph_get_node (current_function_decl)->count; EXIT_BLOCK_PTR->count = (EXIT_BLOCK_PTR->count * count_scale + REG_BR_PROB_BASE / 2) / REG_BR_PROB_BASE; @@ -457,7 +458,7 @@ tree_rest_of_compilation (tree fndecl) gimple_set_body (fndecl, NULL); if (DECL_STRUCT_FUNCTION (fndecl) == 0 - && !cgraph_node (fndecl)->origin) + && !cgraph_get_node (fndecl)->origin) { /* Stop pointing to the local nodes about to be freed. But DECL_INITIAL must remain nonzero so we know this Index: src/gcc/tree-profile.c =================================================================== --- src.orig/gcc/tree-profile.c +++ src/gcc/tree-profile.c @@ -346,7 +346,7 @@ gimple_gen_ic_profiler (histogram_value void gimple_gen_ic_func_profiler (void) { - struct cgraph_node * c_node = cgraph_node (current_function_decl); + struct cgraph_node * c_node = cgraph_get_node (current_function_decl); gimple_stmt_iterator gsi; gimple stmt1, stmt2; tree tree_uid, cur_func, counter_ptr, ptr_var, void0; Index: src/gcc/tree-sra.c =================================================================== --- src.orig/gcc/tree-sra.c +++ src/gcc/tree-sra.c @@ -4502,7 +4502,7 @@ ipa_sra_preliminary_function_checks (str static unsigned int ipa_early_sra (void) { - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); ipa_parm_adjustment_vec adjustments; int ret = 0; Index: src/gcc/tree-ssa-loop-ivopts.c =================================================================== --- src.orig/gcc/tree-ssa-loop-ivopts.c +++ src/gcc/tree-ssa-loop-ivopts.c @@ -2849,7 +2849,7 @@ computation_cost (tree expr, bool speed) unsigned cost; /* Avoid using hard regs in ways which may be unsupported. */ int regno = LAST_VIRTUAL_REGISTER + 1; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); enum node_frequency real_frequency = node->frequency; node->frequency = NODE_FREQUENCY_NORMAL; Index: src/gcc/config/i386/i386.c =================================================================== --- src.orig/gcc/config/i386/i386.c +++ src/gcc/config/i386/i386.c @@ -9298,7 +9298,7 @@ ix86_compute_frame_layout (struct ix86_f && cfun->machine->use_fast_prologue_epilogue_nregs != frame->nregs) { int count = frame->nregs; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); cfun->machine->use_fast_prologue_epilogue_nregs = count; Index: src/gcc/ipa.c =================================================================== --- src.orig/gcc/ipa.c +++ src/gcc/ipa.c @@ -1626,7 +1626,7 @@ record_cdtor_fn (struct cgraph_node *nod VEC_safe_push (tree, heap, static_ctors, node->decl); if (DECL_STATIC_DESTRUCTOR (node->decl)) VEC_safe_push (tree, heap, static_dtors, node->decl); - node = cgraph_node (node->decl); + node = cgraph_get_node (node->decl); node->local.disregard_inline_limits = 1; } Index: src/gcc/ipa-inline.c =================================================================== --- src.orig/gcc/ipa-inline.c +++ src/gcc/ipa-inline.c @@ -1718,7 +1718,7 @@ static GTY ((length ("nnodes"))) struct static unsigned int cgraph_early_inlining (void) { - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); unsigned int todo = 0; int iterations = 0; bool inlined = false; @@ -1996,7 +1996,7 @@ compute_inline_parameters (struct cgraph static unsigned int compute_inline_parameters_for_current (void) { - compute_inline_parameters (cgraph_node (current_function_decl)); + compute_inline_parameters (cgraph_get_node (current_function_decl)); return 0; } Index: src/gcc/ipa-prop.c =================================================================== --- src.orig/gcc/ipa-prop.c +++ src/gcc/ipa-prop.c @@ -1648,7 +1648,7 @@ ipa_make_edge_direct_to_target (struct c target = TREE_OPERAND (target, 0); if (TREE_CODE (target) != FUNCTION_DECL) return NULL; - callee = cgraph_node (target); + callee = cgraph_get_node (target); if (!callee) return NULL; ipa_check_create_node_params (); Index: src/gcc/ipa-pure-const.c =================================================================== --- src.orig/gcc/ipa-pure-const.c +++ src/gcc/ipa-pure-const.c @@ -1563,7 +1563,7 @@ local_pure_const (void) bool skip; struct cgraph_node *node; - node = cgraph_node (current_function_decl); + node = cgraph_get_node (current_function_decl); skip = skip_function_for_local_pure_const (node); if (!warn_suggest_attribute_const && !warn_suggest_attribute_pure Index: src/gcc/ipa-split.c =================================================================== --- src.orig/gcc/ipa-split.c +++ src/gcc/ipa-split.c @@ -1080,7 +1080,7 @@ split_function (struct split_point *spli /* Now create the actual clone. */ rebuild_cgraph_edges (); - node = cgraph_function_versioning (cgraph_node (current_function_decl), + node = cgraph_function_versioning (cgraph_get_node (current_function_decl), NULL, NULL, args_to_skip, split_point->split_bbs, @@ -1093,7 +1093,7 @@ split_function (struct split_point *spli DECL_BUILT_IN_CLASS (node->decl) = NOT_BUILT_IN; DECL_FUNCTION_CODE (node->decl) = (enum built_in_function) 0; } - cgraph_node_remove_callees (cgraph_node (current_function_decl)); + cgraph_node_remove_callees (cgraph_get_node (current_function_decl)); if (!split_part_return_p) TREE_THIS_VOLATILE (node->decl) = 1; if (dump_file) @@ -1265,7 +1265,7 @@ execute_split_functions (void) basic_block bb; int overall_time = 0, overall_size = 0; int todo = 0; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); if (flags_from_decl_or_type (current_function_decl) & ECF_NORETURN) { Index: src/gcc/cgraphbuild.c =================================================================== --- src.orig/gcc/cgraphbuild.c +++ src/gcc/cgraphbuild.c @@ -340,7 +340,7 @@ static unsigned int build_cgraph_edges (void) { basic_block bb; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); struct pointer_set_t *visited_nodes = pointer_set_create (); gimple_stmt_iterator gsi; tree decl; @@ -451,7 +451,7 @@ unsigned int rebuild_cgraph_edges (void) { basic_block bb; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); gimple_stmt_iterator gsi; cgraph_node_remove_callees (node); @@ -502,7 +502,7 @@ void cgraph_rebuild_references (void) { basic_block bb; - struct cgraph_node *node = cgraph_node (current_function_decl); + struct cgraph_node *node = cgraph_get_node (current_function_decl); gimple_stmt_iterator gsi; ipa_remove_all_references (&node->ref_list); @@ -549,7 +549,7 @@ struct gimple_opt_pass pass_rebuild_cgra static unsigned int remove_cgraph_callee_edges (void) { - cgraph_node_remove_callees (cgraph_node (current_function_decl)); + cgraph_node_remove_callees (cgraph_get_node (current_function_decl)); return 0; } Index: src/gcc/cgraphunit.c =================================================================== --- src.orig/gcc/cgraphunit.c +++ src/gcc/cgraphunit.c @@ -390,7 +390,7 @@ cgraph_finalize_function (tree decl, boo void cgraph_mark_if_needed (tree decl) { - struct cgraph_node *node = cgraph_node (decl); + struct cgraph_node *node = cgraph_get_node (decl); if (node->local.finalized && cgraph_decide_is_function_needed (node, decl)) cgraph_mark_needed_node (node); } @@ -667,7 +667,7 @@ verify_cgraph_node (struct cgraph_node * && cgraph_get_node (decl) && (e->callee->former_clone_of != cgraph_get_node (decl)->decl) - && !clone_of_p (cgraph_node (decl), + && !clone_of_p (cgraph_get_node (decl), e->callee)) { error ("edge points to wrong declaration:"); @@ -995,10 +995,12 @@ cgraph_analyze_functions (void) /* If decl is a clone of an abstract function, mark that abstract function so that we don't release its body. The DECL_INITIAL() of that - abstract function declaration will be later needed to output debug info. */ + abstract function declaration will be later needed to output debug + info. */ if (DECL_ABSTRACT_ORIGIN (decl)) { - struct cgraph_node *origin_node = cgraph_node (DECL_ABSTRACT_ORIGIN (decl)); + struct cgraph_node *origin_node; + origin_node = cgraph_get_node (DECL_ABSTRACT_ORIGIN (decl)); origin_node->abstract_and_needed = true; } @@ -1766,7 +1768,7 @@ cgraph_preserve_function_body_p (tree de gcc_assert (cgraph_global_info_ready); /* Look if there is any clone around. */ - node = cgraph_node (decl); + node = cgraph_get_node (decl); if (node->clones) return true; return false; @@ -2106,7 +2108,7 @@ save_inline_function_body (struct cgraph { struct cgraph_node *first_clone, *n; - gcc_assert (node == cgraph_node (node->decl)); + gcc_assert (node == cgraph_get_node (node->decl)); cgraph_lower_function (node); @@ -2114,7 +2116,7 @@ save_inline_function_body (struct cgraph first_clone->decl = copy_node (node->decl); cgraph_insert_node_to_hashtable (first_clone); - gcc_assert (first_clone == cgraph_node (first_clone->decl)); + gcc_assert (first_clone == cgraph_get_node (first_clone->decl)); if (first_clone->next_sibling_clone) { for (n = first_clone->next_sibling_clone; n->next_sibling_clone; n = n->next_sibling_clone) Index: src/gcc/tree-inline.c =================================================================== --- src.orig/gcc/tree-inline.c +++ src/gcc/tree-inline.c @@ -1727,7 +1727,7 @@ copy_bb (copy_body_data *id, basic_block && id->transform_call_graph_edges == CB_CGE_MOVE_CLONES)) && (fn = gimple_call_fndecl (stmt)) != NULL) { - struct cgraph_node *dest = cgraph_node (fn); + struct cgraph_node *dest = cgraph_get_node (fn); /* We have missing edge in the callgraph. This can happen when previous inlining turned an indirect call into a @@ -4158,7 +4158,7 @@ optimize_inline_calls (tree fn) /* Clear out ID. */ memset (&id, 0, sizeof (id)); - id.src_node = id.dst_node = cgraph_node (fn); + id.src_node = id.dst_node = cgraph_get_node (fn); gcc_assert (id.dst_node->analyzed); id.dst_fn = fn; /* Or any functions that aren't finished yet. */