gccrs: backend: Add overflow checks to every arithmetic operation
authorArthur Cohen <arthur.cohen@embecosm.com>
Fri, 26 Aug 2022 06:44:02 +0000 (08:44 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 31 Jan 2023 13:16:49 +0000 (14:16 +0100)
commit9c87dc0afe059ce54280dd81ff773f910a6dffdf
tree83fb51fefaa069421de491008642cd29ae08c2c7
parent41547275c5e9a9b7a92898106180b2d295e1ed36
gccrs: backend: Add overflow checks to every arithmetic operation

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Insert overflow
checks logic.
(CompileExpr::array_copied_expr): Insert overflow checks logic.
* backend/rust-compile-item.cc (CompileItem::visit): Insert overflow
checks logic.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Insert
overflow checks logic.
* rust-gcc.cc (Gcc_backend::arithmetic_or_logical_expression): Differentiate
existing function from `arithmetic_or_logical_expression_checked`.
This function does insert perform overflow checks.
(Gcc_backend::arithmetic_or_logical_expression_checked): New
function.
(is_overflowing_expr): New function. Check if an expression is an
overflowing one (ADD, SUB, MUL).
(fetch_overflow_builtins): New function.
* rust-backend.h: Declare `arithmetic_or_logical_expression_checked` in
abstract `Backend` class.

gcc/testsuite/ChangeLog:

* rust/debug/win64-abi.rs: Fix assertion to take into account
overflow builtins
* rust/compile/torture/macro-issue1426.rs: Moved to...
* rust/execute/torture/macro-issue1426.rs: ...here.
* rust/execute/torture/overflow1.rs: New test.
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/backend/rust-compile-item.cc
gcc/rust/backend/rust-compile-type.cc
gcc/rust/rust-backend.h
gcc/rust/rust-gcc.cc
gcc/testsuite/rust/debug/win64-abi.rs
gcc/testsuite/rust/execute/torture/macro-issue1426.rs [moved from gcc/testsuite/rust/compile/torture/macro-issue1426.rs with 68% similarity]
gcc/testsuite/rust/execute/torture/overflow1.rs [new file with mode: 0644]