Skip to content
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

Properly compare unequal function pointers #581

Closed
wants to merge 2 commits into from
Closed

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Dec 19, 2018

fixes #577

}

fn main() {
assert!(return_fn_ptr() != f);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add this to the existing fn ptr test instead?

}

fn main() {
assert!(return_fn_ptr() == f); //~ ERROR assertion failed
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of this test? We already test elsewhere that assert!(false) fails, don't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wanted to make sure we're getting the right error. But I guess the run-pass test kinda guarantees that

// Two in-bounds pointers, we can compare across allocations
left == right

let check = |ptr: Pointer<Borrow>| match self.memory().get(ptr.alloc_id) {
Copy link
Member

Choose a reason for hiding this comment

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

This is not nice. :/

For once, it's not correct: A pointer into a function allocation is only in-bounds if its offset is 0.

But also, the previous behavior that memory().check_bounds would accept offset-0-size-0 pointers into function allocations was fully intended. These pointers are in-bounds. There is nothing wrong with a &() pointing to a function allocation. So I don't think fixing this here is how we want to proceed.

For example, pointer_offset_inbounds now also fails to compute a 0-offset on a function pointer. This affects every user of the old check_bounds method that was converted to memory().get.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can reintroduce the check_bounds method on Memory

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think that would make most sense.

@RalfJung
Copy link
Member

Superseded by #587

@RalfJung RalfJung closed this Dec 25, 2018
@oli-obk oli-obk deleted the fn_ptr_comparison branch January 16, 2020 08:04
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.

Better error messages when comparing fn ptrs
2 participants