Skip to content

rustc does not detect CPU features correctly when target-cpu=native on Zen 3 #80633

Closed
@as-com

Description

@as-com

I (actually, @tykosa, who managed to get a Ryzen 5 5600X) tried this code:

#[cfg(target_feature = "avx")]
fn foo() {
    println!("hi");
}

fn main() {
    foo();
}

I expected to see this happen: the compiler detects that the CPU has AVX support and compiles the code, like it does on other CPUs

Instead, this happened:

$ rustc -C target-cpu=native test.rs
error[E0425]: cannot find function foo in this scope
 --> test.rs:7:9
  |
7 |         foo();
  |         ^^^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (17eec1433 2021-01-01)
binary: rustc
commit-hash: 17eec1433c69972844dd228b5fe801f218e118c3
commit-date: 2021-01-01
host: x86_64-unknown-linux-gnu
release: 1.51.0-nightly

rustc --print=target-cpus

Available CPUs for this target:
    native         - Select the CPU of the current host (currently generic).
    amdfam10
    athlon
    athlon-4
...
...
  yonah
    znver1
    znver2

Snippet of /proc/cpuinfo:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions