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

Inlining introduces unsized temporaries #111355

Closed
tmiasko opened this issue May 8, 2023 · 1 comment · Fixed by #111424
Closed

Inlining introduces unsized temporaries #111355

tmiasko opened this issue May 8, 2023 · 1 comment · Fixed by #111424
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. F-unsized_fn_params `#![feature(unsized_fn_params)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@tmiasko
Copy link
Contributor

tmiasko commented May 8, 2023

Inlining introduces unsized temporaries. This is problematic since unsized temporaries fail to uphold alignment requirements as described in #71416. For example:

#![feature(unsized_fn_params)]
use std::any::Any;
use std::hint::black_box;

#[repr(align(1024))]
#[allow(dead_code)]
struct A(u8);

impl A {
    fn f(&self) {
        assert_eq!(0, black_box(self as *const A as usize) % 1024);
    }
}

#[inline(always)]
pub fn f(a: dyn Any) {
    a.downcast_ref::<A>().unwrap().f()
}

pub fn main() {
    let a = Box::new(A(0)) as Box<dyn Any>;
    f(*a);
}
$ rustc d.rs -O -Zinline-mir=off && ./d
$ rustc d.rs -O && ./d
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `0`,
 right: `992`', d.rs:11:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@tmiasko tmiasko added A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness C-bug Category: This is a bug. F-unsized_fn_params `#![feature(unsized_fn_params)]` labels May 8, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 8, 2023
@tmiasko tmiasko added the A-mir-opt-inlining Area: MIR inlining label May 8, 2023
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label May 17, 2023
@tmiasko tmiasko removed the I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness label May 17, 2023
@tmiasko tmiasko changed the title Inlining introduces unsized temporaries that fail to uphold alignment requirements Inlining introduces unsized temporaries May 17, 2023
@tmiasko
Copy link
Contributor Author

tmiasko commented May 17, 2023

The unsized locals alignment issue itself was fixed in #111374.

@oli-obk oli-obk added the requires-nightly This issue requires a nightly compiler in some way. label May 17, 2023
@bors bors closed this as completed in 0634557 May 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. F-unsized_fn_params `#![feature(unsized_fn_params)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants