static void append_to_statement_list_1 (tree t, tree *list_p) { tree list = *list_p; tree_stmt_iterator i; if (!list) { if (t && TREE_CODE (t) == STATEMENT_LIST) { *list_p = t; return; } *list_p = list = alloc_stmt_list (); } else if (TREE_CODE (list) != STATEMENT_LIST) { tree first = list; *list_p = list = alloc_stmt_list (); i = tsi_last (list); tsi_link_after (&i, first, TSI_CONTINUE_LINKING); } i = tsi_last (list); tsi_link_after (&i, t, TSI_CONTINUE_LINKING); }
/* If there are any handlers for this range, issue end of range, and then all handler blocks */ void expand_end_java_handler (struct eh_range *range) { tree handler = range->handlers; if (handler) { tree exc_obj = build_exception_object_var (); tree catches = make_node (STATEMENT_LIST); tree_stmt_iterator catches_i = tsi_last (catches); tree *body; for (; handler; handler = TREE_CHAIN (handler)) { tree type, eh_type, x; tree stmts = make_node (STATEMENT_LIST); tree_stmt_iterator stmts_i = tsi_last (stmts); type = TREE_PURPOSE (handler); if (type == NULL) type = throwable_type_node; eh_type = prepare_eh_table_type (type); x = build_call_expr (builtin_decl_explicit (BUILT_IN_EH_POINTER), 1, integer_zero_node); x = build2 (MODIFY_EXPR, void_type_node, exc_obj, x); tsi_link_after (&stmts_i, x, TSI_CONTINUE_LINKING); x = build1 (GOTO_EXPR, void_type_node, TREE_VALUE (handler)); tsi_link_after (&stmts_i, x, TSI_CONTINUE_LINKING); x = build2 (CATCH_EXPR, void_type_node, eh_type, stmts); tsi_link_after (&catches_i, x, TSI_CONTINUE_LINKING); /* Throwable can match anything in Java, and therefore any subsequent handlers are unreachable. */ /* ??? If we're assured of no foreign language exceptions, we'd be better off using NULL as the exception type for the catch. */ if (type == throwable_type_node) break; } body = get_stmts (); *body = build2 (TRY_CATCH_EXPR, void_type_node, *body, catches); } #if defined(DEBUG_JAVA_BINDING_LEVELS) indent (); fprintf (stderr, "expand end handler pc %d <-- %d\n", current_pc, range->start_pc); #endif /* defined(DEBUG_JAVA_BINDING_LEVELS) */ }
static void cp_ubsan_maybe_instrument_return (tree fndecl) { if (VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fndecl))) || DECL_CONSTRUCTOR_P (fndecl) || DECL_DESTRUCTOR_P (fndecl) || !targetm.warn_func_return (fndecl)) return; tree t = DECL_SAVED_TREE (fndecl); while (t) { switch (TREE_CODE (t)) { case BIND_EXPR: t = BIND_EXPR_BODY (t); continue; case TRY_FINALLY_EXPR: t = TREE_OPERAND (t, 0); continue; case STATEMENT_LIST: { tree_stmt_iterator i = tsi_last (t); if (!tsi_end_p (i)) { t = tsi_stmt (i); continue; } } break; case RETURN_EXPR: return; default: break; } break; } if (t == NULL_TREE) return; t = DECL_SAVED_TREE (fndecl); if (TREE_CODE (t) == BIND_EXPR && TREE_CODE (BIND_EXPR_BODY (t)) == STATEMENT_LIST) { tree_stmt_iterator i = tsi_last (BIND_EXPR_BODY (t)); t = ubsan_instrument_return (DECL_SOURCE_LOCATION (fndecl)); tsi_link_after (&i, t, TSI_NEW_STMT); } }
static void lower_function_body (void) { struct lower_data data; tree *body_p = &DECL_SAVED_TREE (current_function_decl); tree bind = *body_p; tree_stmt_iterator i; tree t, x; gcc_assert (TREE_CODE (bind) == BIND_EXPR); data.block = DECL_INITIAL (current_function_decl); BLOCK_SUBBLOCKS (data.block) = NULL_TREE; BLOCK_CHAIN (data.block) = NULL_TREE; TREE_ASM_WRITTEN (data.block) = 1; data.return_statements = NULL_TREE; *body_p = alloc_stmt_list (); i = tsi_start (*body_p); tsi_link_after (&i, bind, TSI_NEW_STMT); lower_bind_expr (&i, &data); i = tsi_last (*body_p); /* If the function falls off the end, we need a null return statement. If we've already got one in the return_statements list, we don't need to do anything special. Otherwise build one by hand. */ if (block_may_fallthru (*body_p) && (data.return_statements == NULL || TREE_OPERAND (TREE_VALUE (data.return_statements), 0) != NULL)) { x = build (RETURN_EXPR, void_type_node, NULL); SET_EXPR_LOCATION (x, cfun->function_end_locus); tsi_link_after (&i, x, TSI_CONTINUE_LINKING); } /* If we lowered any return statements, emit the representative at the end of the function. */ for (t = data.return_statements ; t ; t = TREE_CHAIN (t)) { x = build (LABEL_EXPR, void_type_node, TREE_PURPOSE (t)); tsi_link_after (&i, x, TSI_CONTINUE_LINKING); /* Remove the line number from the representative return statement. It now fills in for many such returns. Failure to remove this will result in incorrect results for coverage analysis. */ x = TREE_VALUE (t); #ifdef USE_MAPPED_LOCATION SET_EXPR_LOCATION (x, UNKNOWN_LOCATION); #else SET_EXPR_LOCUS (x, NULL); #endif tsi_link_after (&i, x, TSI_CONTINUE_LINKING); } gcc_assert (data.block == DECL_INITIAL (current_function_decl)); BLOCK_SUBBLOCKS (data.block) = blocks_nreverse (BLOCK_SUBBLOCKS (data.block)); clear_block_marks (data.block); }
static void mf_build_check_statement_for (tree base, tree limit, block_stmt_iterator *instr_bsi, location_t *locus, tree dirflag) { tree_stmt_iterator head, tsi; block_stmt_iterator bsi; basic_block cond_bb, then_bb, join_bb; edge e; tree cond, t, u, v; tree mf_base; tree mf_elem; tree mf_limit; /* We first need to split the current basic block, and start altering the CFG. This allows us to insert the statements we're about to construct into the right basic blocks. */ cond_bb = bb_for_stmt (bsi_stmt (*instr_bsi)); bsi = *instr_bsi; bsi_prev (&bsi); if (! bsi_end_p (bsi)) e = split_block (cond_bb, bsi_stmt (bsi)); else e = split_block_after_labels (cond_bb); cond_bb = e->src; join_bb = e->dest; /* A recap at this point: join_bb is the basic block at whose head is the gimple statement for which this check expression is being built. cond_bb is the (possibly new, synthetic) basic block the end of which will contain the cache-lookup code, and a conditional that jumps to the cache-miss code or, much more likely, over to join_bb. */ /* Create the bb that contains the cache-miss fallback block (mf_check). */ then_bb = create_empty_bb (cond_bb); make_edge (cond_bb, then_bb, EDGE_TRUE_VALUE); make_single_succ_edge (then_bb, join_bb, EDGE_FALLTHRU); /* Mark the pseudo-fallthrough edge from cond_bb to join_bb. */ e = find_edge (cond_bb, join_bb); e->flags = EDGE_FALSE_VALUE; e->count = cond_bb->count; e->probability = REG_BR_PROB_BASE; /* Update dominance info. Note that bb_join's data was updated by split_block. */ if (dom_info_available_p (CDI_DOMINATORS)) { set_immediate_dominator (CDI_DOMINATORS, then_bb, cond_bb); set_immediate_dominator (CDI_DOMINATORS, join_bb, cond_bb); } /* Build our local variables. */ mf_elem = create_tmp_var (mf_cache_structptr_type, "__mf_elem"); mf_base = create_tmp_var (mf_uintptr_type, "__mf_base"); mf_limit = create_tmp_var (mf_uintptr_type, "__mf_limit"); /* Build: __mf_base = (uintptr_t) <base address expression>. */ t = build2 (MODIFY_EXPR, void_type_node, mf_base, convert (mf_uintptr_type, unshare_expr (base))); SET_EXPR_LOCUS (t, locus); gimplify_to_stmt_list (&t); head = tsi_start (t); tsi = tsi_last (t); /* Build: __mf_limit = (uintptr_t) <limit address expression>. */ t = build2 (MODIFY_EXPR, void_type_node, mf_limit, convert (mf_uintptr_type, unshare_expr (limit))); SET_EXPR_LOCUS (t, locus); gimplify_to_stmt_list (&t); tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING); /* Build: __mf_elem = &__mf_lookup_cache [(__mf_base >> __mf_shift) & __mf_mask]. */ t = build2 (RSHIFT_EXPR, mf_uintptr_type, mf_base, (flag_mudflap_threads ? mf_cache_shift_decl : mf_cache_shift_decl_l)); t = build2 (BIT_AND_EXPR, mf_uintptr_type, t, (flag_mudflap_threads ? mf_cache_mask_decl : mf_cache_mask_decl_l)); t = build4 (ARRAY_REF, TREE_TYPE (TREE_TYPE (mf_cache_array_decl)), mf_cache_array_decl, t, NULL_TREE, NULL_TREE); t = build1 (ADDR_EXPR, mf_cache_structptr_type, t); t = build2 (MODIFY_EXPR, void_type_node, mf_elem, t); SET_EXPR_LOCUS (t, locus); gimplify_to_stmt_list (&t); tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING); /* Quick validity check. if (__mf_elem->low > __mf_base || (__mf_elem_high < __mf_limit)) { __mf_check (); ... and only if single-threaded: __mf_lookup_shift_1 = f...; __mf_lookup_mask_l = ...; } It is expected that this body of code is rarely executed so we mark the edge to the THEN clause of the conditional jump as unlikely. */ /* Construct t <-- '__mf_elem->low > __mf_base'. */ t = build3 (COMPONENT_REF, mf_uintptr_type, build1 (INDIRECT_REF, mf_cache_struct_type, mf_elem), TYPE_FIELDS (mf_cache_struct_type), NULL_TREE); t = build2 (GT_EXPR, boolean_type_node, t, mf_base); /* Construct '__mf_elem->high < __mf_limit'. First build: 1) u <-- '__mf_elem->high' 2) v <-- '__mf_limit'. Then build 'u <-- (u < v). */ u = build3 (COMPONENT_REF, mf_uintptr_type, build1 (INDIRECT_REF, mf_cache_struct_type, mf_elem), TREE_CHAIN (TYPE_FIELDS (mf_cache_struct_type)), NULL_TREE); v = mf_limit; u = build2 (LT_EXPR, boolean_type_node, u, v); /* Build the composed conditional: t <-- 't || u'. Then store the result of the evaluation of 't' in a temporary variable which we can use as the condition for the conditional jump. */ t = build2 (TRUTH_OR_EXPR, boolean_type_node, t, u); cond = create_tmp_var (boolean_type_node, "__mf_unlikely_cond"); t = build2 (MODIFY_EXPR, boolean_type_node, cond, t); gimplify_to_stmt_list (&t); tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING); /* Build the conditional jump. 'cond' is just a temporary so we can simply build a void COND_EXPR. We do need labels in both arms though. */ t = build3 (COND_EXPR, void_type_node, cond, build1 (GOTO_EXPR, void_type_node, tree_block_label (then_bb)), build1 (GOTO_EXPR, void_type_node, tree_block_label (join_bb))); SET_EXPR_LOCUS (t, locus); tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING); /* At this point, after so much hard work, we have only constructed the conditional jump, if (__mf_elem->low > __mf_base || (__mf_elem_high < __mf_limit)) The lowered GIMPLE tree representing this code is in the statement list starting at 'head'. We can insert this now in the current basic block, i.e. the one that the statement we're instrumenting was originally in. */ bsi = bsi_last (cond_bb); for (tsi = head; ! tsi_end_p (tsi); tsi_next (&tsi)) bsi_insert_after (&bsi, tsi_stmt (tsi), BSI_CONTINUE_LINKING); /* Now build up the body of the cache-miss handling: __mf_check(); refresh *_l vars. This is the body of the conditional. */ u = tree_cons (NULL_TREE, mf_file_function_line_tree (locus == NULL ? UNKNOWN_LOCATION : *locus), NULL_TREE); u = tree_cons (NULL_TREE, dirflag, u); /* NB: we pass the overall [base..limit] range to mf_check. */ u = tree_cons (NULL_TREE, fold_build2 (PLUS_EXPR, integer_type_node, fold_build2 (MINUS_EXPR, mf_uintptr_type, mf_limit, mf_base), integer_one_node), u); u = tree_cons (NULL_TREE, mf_base, u); t = build_function_call_expr (mf_check_fndecl, u); gimplify_to_stmt_list (&t); head = tsi_start (t); tsi = tsi_last (t); if (! flag_mudflap_threads) { t = build2 (MODIFY_EXPR, void_type_node, mf_cache_shift_decl_l, mf_cache_shift_decl); tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING); t = build2 (MODIFY_EXPR, void_type_node, mf_cache_mask_decl_l, mf_cache_mask_decl); tsi_link_after (&tsi, t, TSI_CONTINUE_LINKING); } /* Insert the check code in the THEN block. */ bsi = bsi_start (then_bb); for (tsi = head; ! tsi_end_p (tsi); tsi_next (&tsi)) bsi_insert_after (&bsi, tsi_stmt (tsi), BSI_CONTINUE_LINKING); *instr_bsi = bsi_start (join_bb); bsi_next (instr_bsi); }