From bf31620cebc7955ff2f4f975292dcbe9c6f026a5 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Fri, 9 Jun 2017 18:46:51 -0400 Subject: [PATCH] Don't fold conversion from a constant variable. * call.c (convert_like_real): Remove "inner" parameter. Don't replace a constant with its value. * cp-gimplify.c (cp_fully_fold): Use cp_fold_rvalue. From-SVN: r249083 --- gcc/cp/ChangeLog | 4 ++++ gcc/cp/call.c | 31 +++++++++---------------------- gcc/cp/cp-gimplify.c | 28 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 36 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8695d37850c..8949f6b56f6 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,9 @@ 2017-06-09 Jason Merrill + * call.c (convert_like_real): Remove "inner" parameter. + Don't replace a constant with its value. + * cp-gimplify.c (cp_fully_fold): Use cp_fold_rvalue. + * pt.c (convert_nontype_argument): Check NULLPTR_TYPE_P rather than nullptr_node. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 51260f07dfd..5e65bfbff4b 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -147,14 +147,14 @@ static int joust (struct z_candidate *, struct z_candidate *, bool, static int compare_ics (conversion *, conversion *); static tree build_over_call (struct z_candidate *, int, tsubst_flags_t); #define convert_like(CONV, EXPR, COMPLAIN) \ - convert_like_real ((CONV), (EXPR), NULL_TREE, 0, 0, \ + convert_like_real ((CONV), (EXPR), NULL_TREE, 0, \ /*issue_conversion_warnings=*/true, \ /*c_cast_p=*/false, (COMPLAIN)) #define convert_like_with_context(CONV, EXPR, FN, ARGNO, COMPLAIN ) \ - convert_like_real ((CONV), (EXPR), (FN), (ARGNO), 0, \ + convert_like_real ((CONV), (EXPR), (FN), (ARGNO), \ /*issue_conversion_warnings=*/true, \ /*c_cast_p=*/false, (COMPLAIN)) -static tree convert_like_real (conversion *, tree, tree, int, int, bool, +static tree convert_like_real (conversion *, tree, tree, int, bool, bool, tsubst_flags_t); static void op_error (location_t, enum tree_code, enum tree_code, tree, tree, tree, bool); @@ -6552,7 +6552,7 @@ maybe_print_user_conv_context (conversion *convs) static tree convert_like_real (conversion *convs, tree expr, tree fn, int argnum, - int inner, bool issue_conversion_warnings, + bool issue_conversion_warnings, bool c_cast_p, tsubst_flags_t complain) { tree totype = convs->type; @@ -6606,7 +6606,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, totype); if (complained) print_z_candidate (loc, "candidate is:", t->cand); - expr = convert_like_real (t, expr, fn, argnum, 1, + expr = convert_like_real (t, expr, fn, argnum, /*issue_conversion_warnings=*/false, /*c_cast_p=*/false, complain); @@ -6623,14 +6623,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, } else if (t->kind == ck_user || !t->bad_p) { - expr = convert_like_real (t, expr, fn, argnum, 1, + expr = convert_like_real (t, expr, fn, argnum, /*issue_conversion_warnings=*/false, /*c_cast_p=*/false, complain); break; } else if (t->kind == ck_ambig) - return convert_like_real (t, expr, fn, argnum, 1, + return convert_like_real (t, expr, fn, argnum, /*issue_conversion_warnings=*/false, /*c_cast_p=*/false, complain); @@ -6734,18 +6734,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, if (type_unknown_p (expr)) expr = instantiate_type (totype, expr, complain); - /* Convert a constant to its underlying value, unless we are - about to bind it to a reference, in which case we need to - leave it as an lvalue. */ - if (inner >= 0) - { - expr = scalar_constant_value (expr); - if (expr == null_node && INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (totype)) - /* If __null has been converted to an integer type, we do not - want to warn about uses of EXPR as an integer, rather than - as a pointer. */ - expr = build_int_cst (totype, 0); - } return expr; case ck_ambig: /* We leave bad_p off ck_ambig because overload resolution considers @@ -6776,7 +6764,7 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), ix, val) { tree sub = convert_like_real (convs->u.list[ix], val, fn, argnum, - 1, false, false, complain); + false, false, complain); if (sub == error_mark_node) return sub; if (!BRACE_ENCLOSED_INITIALIZER_P (val) @@ -6832,7 +6820,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, }; expr = convert_like_real (next_conversion (convs), expr, fn, argnum, - convs->kind == ck_ref_bind ? -1 : 1, convs->kind == ck_ref_bind ? issue_conversion_warnings : false, c_cast_p, complain); @@ -10173,7 +10160,7 @@ perform_direct_initialization_if_possible (tree type, if (!conv || conv->bad_p) expr = NULL_TREE; else - expr = convert_like_real (conv, expr, NULL_TREE, 0, 0, + expr = convert_like_real (conv, expr, NULL_TREE, 0, /*issue_conversion_warnings=*/false, c_cast_p, complain); diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 106d7224214..e3802f1820b 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -1935,20 +1935,6 @@ cxx_omp_disregard_value_expr (tree decl, bool shared) && DECL_OMP_PRIVATIZED_MEMBER (decl); } -/* Perform folding on expression X. */ - -tree -cp_fully_fold (tree x) -{ - if (processing_template_decl) - return x; - /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't - have to call both. */ - if (cxx_dialect >= cxx11) - x = maybe_constant_value (x); - return cp_fold (x); -} - /* Fold expression X which is used as an rvalue if RVAL is true. */ static tree @@ -1980,6 +1966,20 @@ cp_fold_rvalue (tree x) return cp_fold_maybe_rvalue (x, true); } +/* Perform folding on expression X. */ + +tree +cp_fully_fold (tree x) +{ + if (processing_template_decl) + return x; + /* FIXME cp_fold ought to be a superset of maybe_constant_value so we don't + have to call both. */ + if (cxx_dialect >= cxx11) + x = maybe_constant_value (x); + return cp_fold_rvalue (x); +} + /* c-common interface to cp_fold. If IN_INIT, this is in a static initializer and certain changes are made to the folding done. Or should be (FIXME). We never touch maybe_const, as it is only used for the C front-end