Skip to content

llvm lint: Undefined behavior: Memory reference address is misaligned #56267

Closed
@matthiaskrgr

Description

@matthiaskrgr

reduced from num_cpus:

extern crate libc;

#[inline]
pub fn get_physical() -> usize {
    get_num_physical_cpus()
}

#[cfg(target_os = "linux")]
fn get_num_physical_cpus() -> usize {
    use std::collections::HashSet;
    use std::fs::File;
    use std::io::BufRead;
    use std::io::BufReader;

    let file = File::open("/proc/cpuinfo").unwrap();
    let reader = BufReader::new(file);
    let mut set = HashSet::new();
    for _ in reader.lines().filter_map(|result| result.ok()) {
        set.insert((0, 0));
    }
    4
}

built with
RUSTFLAGS="-C passes=lint" cargo build --release -j 1 yields

   Compiling libc v0.2.44
Unusual: Return statement in function with noreturn attribute
  ret void
   Compiling num_cpus v1.8.0 (/tmp/num_cpus)
Undefined behavior: Memory reference address is misaligned
  %61 = load i32, i32* %60, align 8
Undefined behavior: Memory reference address is misaligned
  %132 = load i32, i32* %131, align 8
    Finished release [optimized] target(s) in 1.12s

cc #7463

rustc 1.32.0-nightly (6bfb46e4a 2018-11-26)
binary: rustc
commit-hash: 6bfb46e4ac9a2704f06de1a2ff7a4612cd70c8cb
commit-date: 2018-11-26
host: x86_64-unknown-linux-gnu
release: 1.32.0-nightly
LLVM version: 8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions