Skip to content

transpile: Override pointer difference expression type to PtrDiff#1843

Open
Rua wants to merge 4 commits into
immunant:masterfrom
Rua:ptrdiff-type
Open

transpile: Override pointer difference expression type to PtrDiff#1843
Rua wants to merge 4 commits into
immunant:masterfrom
Rua:ptrdiff-type

Conversation

@Rua

@Rua Rua commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

@Rua Rua changed the title transpile: Override pointer difference expression type to Ptrdiff transpile: Override pointer difference expression type to PtrDiff Jun 8, 2026
@Rua Rua force-pushed the ptrdiff-type branch 5 times, most recently from 6336ba3 to e962d4c Compare June 9, 2026 15:19
@ahomescu ahomescu requested review from ahomescu and fw-immunant June 11, 2026 00:16
Comment thread c2rust-transpile/tests/snapshots/snapshots__transpile@exprs.c.2021.clang15.snap Outdated
@Rua Rua force-pushed the ptrdiff-type branch 3 times, most recently from 40761b9 to 19cbcc4 Compare June 12, 2026 10:26
@Rua

Rua commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

This now depends on #1850 so that the definition of ptrdiff_t in the snapshot test doesn't differ between platforms.

@Rua Rua requested a review from ahomescu June 12, 2026 10:48
@Rua Rua force-pushed the ptrdiff-type branch 5 times, most recently from 3dc93a5 to 2cf3e05 Compare June 15, 2026 12:04
@Rua Rua force-pushed the ptrdiff-type branch 2 times, most recently from b28b829 to bcd749b Compare June 17, 2026 08:39

@fw-immunant fw-immunant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

) -> WithStmts<Box<Expr>> {
let mut expr_rs = mk().method_call_expr(lhs_rs, "offset_from", vec![rhs_rs]);

if let Some(sz) = self.compute_size_of_expr(pointee_type_id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this needed? If lhs_rs is already of type *mut $pointee_type then offset_from returns the size in units of $pointee_type. There is byte_offset_from for the byte distance. Am I missing something here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. I left it unchanged because it was already in the original code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transpile: Pointer difference results in c_long rather than ptrdiff_t

3 participants