Stream: t-compiler/const-eval

Topic: cast-fn-ptr-unsafe tests


RalfJ (Nov 15 2018 at 17:32, on Zulip):

@Oli I don' get https://github.com/solson/miri/blob/master/tests/compile-fail/cast_fn_ptr_unsafe.rs and https://github.com/solson/miri/blob/master/tests/compile-fail/cast_fn_ptr_unsafe2.rs

RalfJ (Nov 15 2018 at 17:32, on Zulip):

the comment doesn't even match what the test does

RalfJ (Nov 15 2018 at 17:32, on Zulip):

rustc does allow casting fn() to unsafe fn()

RalfJ (Nov 15 2018 at 17:32, on Zulip):

and indeed why wouldn't it?

RalfJ (Nov 15 2018 at 17:49, on Zulip):

my inclination is to just remove these two tests. we got tons of tests for what happens when you transmute a fn ptr and call a fn with the wrong signature. I do not know what these two add.

RalfJ (Nov 15 2018 at 17:50, on Zulip):

Seems you added them with https://github.com/solson/miri/commit/00eb198a82376eeb608c32e6d4252743f6dcfc87 though sh probably there was a reason

oli (Nov 16 2018 at 07:12, on Zulip):

we want to prevent calling an unsafe fn via a fn pointer

oli (Nov 16 2018 at 07:13, on Zulip):

feel free to remove them, we do need to trust the type system

RalfJ (Nov 16 2018 at 07:49, on Zulip):

we want to prevent calling an unsafe fn via a fn pointer

Do we? I can transmute one to the other and then call it. And I do not see a good way -- nor a good reason -- to disallow this.

RalfJ (Nov 16 2018 at 07:49, on Zulip):

Or do you mean "in safe code"? That is a type system matter, miri shouldn't (and in many cases can't) care.

oli (Nov 16 2018 at 07:51, on Zulip):

I agree fully with the two things you said and have come to the same conclusion. Back then I think I added this just to be very sure

oli (Nov 16 2018 at 07:53, on Zulip):

unsafe code may convert an unsafe fn pointer to a safe one. That might actually be totally safe if e.g. the arguments change, too. If the arg was *const T that was dereferenced inside the function and we converted the function pointer to something taking a &T, then that seems like a valid operation

RalfJ (Nov 16 2018 at 07:56, on Zulip):

ack

RalfJ (Nov 16 2018 at 07:56, on Zulip):

PR submitted

Last update: Nov 15 2019 at 21:20UTC