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

llvm lint: Unusual: "Load from function body" on unsafe code #60321

Closed
matthiaskrgr opened this issue Apr 26, 2019 · 2 comments
Closed

llvm lint: Unusual: "Load from function body" on unsafe code #60321

matthiaskrgr opened this issue Apr 26, 2019 · 2 comments
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/thinlto/thin-lto-inlines.rs -C passes=lint -C opt-level=3 
Unusual: Load from function body
  %28 = load i8, i8* bitcast (i32 ()* @_ZN16thin_lto_inlines3foo17h0a63dafc3d3ea645E to i8*), align 1
Unusual: Load from function body
  %29 = load i8, i8* bitcast (i32 ()* @_ZN16thin_lto_inlines3bar3bar17hb953f1ee32a332f0E to i8*), align 1

the code contains unsafe code though:

// run-pass

// compile-flags: -Z thinlto -C codegen-units=8 -O
// ignore-emscripten can't inspect instructions on emscripten

// We want to assert here that ThinLTO will inline across codegen units. There's
// not really a great way to do that in general so we sort of hack around it by
// praying two functions go into separate codegen units and then assuming that
// if inlining *doesn't* happen the first byte of the functions will differ.

pub fn foo() -> u32 {
    bar::bar()
}

mod bar {
    pub fn bar() -> u32 {
        3
    }
}

fn main() {
    println!("{} {}", foo(), bar::bar());

    unsafe {
        let foo = foo as usize as *const u8;
        let bar = bar::bar as usize as *const u8;

        assert_eq!(*foo, *bar);
    }
}

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. labels Apr 27, 2019
@nikic
Copy link
Contributor

nikic commented Apr 27, 2019

This seems fine. The lint complains exactly about what the code is intended to do (inspecting instructions in the function), and it's just an "unusual" lint. What the code does is indeed very unusual ;)

@Mark-Simulacrum
Copy link
Member

Closing since we believe this is okay.

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