Skip to content

Make sure casts from other types to fat pointers are illegal #25038

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

Merged
merged 1 commit into from
May 2, 2015

Conversation

bluss
Copy link
Member

@bluss bluss commented May 1, 2015

typeck: Make sure casts from other types to fat pointers are illegal

Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,

Fixes #21397
Fixes #22955
Fixes #23237
Fixes #24100

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see CONTRIBUTING.md for more information.

@bluss bluss force-pushed the fat-pointer-cast branch from f5c5423 to ca2ac60 Compare May 1, 2015 19:53
@bluss bluss changed the title Make sure casts from fat to thin pointers are illegal Make sure casts from thin to fat pointers are illegal May 1, 2015
@bluss
Copy link
Member Author

bluss commented May 1, 2015

This change catches more invalid casts than I intended..

@bluss bluss force-pushed the fat-pointer-cast branch from f79ca80 to 988da41 Compare May 1, 2015 20:45
@bluss bluss changed the title Make sure casts from thin to fat pointers are illegal Make sure casts from other types to fat pointers are illegal May 1, 2015
@brson
Copy link
Contributor

brson commented May 1, 2015

r? @pnkfelix

@rust-highfive rust-highfive assigned pnkfelix and unassigned brson May 1, 2015
@@ -14,6 +14,6 @@ fn main() {
let foo: *mut libc::c_void;
let cb: &mut Fn() = unsafe {
&mut *(foo as *mut Fn())
//~^ ERROR use of possibly uninitialized variable: `foo`
//~^ ERROR illegal cast
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this test case was actually testing the wrong thing. The associated issue is actually just another instance of casting thin <-> fat pointers, and this test case should not have closed that issue. Note that the error is complaining about something completely unrelated to why the code is actually invalid.

It would be great if you could actually fix up this test case to avoid the other reasons why this case is invalid. A corrected test case looks like

fn main() {
    let ptr: *mut () = 0 as *mut _;
    let _: &mut Fn() = unsafe {
        &mut *(ptr as *mut Fn())
    };
}

Copy link
Member Author

Choose a reason for hiding this comment

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

absolutely. Finding this test case was a bit confusing. Thanks for the test code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,

Fixes rust-lang#21397
Fixes rust-lang#22955
Fixes rust-lang#23237
Fixes rust-lang#24100
@bluss bluss force-pushed the fat-pointer-cast branch from 988da41 to 4806fb2 Compare May 1, 2015 23:20
@bluss
Copy link
Member Author

bluss commented May 1, 2015

Updated the list of issues this should fix (basically lots of the same kinds of fat pointer casts)

@luqmana
Copy link
Member

luqmana commented May 2, 2015

@bors r+ 4806fb2

@bors
Copy link
Collaborator

bors commented May 2, 2015

⌛ Testing commit 4806fb2 with merge 5574029...

bors added a commit that referenced this pull request May 2, 2015
typeck: Make sure casts from other types to fat pointers are illegal

Fixes ICEs where non-fat pointers and scalars are cast to fat pointers,

Fixes #21397
Fixes #22955
Fixes #23237
Fixes #24100
@bors bors merged commit 4806fb2 into rust-lang:master May 2, 2015
@bluss bluss deleted the fat-pointer-cast branch May 2, 2015 19:30
@bluss
Copy link
Member Author

bluss commented May 2, 2015

Nice. Thank you!

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