aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc49
1 files changed, 23 insertions, 26 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 353a498..21f4ca1 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -31,6 +31,7 @@
#include "convert.h"
#include "print-tree.h"
#include "rust-system.h"
+#include "rust-tyty.h"
namespace Rust {
namespace Compile {
@@ -158,27 +159,28 @@ CompileExpr::visit (HIR::ArithmeticOrLogicalExpr &expr)
return;
}
- if (ctx->in_fn () && !ctx->const_context_p ())
- {
- auto receiver_tmp = NULL_TREE;
- auto receiver
- = Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
- TREE_TYPE (lhs), lhs, true,
- expr.get_locus (), &receiver_tmp);
- auto check
- = Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
- expr.get_locus (),
- receiver);
-
- ctx->add_statement (check);
- translated = receiver->get_tree (expr.get_locus ());
- }
- else
+ bool can_generate_overflow_checks
+ = (ctx->in_fn () && !ctx->const_context_p ()) && flag_overflow_checks;
+ if (!can_generate_overflow_checks)
{
translated
= Backend::arithmetic_or_logical_expression (op, lhs, rhs,
expr.get_locus ());
+ return;
}
+
+ auto receiver_tmp = NULL_TREE;
+ auto receiver
+ = Backend::temporary_variable (ctx->peek_fn ().fndecl, NULL_TREE,
+ TREE_TYPE (lhs), lhs, true,
+ expr.get_locus (), &receiver_tmp);
+ auto check
+ = Backend::arithmetic_or_logical_expression_checked (op, lhs, rhs,
+ expr.get_locus (),
+ receiver);
+
+ ctx->add_statement (check);
+ translated = receiver->get_tree (expr.get_locus ());
}
void
@@ -1035,11 +1037,6 @@ check_match_scrutinee (HIR::MatchExpr &expr, Context *ctx)
}
TyTy::TypeKind scrutinee_kind = scrutinee_expr_tyty->get_kind ();
- rust_assert ((TyTy::is_primitive_type_kind (scrutinee_kind)
- && scrutinee_kind != TyTy::TypeKind::NEVER)
- || scrutinee_kind == TyTy::TypeKind::ADT
- || scrutinee_kind == TyTy::TypeKind::TUPLE
- || scrutinee_kind == TyTy::TypeKind::REF);
if (scrutinee_kind == TyTy::TypeKind::FLOAT)
{
@@ -1397,8 +1394,8 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
TyTy::FnType *fntype = static_cast<TyTy::FnType *> (lookup_fntype);
TyTy::BaseType *receiver = nullptr;
- ok = ctx->get_tyctx ()->lookup_receiver (expr.get_mappings ().get_hirid (),
- &receiver);
+ ok = ctx->get_tyctx ()->lookup_type (
+ expr.get_receiver ().get_mappings ().get_hirid (), &receiver);
rust_assert (ok);
bool is_dyn_dispatch
@@ -1535,8 +1532,8 @@ CompileExpr::resolve_operator_overload (
TyTy::BaseType *receiver = nullptr;
bool ok
- = ctx->get_tyctx ()->lookup_receiver (expr.get_mappings ().get_hirid (),
- &receiver);
+ = ctx->get_tyctx ()->lookup_type (lhs_expr.get_mappings ().get_hirid (),
+ &receiver);
rust_assert (ok);
bool is_generic_receiver = receiver->get_kind () == TyTy::TypeKind::PARAM;
@@ -2456,7 +2453,7 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
auto body_mappings = function_body.get_mappings ();
if (flag_name_resolution_2_0)
{
- auto nr_ctx
+ auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());