]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: add new -frust-overflow-checks flag to control overflow checks
authorPhilip Herron <herron.philip@googlemail.com>
Thu, 23 Jan 2025 14:44:20 +0000 (14:44 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:06:57 +0000 (13:06 +0100)
This will be crucial for more complex gimple debugging to make it easier
to follow the code vs the original rust code.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): disable overflow checks
* lang.opt: new flag

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/lang.opt

index 887e476f234a3a52f5198154309357108ad393d5..29cc8835c33d186a0898e2a48f4d444abd482039 100644 (file)
@@ -159,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
index 0e9aab48dfb7a2d8cfb24a11f04d8ab11d82d91d..9cdbce2bc0af4e59059e94a21d324c514e575ccc 100644 (file)
@@ -225,4 +225,8 @@ Enum(frust_panic) String(unwind) Value(0)
 EnumValue
 Enum(frust_panic) String(abort) Value(1)
 
+frust-overflow-checks
+Rust Var(flag_overflow_checks) Init(1)
+Enable the overflow checks in code generation
+
 ; This comment is to ensure we retain the blank line above.