Skip to content

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

Closed
@matthiaskrgr

Description

@matthiaskrgr
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions