Skip to content

llvm lint: Pessimization: Static alloca outside of entry block / UB #60322

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

Closed
matthiaskrgr opened this issue Apr 26, 2019 · 3 comments
Closed
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

rustc 1.36.0-nightly (3991285f5 2019-04-25)
binary: rustc
commit-hash: 3991285f55a4b7cd92b7ffcdc396a3023076f5cb
commit-date: 2019-04-25
host: x86_64-unknown-linux-gnu
release: 1.36.0-nightly
LLVM version: 8.0
rustc src/test/run-pass/unsized-locals/autoderef.rs -C passes=lint -C opt-level=3
Pessimization: Static alloca outside of entry block
  %95 = alloca i8, i64 20, align 16
Pessimization: Static alloca outside of entry block
  %290 = alloca i8, i64 0, align 16
Pessimization: Static alloca outside of entry block
  %295 = alloca i8, i64 0, align 16
Pessimization: Static alloca outside of entry block
  %338 = alloca i8, i64 0, align 16
Undefined behavior: Call argument type mismatches callee parameter type
  call void bitcast (void (%"main::{{closure}}"*)* @_ZN4core3ptr18real_drop_in_place17h74dade2e05fed3c8E to void ({}*)*)({}* align 1 %292) #9

code:

#![feature(unsized_locals)]

pub trait Foo {
    fn foo(self) -> String;
}

impl Foo for [char] {
    fn foo(self) -> String {
        self.iter().collect()
    }
}

impl Foo for str {
    fn foo(self) -> String {
        self.to_owned()
    }
}

impl Foo for dyn FnMut() -> String {
    fn foo(mut self) -> String {
        self()
    }
}


fn main() {
    let x = *(Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>);
    assert_eq!(&x.foo() as &str, "hello");

    let x = Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>;
    assert_eq!(&x.foo() as &str, "hello");

    let x = "hello".to_owned().into_boxed_str();
    assert_eq!(&x.foo() as &str, "hello");

    let x = *("hello".to_owned().into_boxed_str());
    assert_eq!(&x.foo() as &str, "hello");

    let x = "hello".to_owned().into_boxed_str();
    assert_eq!(&x.foo() as &str, "hello");

    let x = *(Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>);
    assert_eq!(&x.foo() as &str, "hello");

    let x = Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>;
    assert_eq!(&x.foo() as &str, "hello");
}

cc #7463

@jonas-schievink jonas-schievink added A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-nominated and removed I-nominated labels Apr 27, 2019
@jonas-schievink
Copy link
Contributor

The UB issue looks similar to #48310 at least

@nikic
Copy link
Contributor

nikic commented Apr 27, 2019

Not sure if we can do anything here. We don't generate those allocas that way, but the originally dynamic alloca size is statically determined during optimization.

@Mark-Simulacrum
Copy link
Member

This has since been fixed, as far as I can tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants