Skip to content

Commit deaa2fe

Browse files
committed
Make the feature whitelists constants
This simplifies the code a bit and makes the types nicer, too.
1 parent 1ad8561 commit deaa2fe

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/librustc_driver/target_features.rs

+25-25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ use syntax::parse::token::InternedString;
1616
use syntax::parse::token::intern_and_get_ident as intern;
1717
use libc::c_char;
1818

19+
// WARNING: the features must be known to LLVM or the feature
20+
// detection code will walk past the end of the feature array,
21+
// leading to crashes.
22+
23+
const ARM_WHITELIST: &'static [&'static str] = &[
24+
"neon\0",
25+
"vfp2\0",
26+
"vfp3\0",
27+
"vfp4\0",
28+
];
29+
30+
const X86_WHITELIST: &'static [&'static str] = &[
31+
"avx\0",
32+
"avx2\0",
33+
"sse\0",
34+
"sse2\0",
35+
"sse3\0",
36+
"sse4.1\0",
37+
"sse4.2\0",
38+
"ssse3\0",
39+
];
40+
1941
/// Add `target_feature = "..."` cfgs for a variety of platform
2042
/// specific features (SSE, NEON etc.).
2143
///
@@ -24,32 +46,10 @@ use libc::c_char;
2446
pub fn add_configuration(cfg: &mut ast::CrateConfig, sess: &Session) {
2547
let target_machine = create_target_machine(sess);
2648

27-
// WARNING: the features must be known to LLVM or the feature
28-
// detection code will walk past the end of the feature array,
29-
// leading to crashes.
30-
31-
let arm_whitelist = [
32-
"neon\0",
33-
"vfp2\0",
34-
"vfp3\0",
35-
"vfp4\0",
36-
];
37-
38-
let x86_whitelist = [
39-
"avx\0",
40-
"avx2\0",
41-
"sse\0",
42-
"sse2\0",
43-
"sse3\0",
44-
"sse4.1\0",
45-
"sse4.2\0",
46-
"ssse3\0",
47-
];
48-
4949
let whitelist = match &*sess.target.target.arch {
50-
"arm" => &arm_whitelist[..],
51-
"x86" | "x86_64" => &x86_whitelist[..],
52-
_ => &[][..],
50+
"arm" => ARM_WHITELIST,
51+
"x86" | "x86_64" => X86_WHITELIST,
52+
_ => &[],
5353
};
5454

5555
let tf = InternedString::new("target_feature");

0 commit comments

Comments
 (0)