Skip to content

Add write_bytes and arith_offset#4620

Merged
philberty merged 2 commits into
Rust-GCC:masterfrom
nsvke:add-ptr-intrinsics
Jun 29, 2026
Merged

Add write_bytes and arith_offset#4620
philberty merged 2 commits into
Rust-GCC:masterfrom
nsvke:add-ptr-intrinsics

Conversation

@nsvke

@nsvke nsvke commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

This patch implements arith_offset and write_bytes compiler intrinsics.

  • write_bytes: Lowered to __builtin_memset.
  • arith_offset: Lowered using POINTER_PLUS_EXPR.

rustc behavior:

nsvke added 2 commits June 26, 2026 16:36
This patch implements the 'write_bytes' compiler intrinsic. It performs
a write operation to memory using '__builtin_memset'.

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (generic_intrinsics): Add
	write_bytes handler to map.
	* backend/rust-intrinsic-handlers.cc (write_bytes_handler): New
	function.
	* backend/rust-intrinsic-handlers.h (write_bytes_handler): New
	declaration.
	* typecheck/rust-hir-type-check-intrinsic.cc
	(IntrinsicChecker::intrinsic_rules): Add write_bytes rule.
	* util/rust-intrinsic-values.h (class Intrinsics): Add
	WRITE_BYTES constexpr.

gcc/testsuite/ChangeLog:

	* rust/execute/write-bytes.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
This patch implements the 'arith_offset' compiler intrinsic. It moves a
pointer forward or backward by a given number of elements. It does not
cause Undefined Behavior if the pointer goes out of bounds.

gcc/rust/ChangeLog:

	* backend/rust-compile-intrinsic.cc (generic_intrinsics): Add
	arith_offset handler to map.
	* backend/rust-intrinsic-handlers.cc (arith_offset_handler): New
	function.
	* backend/rust-intrinsic-handlers.h (arith_offset_handler): New
	declaration.
	* typecheck/rust-hir-type-check-intrinsic.cc
	(IntrinsicChecker::intrinsic_rules): Add arith_offset rule.
	* util/rust-intrinsic-values.h (class Intrinsics): Add
	ARITH_OFFSET constexpr.

gcc/testsuite/ChangeLog:

	* rust/execute/arith-offset.rs: New test.

Signed-off-by: Enes Cevik <enes@nsvke.com>
@nsvke nsvke force-pushed the add-ptr-intrinsics branch from 4d47a74 to 77fda88 Compare June 26, 2026 14:05

@philberty philberty left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@philberty philberty added this pull request to the merge queue Jun 29, 2026
Merged via the queue into Rust-GCC:master with commit 26ca5e3 Jun 29, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants