Commit 5756d0f9 by Jason Merrill Committed by Jason Merrill

re PR c++/65656 (__builtin_constant_p should always be constexpr)

	PR c++/65656
	* constexpr.c (cxx_eval_builtin_function_call): Fix
	__builtin_constant_p.

From-SVN: r222531
parent b71983a5
2015-04-28 Jason Merrill <jason@redhat.com> 2015-04-28 Jason Merrill <jason@redhat.com>
PR c++/65656
* constexpr.c (cxx_eval_builtin_function_call): Fix
__builtin_constant_p.
PR c++/50800 PR c++/50800
* tree.c (strip_typedefs): Add remove_attributes parm. * tree.c (strip_typedefs): Add remove_attributes parm.
(strip_typedefs_expr): Likewise. (strip_typedefs_expr): Likewise.
......
...@@ -1014,7 +1014,7 @@ get_nth_callarg (tree t, int n) ...@@ -1014,7 +1014,7 @@ get_nth_callarg (tree t, int n)
represented by _CST nodes. */ represented by _CST nodes. */
static tree static tree
cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, tree fun,
bool lval, bool lval,
bool *non_constant_p, bool *overflow_p) bool *non_constant_p, bool *overflow_p)
{ {
...@@ -1022,18 +1022,30 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t, ...@@ -1022,18 +1022,30 @@ cxx_eval_builtin_function_call (const constexpr_ctx *ctx, tree t,
tree *args = (tree *) alloca (nargs * sizeof (tree)); tree *args = (tree *) alloca (nargs * sizeof (tree));
tree new_call; tree new_call;
int i; int i;
for (i = 0; i < nargs; ++i)
/* Don't fold __builtin_constant_p within a constexpr function. */
if (DECL_FUNCTION_CODE (fun) == BUILT_IN_CONSTANT_P
&& current_function_decl
&& DECL_DECLARED_CONSTEXPR_P (current_function_decl))
{ {
args[i] = cxx_eval_constant_expression (ctx, CALL_EXPR_ARG (t, i), *non_constant_p = true;
lval, return t;
non_constant_p, overflow_p);
if (ctx->quiet && *non_constant_p)
return t;
} }
if (*non_constant_p)
return t; /* Be permissive for arguments to built-ins; __builtin_constant_p should
return constant false for a non-constant argument. */
constexpr_ctx new_ctx = *ctx;
new_ctx.quiet = true;
bool dummy1 = false, dummy2 = false;
for (i = 0; i < nargs; ++i)
args[i] = cxx_eval_constant_expression (&new_ctx, CALL_EXPR_ARG (t, i),
lval, &dummy1, &dummy2);
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), new_call = fold_build_call_array_loc (EXPR_LOCATION (t), TREE_TYPE (t),
CALL_EXPR_FN (t), nargs, args); CALL_EXPR_FN (t), nargs, args);
force_folding_builtin_constant_p = save_ffbcp;
VERIFY_CONSTANT (new_call); VERIFY_CONSTANT (new_call);
return new_call; return new_call;
} }
...@@ -1200,7 +1212,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t, ...@@ -1200,7 +1212,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
return void_node; return void_node;
if (is_builtin_fn (fun)) if (is_builtin_fn (fun))
return cxx_eval_builtin_function_call (ctx, t, return cxx_eval_builtin_function_call (ctx, t, fun,
lval, non_constant_p, overflow_p); lval, non_constant_p, overflow_p);
if (!DECL_DECLARED_CONSTEXPR_P (fun)) if (!DECL_DECLARED_CONSTEXPR_P (fun))
{ {
......
// PR c++/65656
// { dg-options "-std=c++11 -O" }
int main(int argc, char *argv[]) {
constexpr bool x = __builtin_constant_p(argc);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment