Skip to content

Commit 00dcb66

Browse files
committed
cmdline: Make target features individually overridable
1 parent 9912925 commit 00dcb66

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/doc/rustc/src/codegen-options/index.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,15 @@ machine. Each target has a default base CPU.
464464

465465
Individual targets will support different features; this flag lets you control
466466
enabling or disabling a feature. Each feature should be prefixed with a `+` to
467-
enable it or `-` to disable it. Separate multiple features with commas.
467+
enable it or `-` to disable it.
468+
469+
Features from multiple `-C target-feature` options are combined. \
470+
Multiple features can be specified in a single option by separating them
471+
with commas - `-C target-feature=+x,-y`. \
472+
If some feature is specified more than once with both `+` and `-`,
473+
then values passed later override values passed earlier. \
474+
For example, `-C target-feature=+x,-y,+z -Ctarget-feature=-x,+y`
475+
is equivalent to `-C target-feature=-x,+y,+z`.
468476

469477
To see the valid options and an example of use, run `rustc --print
470478
target-features`.

src/librustc_session/options.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ macro_rules! options {
270270
"one of supported relocation models (`rustc --print relocation-models`)";
271271
pub const parse_tls_model: &str =
272272
"one of supported TLS models (`rustc --print tls-models`)";
273+
pub const parse_target_feature: &str = parse_string;
273274
}
274275

275276
#[allow(dead_code)]
@@ -636,6 +637,19 @@ macro_rules! options {
636637
}
637638
true
638639
}
640+
641+
fn parse_target_feature(slot: &mut String, v: Option<&str>) -> bool {
642+
match v {
643+
Some(s) => {
644+
if !slot.is_empty() {
645+
slot.push_str(",");
646+
}
647+
slot.push_str(s);
648+
true
649+
}
650+
None => false,
651+
}
652+
}
639653
}
640654
) }
641655

@@ -731,7 +745,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
731745
"use soft float ABI (*eabihf targets only) (default: no)"),
732746
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
733747
"select target processor (`rustc --print target-cpus` for details)"),
734-
target_feature: String = (String::new(), parse_string, [TRACKED],
748+
target_feature: String = (String::new(), parse_target_feature, [TRACKED],
735749
"target specific attributes. (`rustc --print target-features` for details). \
736750
This feature is unsafe."),
737751

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// only-x86_64
2+
// compile-flags: -C target-feature=+sse2,-avx,+avx2 -C target-feature=+avx,-avx2
3+
4+
#![crate_type = "lib"]
5+
6+
#[no_mangle]
7+
pub fn foo() {
8+
// CHECK: attributes #0 = { {{.*}}"target-features"="+sse2,-avx,+avx2,+avx,-avx2"{{.*}} }
9+
}

0 commit comments

Comments
 (0)