Skip to content

target_feature cfg only obeys -C target-feature="+feature" #31662

Closed
@hanna-kruppe

Description

@hanna-kruppe

This program on a 32 bit Linux outputs no SSE :( even though our default target does enable SSE and SSE2:

#![feature(cfg_target_feature)]

#[cfg(target_feature="sse")]
fn main() {
    println!("yay, SSE!");
}

#[cfg(not(target_feature="sse"))]
fn main() {
    println!("no SSE :(");
}

I'll save myself the hassle of copying rustc -vV from the VM I tested this on, because the relevant code hasn't been touched since cfg_target_feature was introduced in 4f44258 (July 2015).

This is because the feature detection is really naive, neither asking LLVM for details nor even looking at rustc's own target definitions. @huonw mentioned this in #27731 (comment) but IMHO this deserves an issue of its own.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions