Skip to content

Commit

Permalink
Fix LLVM version handling in compiletest
Browse files Browse the repository at this point in the history
Convert version string to integer before comparing. Otherwise
we get into trouble with double digit versions ;)
  • Loading branch information
nikic committed Mar 19, 2020
1 parent 841558d commit 7a14f9e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
27 changes: 21 additions & 6 deletions src/tools/compiletest/src/header.rs
Expand Up @@ -191,6 +191,7 @@ impl EarlyProps {
return true;
}
if let Some(ref actual_version) = config.llvm_version {
let actual_version = version_to_int(actual_version);
if line.starts_with("min-llvm-version") {
let min_version = line
.trim_end()
Expand All @@ -199,7 +200,7 @@ impl EarlyProps {
.expect("Malformed llvm version directive");
// Ignore if actual version is smaller the minimum required
// version
&actual_version[..] < min_version
actual_version < version_to_int(min_version)
} else if line.starts_with("min-system-llvm-version") {
let min_version = line
.trim_end()
Expand All @@ -208,7 +209,7 @@ impl EarlyProps {
.expect("Malformed llvm version directive");
// Ignore if using system LLVM and actual version
// is smaller the minimum required version
config.system_llvm && &actual_version[..] < min_version
config.system_llvm && actual_version < version_to_int(min_version)
} else if line.starts_with("ignore-llvm-version") {
// Syntax is: "ignore-llvm-version <version1> [- <version2>]"
let range_components = line
Expand All @@ -219,15 +220,15 @@ impl EarlyProps {
.take(3) // 3 or more = invalid, so take at most 3.
.collect::<Vec<&str>>();
match range_components.len() {
1 => &actual_version[..] == range_components[0],
1 => actual_version == version_to_int(range_components[0]),
2 => {
let v_min = range_components[0];
let v_max = range_components[1];
let v_min = version_to_int(range_components[0]);
let v_max = version_to_int(range_components[1]);
if v_max < v_min {
panic!("Malformed LLVM version range: max < min")
}
// Ignore if version lies inside of range.
&actual_version[..] >= v_min && &actual_version[..] <= v_max
actual_version >= v_min && actual_version <= v_max
}
_ => panic!("Malformed LLVM version directive"),
}
Expand All @@ -238,6 +239,20 @@ impl EarlyProps {
false
}
}

fn version_to_int(version: &str) -> u32 {
let version_without_suffix = version.split('-').next().unwrap();
let components: Vec<u32> = version_without_suffix
.split('.')
.map(|s| s.parse().expect("Malformed version component"))
.collect();
match components.len() {
1 => components[0] * 10000,
2 => components[0] * 10000 + components[1] * 100,
3 => components[0] * 10000 + components[1] * 100 + components[2],
_ => panic!("Malformed version"),
}
}
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/tools/compiletest/src/header/tests.rs
Expand Up @@ -122,9 +122,8 @@ fn llvm_version() {
config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);

// FIXME.
// config.llvm_version = Some("10.0.0-rust".to_owned());
// assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
config.llvm_version = Some("10.0.0-rust".to_owned());
assert!(!parse_rs(&config, "// min-llvm-version 9.0").ignore);
}

#[test]
Expand Down

0 comments on commit 7a14f9e

Please sign in to comment.