From: Jason Merrill Date: Thu, 28 Apr 2016 19:01:13 +0000 (-0400) Subject: cvt.c (cp_get_callee): New. X-Git-Tag: basepoints/gcc-8~7324 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=babaa9df0279b16243acc58c9a5d7731f4882af4;p=thirdparty%2Fgcc.git cvt.c (cp_get_callee): New. * cvt.c (cp_get_callee): New. * constexpr.c (get_function_named_in_call): Use it. * cxx-pretty-print.c (postfix_expression): Use it. * except.c (check_noexcept_r): Use it. * method.c (check_nontriv): Use it. * tree.c (build_aggr_init_expr): Use it. * cp-tree.h: Declare it. From-SVN: r235596 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 1219f82db98c..ff6d30a00f73 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,13 @@ +2016-04-28 Jason Merrill + + * cvt.c (cp_get_callee): New. + * constexpr.c (get_function_named_in_call): Use it. + * cxx-pretty-print.c (postfix_expression): Use it. + * except.c (check_noexcept_r): Use it. + * method.c (check_nontriv): Use it. + * tree.c (build_aggr_init_expr): Use it. + * cp-tree.h: Declare it. + 2015-04-27 Ryan Burn Jeff Law diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index f0307a3df134..6054d1a9e3f7 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1044,21 +1044,7 @@ save_fundef_copy (tree fun, tree copy) static tree get_function_named_in_call (tree t) { - tree fun = NULL; - switch (TREE_CODE (t)) - { - case CALL_EXPR: - fun = CALL_EXPR_FN (t); - break; - - case AGGR_INIT_EXPR: - fun = AGGR_INIT_EXPR_FN (t); - break; - - default: - gcc_unreachable(); - break; - } + tree fun = cp_get_callee (t); if (fun && TREE_CODE (fun) == ADDR_EXPR && TREE_CODE (TREE_OPERAND (fun, 0)) == FUNCTION_DECL) fun = TREE_OPERAND (fun, 0); diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 4c548c9ba969..f6ea0b734c22 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -5694,6 +5694,7 @@ extern tree ocp_convert (tree, tree, int, int, extern tree cp_convert (tree, tree, tsubst_flags_t); extern tree cp_convert_and_check (tree, tree, tsubst_flags_t); extern tree cp_fold_convert (tree, tree); +extern tree cp_get_callee (tree); extern tree convert_to_void (tree, impl_conv_void, tsubst_flags_t); extern tree convert_force (tree, tree, int, diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 0d1048cd7fe4..8c9d78b641c6 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -904,6 +904,20 @@ ocp_convert (tree type, tree expr, int convtype, int flags, return error_mark_node; } +/* If CALL is a call, return the callee; otherwise null. */ + +tree +cp_get_callee (tree call) +{ + if (call == NULL_TREE) + return call; + else if (TREE_CODE (call) == CALL_EXPR) + return CALL_EXPR_FN (call); + else if (TREE_CODE (call) == AGGR_INIT_EXPR) + return AGGR_INIT_EXPR_FN (call); + return NULL_TREE; +} + /* When an expression is used in a void context, its value is discarded and no lvalue-rvalue and similar conversions happen [expr.static.cast/4, stmt.expr/1, expr.comma/1]. This permits dereferencing an incomplete type diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index cc28045eb64e..3b52a35a2e58 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -490,8 +490,7 @@ cxx_pretty_printer::postfix_expression (tree t) case AGGR_INIT_EXPR: case CALL_EXPR: { - tree fun = (code == AGGR_INIT_EXPR ? AGGR_INIT_EXPR_FN (t) - : CALL_EXPR_FN (t)); + tree fun = cp_get_callee (t); tree saved_scope = enclosing_scope; bool skipfirst = false; tree arg; diff --git a/gcc/cp/except.c b/gcc/cp/except.c index 53367100de9c..014df507f227 100644 --- a/gcc/cp/except.c +++ b/gcc/cp/except.c @@ -1158,8 +1158,7 @@ check_noexcept_r (tree *tp, int * /*walk_subtrees*/, void * /*data*/) translation unit, creating ODR problems. We could use TREE_NOTHROW (t) for !TREE_PUBLIC fns, though... */ - tree fn = (code == AGGR_INIT_EXPR - ? AGGR_INIT_EXPR_FN (t) : CALL_EXPR_FN (t)); + tree fn = cp_get_callee (t); tree type = TREE_TYPE (fn); gcc_assert (POINTER_TYPE_P (type)); type = TREE_TYPE (type); diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 862451f249bf..0e501d9045ab 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -1002,12 +1002,8 @@ get_inherited_ctor (tree ctor) static tree check_nontriv (tree *tp, int *, void *) { - tree fn; - if (TREE_CODE (*tp) == CALL_EXPR) - fn = CALL_EXPR_FN (*tp); - else if (TREE_CODE (*tp) == AGGR_INIT_EXPR) - fn = AGGR_INIT_EXPR_FN (*tp); - else + tree fn = cp_get_callee (*tp); + if (fn == NULL_TREE) return NULL_TREE; if (TREE_CODE (fn) == ADDR_EXPR) diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 5b5d5ba48f95..97601aa1f186 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -470,11 +470,8 @@ build_aggr_init_expr (tree type, tree init) if (processing_template_decl) return init; - if (TREE_CODE (init) == CALL_EXPR) - fn = CALL_EXPR_FN (init); - else if (TREE_CODE (init) == AGGR_INIT_EXPR) - fn = AGGR_INIT_EXPR_FN (init); - else + fn = cp_get_callee (init); + if (fn == NULL_TREE) return convert (type, init); is_ctor = (TREE_CODE (fn) == ADDR_EXPR