diff options
author | Jakub Jelinek <jakub@redhat.com> | 2016-07-20 16:00:02 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2016-07-20 16:00:02 +0200 |
commit | 109d2197c31b766daf9c7b138bc7eeaab12985df (patch) | |
tree | b4130392d26901052d9c0f2e7c70f90f8177f8c5 /gcc/cp | |
parent | 2d06ca74a23cc87d2edc983f24a196a815af1c01 (diff) | |
download | gcc-109d2197c31b766daf9c7b138bc7eeaab12985df.zip gcc-109d2197c31b766daf9c7b138bc7eeaab12985df.tar.gz gcc-109d2197c31b766daf9c7b138bc7eeaab12985df.tar.bz2 |
re PR middle-end/50060 (intrinsics not folded by the middle-end)
PR c++/50060
* constexpr.c (cxx_eval_builtin_function_call): Pass false as lval
when evaluating call arguments. Use fold_builtin_call_array instead
of fold_build_call_array_loc, return t if it returns NULL. Otherwise
check the result with potential_constant_expression and call
cxx_eval_constant_expression on it.
* g++.dg/cpp0x/constexpr-50060.C: New test.
* g++.dg/cpp1y/constexpr-50060.C: New test.
From-SVN: r238520
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/cp/constexpr.c | 32 |
2 files changed, 34 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 417cb82..7b90320 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2016-07-20 Jakub Jelinek <jakub@redhat.com> + + PR c++/50060 + * constexpr.c (cxx_eval_builtin_function_call): Pass false as lval + when evaluating call arguments. Use fold_builtin_call_array instead + of fold_build_call_array_loc, return t if it returns NULL. Otherwise + check the result with potential_constant_expression and call + cxx_eval_constant_expression on it. + 2016-07-19 Jason Merrill <jason@redhat.com> PR c++/67164 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index 91d14a5..346fdfa 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -1105,7 +1105,7 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, for (i = 0; i < nargs; ++i) { args[i] = cxx_eval_constant_expression (&new_ctx, CALL_EXPR_ARG (t, i), - lval, &dummy1, &dummy2); + false, &dummy1, &dummy2); if (bi_const_p) /* For __built_in_constant_p, fold all expressions with constant values even if they aren't C++ constant-expressions. */ @@ -1114,13 +1114,31 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun, bool save_ffbcp = force_folding_builtin_constant_p; force_folding_builtin_constant_p = true; - new_call = fold_build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t), - CALL_EXPR_FN (t), nargs, args); - /* Fold away the NOP_EXPR from fold_builtin_n. */ - new_call = fold (new_call); + new_call = fold_builtin_call_array (EXPR_LOCATION (t), TREE_TYPE (t), + CALL_EXPR_FN (t), nargs, args); force_folding_builtin_constant_p = save_ffbcp; - VERIFY_CONSTANT (new_call); - return new_call; + if (new_call == NULL) + { + if (!*non_constant_p && !ctx->quiet) + { + new_call = build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t), + CALL_EXPR_FN (t), nargs, args); + error ("%q+E is not a constant expression", new_call); + } + *non_constant_p = true; + return t; + } + + if (!potential_constant_expression (new_call)) + { + if (!*non_constant_p && !ctx->quiet) + error ("%q+E is not a constant expression", new_call); + *non_constant_p = true; + return t; + } + + return cxx_eval_constant_expression (&new_ctx, new_call, lval, + non_constant_p, overflow_p); } /* TEMP is the constant value of a temporary object of type TYPE. Adjust |