aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-constexpr.cc
diff options
context:
space:
mode:
authorFaisal Abbas <90.abbasfaisal@gmail.com>2022-06-25 11:56:42 +0100
committerFaisal Abbas <90.abbasfaisal@gmail.com>2022-06-25 11:56:42 +0100
commit2a7a0589f62ab9157d9f862ec2fd7d680c53c5f3 (patch)
treecd2d4525815c4b8472517e59cb840c152d4b366a /gcc/rust/backend/rust-constexpr.cc
parent5bab921fc018bfaae00d2739e5c4e5912673823a (diff)
downloadgcc-2a7a0589f62ab9157d9f862ec2fd7d680c53c5f3.zip
gcc-2a7a0589f62ab9157d9f862ec2fd7d680c53c5f3.tar.gz
gcc-2a7a0589f62ab9157d9f862ec2fd7d680c53c5f3.tar.bz2
gccrs const folding port: continue porting potential_constant_expression_1()
Following functions are ported in this changeset: - maybe_constexpr_fn - get_nth_callarg - var_in_maybe_constexpr_fn - array_type_nelts_top - builtin_valid_in_constant_expr_p - decl_maybe_constant_var_p - cp_type_quals
Diffstat (limited to 'gcc/rust/backend/rust-constexpr.cc')
-rw-r--r--gcc/rust/backend/rust-constexpr.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-constexpr.cc b/gcc/rust/backend/rust-constexpr.cc
index f77fb3a..53c6ef6 100644
--- a/gcc/rust/backend/rust-constexpr.cc
+++ b/gcc/rust/backend/rust-constexpr.cc
@@ -397,5 +397,45 @@ get_function_named_in_call (tree t)
return fun;
}
+// forked from gcc/cp/constexpr.cc maybe_constexpr_fn
+
+/* True if a function might be declared constexpr */
+
+bool
+maybe_constexpr_fn (tree t)
+{
+ return (DECL_DECLARED_CONSTEXPR_P (t));
+}
+
+// forked from gcc/cp/constexpr.cc get_nth_callarg
+
+/* We have an expression tree T that represents a call, either CALL_EXPR.
+ Return the Nth argument. */
+
+inline tree
+get_nth_callarg (tree t, int n)
+{
+ switch (TREE_CODE (t))
+ {
+ case CALL_EXPR:
+ return CALL_EXPR_ARG (t, n);
+
+ default:
+ gcc_unreachable ();
+ return NULL;
+ }
+}
+
+// forked from gcc/cp/constexpr.cc var_in_maybe_constexpr_fn
+
+/* True if T was declared in a function that might be constexpr: either a
+ function that was declared constexpr. */
+
+bool
+var_in_maybe_constexpr_fn (tree t)
+{
+ return (DECL_FUNCTION_SCOPE_P (t) && maybe_constexpr_fn (DECL_CONTEXT (t)));
+}
+
} // namespace Compile
} // namespace Rust