Skip to content

llvm lint: "Unusual: Address one pointer dereference" on unsafe code #60320

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 · 2 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/signal-exit-status.rs -C passes=lint -C opt-level=3
Unusual: Address one pointer dereference
  store i64 0, i64* inttoptr (i64 1 to i64*), align 8

code:

// ignore-cloudabi no processes
// ignore-emscripten no processes
// ignore-windows

use std::env;
use std::process::Command;

pub fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() >= 2 && args[1] == "signal" {
        // Raise a segfault.
        unsafe { *(1 as *mut isize) = 0; }
    } else {
        let status = Command::new(&args[0]).arg("signal").status().unwrap();
        assert!(status.code().is_none());
    }
}

Is this expected given the snippet contains unsafe code?

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. C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed C-cleanup Category: PRs that clean code up or issues documenting cleanup. labels Apr 27, 2019
@nikic
Copy link
Contributor

nikic commented Apr 27, 2019

This one looks okay as well. The code is dereferencing a 1-pointer to generate a segfault, which is (some special cases notwithstanding) UB.

Might be nice to raise sigsegv in a more conventional way for this test though.

@Mark-Simulacrum
Copy link
Member

Closing since we think 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