This corresponds to: [PATCH 25/89] Introduce gimple_catch https://gcc.gnu.org/ml/gcc-patches/2014-04/msg01178.html from the original 89-patch kit
That earlier patch was approved by Jeff: > OK after fixing up the naming/const stuff as discussed for prior > patches. > That applies to 22-30. Make sure to take care of > the pretty printers per Trevor's comments as well. He indicated those > were missing in a couple of those patches. in https://gcc.gnu.org/ml/gcc-patches/2014-05/msg00628.html gcc/ * coretypes.h (gimple_catch): New typedef. (const_gimple_catch): New typedef. * gimple-low.c (lower_try_catch): Add checked cast to gimple_catch. (gimple_try_catch_may_fallthru): Likewise. * gimple-pretty-print.c (dump_gimple_catch): Require a gimple_catch rather than a plain gimple. (pp_gimple_stmt_1): Add checked cast to gimple_catch within GIMPLE_CATCH case of switch statement. * gimple-walk.c (walk_gimple_op): Likewise. (walk_gimple_stmt): Likewise. * gimple.c (gimple_build_catch): Return a gimple_catch rather than a plain gimple. (gimple_copy): Add checked casts to gimple_catch within GIMPLE_CATCH case of switch statement, introducing new locals. * gimple.h (gimple_build_catch): Return a gimple_catch rather than a plain gimple. (gimple_catch_types_ptr): Require a gimple_catch rather than a plain gimple. (gimple_catch_handler_ptr): Likewise. (gimple_catch_handler): Likewise. (gimple_catch_set_types): Likewise. (gimple_catch_set_handler): Likewise. * omp-low.c (lower_omp_1): Add checked cast to gimple_catch within GIMPLE_CATCH case of switch statement. * tree-cfg.c (verify_gimple_in_seq_2): Likewise. (do_warn_unused_result): Likewise. * tree-eh.c (collect_finally_tree): Likewise. (replace_goto_queue_1): Likewise. (lower_catch): Convert local from gimple to gimple_catch. (refactor_eh_r): Add checked cast to gimple_catch within GIMPLE_CATCH case of switch statement. * tree-inline.c (remap_gimple_stmt): Likewise. (estimate_num_insns): Add checked cast to gimple_catch within GIMPLE_CATCH case of switch statement, introducing new local. --- gcc/ChangeLog.gimple-classes | 48 ++++++++++++++++++++++++++++++++++++++++++++ gcc/coretypes.h | 4 ++++ gcc/gimple-low.c | 7 +++++-- gcc/gimple-pretty-print.c | 4 ++-- gcc/gimple-walk.c | 9 +++++---- gcc/gimple.c | 16 +++++++++------ gcc/gimple.h | 28 +++++++++++--------------- gcc/omp-low.c | 2 +- gcc/tree-cfg.c | 6 ++++-- gcc/tree-eh.c | 14 ++++++++----- gcc/tree-inline.c | 11 +++++++--- 11 files changed, 108 insertions(+), 41 deletions(-) diff --git a/gcc/ChangeLog.gimple-classes b/gcc/ChangeLog.gimple-classes index b3a475e..04b611e 100644 --- a/gcc/ChangeLog.gimple-classes +++ b/gcc/ChangeLog.gimple-classes @@ -1,5 +1,53 @@ 2014-10-24 David Malcolm <dmalc...@redhat.com> + Introduce gimple_catch + + * coretypes.h (gimple_catch): New typedef. + (const_gimple_catch): New typedef. + + * gimple-low.c (lower_try_catch): Add checked cast to gimple_catch. + (gimple_try_catch_may_fallthru): Likewise. + + * gimple-pretty-print.c (dump_gimple_catch): Require a gimple_catch + rather than a plain gimple. + (pp_gimple_stmt_1): Add checked cast to gimple_catch within + GIMPLE_CATCH case of switch statement. + + * gimple-walk.c (walk_gimple_op): Likewise. + (walk_gimple_stmt): Likewise. + + * gimple.c (gimple_build_catch): Return a gimple_catch rather than + a plain gimple. + (gimple_copy): Add checked casts to gimple_catch within + GIMPLE_CATCH case of switch statement, introducing new locals. + + * gimple.h (gimple_build_catch): Return a gimple_catch rather than + a plain gimple. + (gimple_catch_types_ptr): Require a gimple_catch rather than a + plain gimple. + (gimple_catch_handler_ptr): Likewise. + (gimple_catch_handler): Likewise. + (gimple_catch_set_types): Likewise. + (gimple_catch_set_handler): Likewise. + + * omp-low.c (lower_omp_1): Add checked cast to gimple_catch within + GIMPLE_CATCH case of switch statement. + + * tree-cfg.c (verify_gimple_in_seq_2): Likewise. + (do_warn_unused_result): Likewise. + + * tree-eh.c (collect_finally_tree): Likewise. + (replace_goto_queue_1): Likewise. + (lower_catch): Convert local from gimple to gimple_catch. + (refactor_eh_r): Add checked cast to gimple_catch within + GIMPLE_CATCH case of switch statement. + + * tree-inline.c (remap_gimple_stmt): Likewise. + (estimate_num_insns): Add checked cast to gimple_catch within + GIMPLE_CATCH case of switch statement, introducing new local. + +2014-10-24 David Malcolm <dmalc...@redhat.com> + Introduce gimple_transaction * coretypes.h (gimple_transaction): New typedef. diff --git a/gcc/coretypes.h b/gcc/coretypes.h index a38d7bd..bff57cc 100644 --- a/gcc/coretypes.h +++ b/gcc/coretypes.h @@ -134,6 +134,10 @@ struct gimple_statement_bind; typedef struct gimple_statement_bind *gimple_bind; typedef const struct gimple_statement_bind *const_gimple_bind; +struct gimple_statement_catch; +typedef struct gimple_statement_catch *gimple_catch; +typedef const struct gimple_statement_catch *const_gimple_catch; + struct gimple_statement_phi; typedef struct gimple_statement_phi *gimple_phi; typedef const struct gimple_statement_phi *const_gimple_phi; diff --git a/gcc/gimple-low.c b/gcc/gimple-low.c index 4a4ad8a..9ac984e 100644 --- a/gcc/gimple-low.c +++ b/gcc/gimple-low.c @@ -453,7 +453,9 @@ lower_try_catch (gimple_stmt_iterator *gsi, struct lower_data *data) for (; !gsi_end_p (i); gsi_next (&i)) { data->cannot_fallthru = false; - lower_sequence (gimple_catch_handler_ptr (gsi_stmt (i)), data); + lower_sequence (gimple_catch_handler_ptr ( + as_a <gimple_catch> (gsi_stmt (i))), + data); if (!data->cannot_fallthru) cannot_fallthru = false; } @@ -515,7 +517,8 @@ gimple_try_catch_may_fallthru (gimple stmt) through iff any of the catch bodies falls through. */ for (; !gsi_end_p (i); gsi_next (&i)) { - if (gimple_seq_may_fallthru (gimple_catch_handler (gsi_stmt (i)))) + if (gimple_seq_may_fallthru (gimple_catch_handler ( + as_a <gimple_catch> (gsi_stmt (i))))) return true; } return false; diff --git a/gcc/gimple-pretty-print.c b/gcc/gimple-pretty-print.c index a188759..f7287f6 100644 --- a/gcc/gimple-pretty-print.c +++ b/gcc/gimple-pretty-print.c @@ -988,7 +988,7 @@ dump_gimple_try (pretty_printer *buffer, gimple gs, int spc, int flags) dumpfile.h). */ static void -dump_gimple_catch (pretty_printer *buffer, gimple gs, int spc, int flags) +dump_gimple_catch (pretty_printer *buffer, gimple_catch gs, int spc, int flags) { if (flags & TDF_RAW) dump_gimple_fmt (buffer, spc, flags, "%G <%T, %+CATCH <%S>%->", gs, @@ -2194,7 +2194,7 @@ pp_gimple_stmt_1 (pretty_printer *buffer, gimple gs, int spc, int flags) break; case GIMPLE_CATCH: - dump_gimple_catch (buffer, gs, spc, flags); + dump_gimple_catch (buffer, as_a <gimple_catch> (gs), spc, flags); break; case GIMPLE_EH_FILTER: diff --git a/gcc/gimple-walk.c b/gcc/gimple-walk.c index e41a9a5..fc74f49 100644 --- a/gcc/gimple-walk.c +++ b/gcc/gimple-walk.c @@ -278,8 +278,8 @@ walk_gimple_op (gimple stmt, walk_tree_fn callback_op, break; case GIMPLE_CATCH: - ret = walk_tree (gimple_catch_types_ptr (stmt), callback_op, wi, - pset); + ret = walk_tree (gimple_catch_types_ptr (as_a <gimple_catch> (stmt)), + callback_op, wi, pset); if (ret) return ret; break; @@ -551,8 +551,9 @@ walk_gimple_stmt (gimple_stmt_iterator *gsi, walk_stmt_fn callback_stmt, break; case GIMPLE_CATCH: - ret = walk_gimple_seq_mod (gimple_catch_handler_ptr (stmt), callback_stmt, - callback_op, wi); + ret = walk_gimple_seq_mod (gimple_catch_handler_ptr ( + as_a <gimple_catch> (stmt)), + callback_stmt, callback_op, wi); if (ret) return wi->callback_result; break; diff --git a/gcc/gimple.c b/gcc/gimple.c index 68ede1f..61a9c83 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -614,10 +614,10 @@ gimple_build_asm_vec (const char *string, vec<tree, va_gc> *inputs, TYPES are the catch types. HANDLER is the exception handler. */ -gimple +gimple_catch gimple_build_catch (tree types, gimple_seq handler) { - gimple p = gimple_alloc (GIMPLE_CATCH, 0); + gimple_catch p = as_a <gimple_catch> (gimple_alloc (GIMPLE_CATCH, 0)); gimple_catch_set_types (p, types); if (handler) gimple_catch_set_handler (p, handler); @@ -1664,10 +1664,14 @@ gimple_copy (gimple stmt) break; case GIMPLE_CATCH: - new_seq = gimple_seq_copy (gimple_catch_handler (stmt)); - gimple_catch_set_handler (copy, new_seq); - t = unshare_expr (gimple_catch_types (stmt)); - gimple_catch_set_types (copy, t); + { + gimple_catch catch_stmt = as_a <gimple_catch> (stmt); + gimple_catch catch_copy = as_a <gimple_catch> (copy); + new_seq = gimple_seq_copy (gimple_catch_handler (catch_stmt)); + gimple_catch_set_handler (catch_copy, new_seq); + t = unshare_expr (gimple_catch_types (catch_stmt)); + gimple_catch_set_types (catch_copy, t); + } break; case GIMPLE_EH_FILTER: diff --git a/gcc/gimple.h b/gcc/gimple.h index 4ddcb24..23e6861 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1325,7 +1325,7 @@ gimple_bind gimple_build_bind (tree, gimple_seq, tree); gimple_asm gimple_build_asm_vec (const char *, vec<tree, va_gc> *, vec<tree, va_gc> *, vec<tree, va_gc> *, vec<tree, va_gc> *); -gimple gimple_build_catch (tree, gimple_seq); +gimple_catch gimple_build_catch (tree, gimple_seq); gimple gimple_build_eh_filter (tree, gimple_seq); gimple gimple_build_eh_must_not_throw (tree); gimple gimple_build_eh_else (gimple_seq, gimple_seq); @@ -3535,53 +3535,49 @@ gimple_catch_types (const_gimple gs) } -/* Return a pointer to the types handled by GIMPLE_CATCH statement GS. */ +/* Return a pointer to the types handled by GIMPLE_CATCH statement CATCH_STMT. */ static inline tree * -gimple_catch_types_ptr (gimple gs) +gimple_catch_types_ptr (gimple_catch catch_stmt) { - gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch *> (gs); return &catch_stmt->types; } /* Return a pointer to the GIMPLE sequence representing the body of - the handler of GIMPLE_CATCH statement GS. */ + the handler of GIMPLE_CATCH statement CATCH_STMT. */ static inline gimple_seq * -gimple_catch_handler_ptr (gimple gs) +gimple_catch_handler_ptr (gimple_catch catch_stmt) { - gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch *> (gs); return &catch_stmt->handler; } /* Return the GIMPLE sequence representing the body of the handler of - GIMPLE_CATCH statement GS. */ + GIMPLE_CATCH statement CATCH_STMT. */ static inline gimple_seq -gimple_catch_handler (gimple gs) +gimple_catch_handler (gimple_catch catch_stmt) { - return *gimple_catch_handler_ptr (gs); + return *gimple_catch_handler_ptr (catch_stmt); } -/* Set T to be the set of types handled by GIMPLE_CATCH GS. */ +/* Set T to be the set of types handled by GIMPLE_CATCH CATCH_STMT. */ static inline void -gimple_catch_set_types (gimple gs, tree t) +gimple_catch_set_types (gimple_catch catch_stmt, tree t) { - gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch *> (gs); catch_stmt->types = t; } -/* Set HANDLER to be the body of GIMPLE_CATCH GS. */ +/* Set HANDLER to be the body of GIMPLE_CATCH CATCH_STMT. */ static inline void -gimple_catch_set_handler (gimple gs, gimple_seq handler) +gimple_catch_set_handler (gimple_catch catch_stmt, gimple_seq handler) { - gimple_statement_catch *catch_stmt = as_a <gimple_statement_catch *> (gs); catch_stmt->handler = handler; } diff --git a/gcc/omp-low.c b/gcc/omp-low.c index b8a131b..2c4e992 100644 --- a/gcc/omp-low.c +++ b/gcc/omp-low.c @@ -10458,7 +10458,7 @@ lower_omp_1 (gimple_stmt_iterator *gsi_p, omp_context *ctx) gimple_regimplify_operands (stmt, gsi_p); break; case GIMPLE_CATCH: - lower_omp (gimple_catch_handler_ptr (stmt), ctx); + lower_omp (gimple_catch_handler_ptr (as_a <gimple_catch> (stmt)), ctx); break; case GIMPLE_EH_FILTER: lower_omp (gimple_eh_filter_failure_ptr (stmt), ctx); diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c index 1662d49..d459228 100644 --- a/gcc/tree-cfg.c +++ b/gcc/tree-cfg.c @@ -4644,7 +4644,8 @@ verify_gimple_in_seq_2 (gimple_seq stmts) break; case GIMPLE_CATCH: - err |= verify_gimple_in_seq_2 (gimple_catch_handler (stmt)); + err |= verify_gimple_in_seq_2 (gimple_catch_handler ( + as_a <gimple_catch> (stmt))); break; case GIMPLE_TRANSACTION: @@ -8364,7 +8365,8 @@ do_warn_unused_result (gimple_seq seq) do_warn_unused_result (gimple_try_cleanup (g)); break; case GIMPLE_CATCH: - do_warn_unused_result (gimple_catch_handler (g)); + do_warn_unused_result (gimple_catch_handler ( + as_a <gimple_catch> (g))); break; case GIMPLE_EH_FILTER: do_warn_unused_result (gimple_eh_filter_failure (g)); diff --git a/gcc/tree-eh.c b/gcc/tree-eh.c index 9769225..15dcf51 100644 --- a/gcc/tree-eh.c +++ b/gcc/tree-eh.c @@ -263,7 +263,9 @@ collect_finally_tree (gimple stmt, gimple region) break; case GIMPLE_CATCH: - collect_finally_tree_1 (gimple_catch_handler (stmt), region); + collect_finally_tree_1 (gimple_catch_handler ( + as_a <gimple_catch> (stmt)), + region); break; case GIMPLE_EH_FILTER: @@ -519,7 +521,9 @@ replace_goto_queue_1 (gimple stmt, struct leh_tf_state *tf, replace_goto_queue_stmt_list (gimple_try_cleanup_ptr (stmt), tf); break; case GIMPLE_CATCH: - replace_goto_queue_stmt_list (gimple_catch_handler_ptr (stmt), tf); + replace_goto_queue_stmt_list (gimple_catch_handler_ptr ( + as_a <gimple_catch> (stmt)), + tf); break; case GIMPLE_EH_FILTER: replace_goto_queue_stmt_list (gimple_eh_filter_failure_ptr (stmt), tf); @@ -1764,10 +1768,10 @@ lower_catch (struct leh_state *state, gimple tp) gsi_next (&gsi)) { eh_catch c; - gimple gcatch; + gimple_catch gcatch; gimple_seq handler; - gcatch = gsi_stmt (gsi); + gcatch = as_a <gimple_catch> (gsi_stmt (gsi)); c = gen_eh_region_catch (try_region, gimple_catch_types (gcatch)); handler = gimple_catch_handler (gcatch); @@ -3061,7 +3065,7 @@ refactor_eh_r (gimple_seq seq) refactor_eh_r (gimple_try_cleanup (one)); break; case GIMPLE_CATCH: - refactor_eh_r (gimple_catch_handler (one)); + refactor_eh_r (gimple_catch_handler (as_a <gimple_catch> (one))); break; case GIMPLE_EH_FILTER: refactor_eh_r (gimple_eh_filter_failure (one)); diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c index 44a2ba0..b6f2a5c 100644 --- a/gcc/tree-inline.c +++ b/gcc/tree-inline.c @@ -1338,8 +1338,11 @@ remap_gimple_stmt (gimple stmt, copy_body_data *id) break; case GIMPLE_CATCH: - s1 = remap_gimple_seq (gimple_catch_handler (stmt), id); - copy = gimple_build_catch (gimple_catch_types (stmt), s1); + { + gimple_catch catch_stmt = as_a <gimple_catch> (stmt); + s1 = remap_gimple_seq (gimple_catch_handler (catch_stmt), id); + copy = gimple_build_catch (gimple_catch_types (catch_stmt), s1); + } break; case GIMPLE_EH_FILTER: @@ -3983,7 +3986,9 @@ estimate_num_insns (gimple stmt, eni_weights *weights) return estimate_num_insns_seq (gimple_eh_filter_failure (stmt), weights); case GIMPLE_CATCH: - return estimate_num_insns_seq (gimple_catch_handler (stmt), weights); + return estimate_num_insns_seq (gimple_catch_handler ( + as_a <gimple_catch> (stmt)), + weights); case GIMPLE_TRY: return (estimate_num_insns_seq (gimple_try_eval (stmt), weights) -- 1.8.5.3