Skip to content

Support overflowing_add in libcore #1898

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
Tracked by #1895
philberty opened this issue Feb 21, 2023 · 0 comments · Fixed by #1945
Closed
2 tasks done
Tracked by #1895

Support overflowing_add in libcore #1898

philberty opened this issue Feb 21, 2023 · 0 comments · Fixed by #1945
Assignees
Labels

Comments

@philberty
Copy link
Member

I tried this code:

mod intrinsics {
    extern "rust-intrinsic" {
        pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
    }
}

pub enum Option<T> {
    None,
    Some(T),
}

#[lang = "i32"]
impl i32 {
    pub fn checked_add(self, rhs: Self) -> Option<Self> {
        let (a, b) = self.overflowing_add(rhs);
        if b {
            Option::None
        } else {
            Option::Some(a)
        }
    }

    pub fn overflowing_add(self, rhs: Self) -> (Self, bool) {
        let (a, b) = unsafe { intrinsics::add_with_overflow(self as i32, rhs as i32) };
        (a as Self, b)
    }
}

I expected to see this happen: compile without error

test.rs:24:31: error: unknown builtin intrinsic: add_with_overflow
   24 |         let (a, b) = unsafe { intrinsics::add_with_overflow(self as i32, rhs as i32) };
      |                               ^~~~~~~~~~

Meta

  • What version of Rust GCC were you using, git sha if possible.
@philberty philberty added the bug label Feb 21, 2023
@github-project-automation github-project-automation bot moved this to Additional sprint items in libcore 1.49 Feb 21, 2023
@philberty philberty mentioned this issue Feb 21, 2023
41 tasks
@philberty philberty self-assigned this Mar 1, 2023
philberty added a commit that referenced this issue Mar 1, 2023
Fixes #1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner):
	(std::function<tree): new wrapper over op_with_overflow
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
philberty added a commit that referenced this issue Mar 1, 2023
Fixes #1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
philberty added a commit that referenced this issue Mar 1, 2023
Fixes #1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
@github-project-automation github-project-automation bot moved this from Additional sprint items to Done in libcore 1.49 Mar 1, 2023
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Mar 2, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Mar 2, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Mar 27, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Apr 6, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Apr 7, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 15, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Nov 21, 2023
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 5, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 9, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 11, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 12, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 16, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
CohenArthur pushed a commit to CohenArthur/gccrs that referenced this issue Jan 17, 2024
Fixes Rust-GCC#1898

Signed-off-by: Philip Herron <[email protected]>

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): wraps op_with_overflow
	(std::function<tree): likewise
	(op_with_overflow): generate the intrinsic based on the tree_code op

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-8.rs: New test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant