aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/cp-gimplify.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-08-08 11:00:51 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2018-08-08 11:00:51 +0200
commite408261123697a82b5965c700fa2465999f0fd62 (patch)
tree22ed906d9f15d60555219787db1ca461460a6741 /gcc/cp/cp-gimplify.c
parent5e539332c47faa6d6df728d27fae5d02805ca5ec (diff)
downloadgcc-e408261123697a82b5965c700fa2465999f0fd62.zip
gcc-e408261123697a82b5965c700fa2465999f0fd62.tar.gz
gcc-e408261123697a82b5965c700fa2465999f0fd62.tar.bz2
P0595R1 - is_constant_evaluated
P0595R1 - is_constant_evaluated cp/ * cp-tree.h (enum cp_built_in_function): New. (maybe_constant_init): Add pretend_const_required argument. * typeck2.c (store_init_value): Pass true as new argument to maybe_constant_init. * constexpr.c (constexpr_fn_retval): Check also DECL_BUILT_IN_CLASS for BUILT_IN_UNREACHABLE. (struct constexpr_ctx): Add pretend_const_required field. (cxx_eval_builtin_function_call): Use DECL_IS_BUILTIN_CONSTANT_P macro. Handle CP_BUILT_IN_IS_CONSTANT_EVALUATED. Check also DECL_BUILT_IN_CLASS for BUILT_IN_UNREACHABLE. (cxx_eval_outermost_constant_expr): Add pretend_const_required argument, initialize pretend_const_required field in ctx. If the result is TREE_CONSTANT and non_constant_p, retry with pretend_const_required false if it was true. (is_sub_constant_expr): Initialize pretend_const_required_field in ctx. (cxx_constant_value): Pass true as pretend_const_required to cxx_eval_outermost_constant_expr. (maybe_constant_value): Pass false as pretend_const_required to cxx_eval_outermost_constant_expr. (fold_non_dependent_expr): Likewise. (maybe_constant_init_1): Add pretend_const_required argument, pass it down to cxx_eval_outermost_constant_expr. Pass !allow_non_constant instead of false as strict to cxx_eval_outermost_constant_expr. (maybe_constant_init): Add pretend_const_required argument, pass it down to maybe_constant_init_1. (cxx_constant_init): Pass true as pretend_const_required to maybe_constant_init_1. * cp-gimplify.c (cp_gimplify_expr): Handle CALL_EXPRs to CP_BUILT_IN_IS_CONSTANT_EVALUATED. (cp_fold): Don't fold CP_BUILT_IN_IS_CONSTANT_EVALUATED calls. * decl.c: Include langhooks.h. (cxx_init_decl_processing): Register __builtin_is_constant_evaluated built-in. * tree.c (builtin_valid_in_constant_expr_p): Return true for CP_BUILT_IN_IS_CONSTANT_EVALUATED. * pt.c (declare_integer_pack): Initialize DECL_FUNCTION_CODE. testsuite/ * g++.dg/cpp2a/is-constant-evaluated1.C: New test. From-SVN: r263392
Diffstat (limited to 'gcc/cp/cp-gimplify.c')
-rw-r--r--gcc/cp/cp-gimplify.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 28802b5..7db4acc 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -793,6 +793,15 @@ cp_gimplify_expr (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p)
ret = GS_ERROR;
}
}
+ if (ret != GS_ERROR)
+ {
+ tree decl = cp_get_callee_fndecl_nofold (*expr_p);
+ if (decl
+ && DECL_BUILT_IN_CLASS (decl) == BUILT_IN_FRONTEND
+ && ((int) DECL_FUNCTION_CODE (decl)
+ == CP_BUILT_IN_IS_CONSTANT_EVALUATED))
+ *expr_p = boolean_false_node;
+ }
break;
case RETURN_EXPR:
@@ -2483,6 +2492,13 @@ cp_fold (tree x)
&& DECL_DECLARED_CONSTEXPR_P (current_function_decl))
nw = 1;
+ /* Defer folding __builtin_is_constant_evaluated. */
+ if (callee
+ && DECL_BUILT_IN_CLASS (callee) == BUILT_IN_FRONTEND
+ && ((int) DECL_FUNCTION_CODE (callee)
+ == CP_BUILT_IN_IS_CONSTANT_EVALUATED))
+ break;
+
x = copy_node (x);
m = call_expr_nargs (x);