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

crash using by-value records with mutable fields #2493

Closed
nikomatsakis opened this issue Jun 3, 2012 · 3 comments
Closed

crash using by-value records with mutable fields #2493

nikomatsakis opened this issue Jun 3, 2012 · 3 comments
Assignees
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Milestone

Comments

@nikomatsakis
Copy link
Contributor

The following program will segfault, double free, leak, and generally misbehave:

type T = {mut f: @int};
fn foo(++x: T) { x.f = @4; }
fn main() {
    let x = {mut f: @3};
    foo(x);
}

The reason is our by-value protocol: we copy the data for the record but do not invoke the take-glue (nor drop-glue). As a result, the assignment x.f = @4 within foo() causes the original @3 to be freed, but never arranges for the new @4 to be released. When foo() returns, main() tries to drop its copy of x, which still contains the original @3 pointer.

Of course the same badness would happen if the type T included a unique pointer. Or really anything that requires take/drop-glue.

@nikomatsakis
Copy link
Contributor Author

should we keep by-value mode (and I could see that it might be a good idea for performance), one solution I could institute easily enough is for borrowck to forbid modifications to interior data of a by-val mode argument

@nikomatsakis
Copy link
Contributor Author

actually that would not be sufficient. I'd also have to modify borrowck to ensure the caller doesn't modify the arg in some sort of closure.

@ghost ghost assigned nikomatsakis Jun 7, 2012
@graydon
Copy link
Contributor

graydon commented Aug 31, 2012

Obsolete / WONTFIX due to scheduled removal of modes.

@graydon graydon closed this as completed Aug 31, 2012
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
add very basic Android support

This is just enough to print to stdout. I won't push this any further, but having these basics should hopefully make it easier for others to do so.

Also slightly improve threading support on FreeBSD while we are at it.

Partially based on rust-lang/miri#2011.
Fixes rust-lang/miri#2010.
celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Kani compiler will now only store KaniMetadata after compiling all harnesses. Before, we were storing before codegen in the first iteration of the compiler.

This will still allow us to generate metadata without actually performing codegen, if we ever implement a `kani list` subcommand. The metadata won't be stored though if Kani fails to codegen. However, we don't do anything extra with that file if the compilation fails.

This change is required for rust-lang#2493 and contracts work. This will allow us to store information collected during code generation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

2 participants