Skip to content

Commit 7a14f9e

Browse files
committed
Fix LLVM version handling in compiletest
Convert version string to integer before comparing. Otherwise we get into trouble with double digit versions ;)
1 parent 841558d commit 7a14f9e

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl EarlyProps {
191191
return true;
192192
}
193193
if let Some(ref actual_version) = config.llvm_version {
194+
let actual_version = version_to_int(actual_version);
194195
if line.starts_with("min-llvm-version") {
195196
let min_version = line
196197
.trim_end()
@@ -199,7 +200,7 @@ impl EarlyProps {
199200
.expect("Malformed llvm version directive");
200201
// Ignore if actual version is smaller the minimum required
201202
// version
202-
&actual_version[..] < min_version
203+
actual_version < version_to_int(min_version)
203204
} else if line.starts_with("min-system-llvm-version") {
204205
let min_version = line
205206
.trim_end()
@@ -208,7 +209,7 @@ impl EarlyProps {
208209
.expect("Malformed llvm version directive");
209210
// Ignore if using system LLVM and actual version
210211
// is smaller the minimum required version
211-
config.system_llvm && &actual_version[..] < min_version
212+
config.system_llvm && actual_version < version_to_int(min_version)
212213
} else if line.starts_with("ignore-llvm-version") {
213214
// Syntax is: "ignore-llvm-version <version1> [- <version2>]"
214215
let range_components = line
@@ -219,15 +220,15 @@ impl EarlyProps {
219220
.take(3) // 3 or more = invalid, so take at most 3.
220221
.collect::<Vec<&str>>();
221222
match range_components.len() {
222-
1 => &actual_version[..] == range_components[0],
223+
1 => actual_version == version_to_int(range_components[0]),
223224
2 => {
224-
let v_min = range_components[0];
225-
let v_max = range_components[1];
225+
let v_min = version_to_int(range_components[0]);
226+
let v_max = version_to_int(range_components[1]);
226227
if v_max < v_min {
227228
panic!("Malformed LLVM version range: max < min")
228229
}
229230
// Ignore if version lies inside of range.
230-
&actual_version[..] >= v_min && &actual_version[..] <= v_max
231+
actual_version >= v_min && actual_version <= v_max
231232
}
232233
_ => panic!("Malformed LLVM version directive"),
233234
}
@@ -238,6 +239,20 @@ impl EarlyProps {
238239
false
239240
}
240241
}
242+
243+
fn version_to_int(version: &str) -> u32 {
244+
let version_without_suffix = version.split('-').next().unwrap();
245+
let components: Vec<u32> = version_without_suffix
246+
.split('.')
247+
.map(|s| s.parse().expect("Malformed version component"))
248+
.collect();
249+
match components.len() {
250+
1 => components[0] * 10000,
251+
2 => components[0] * 10000 + components[1] * 100,
252+
3 => components[0] * 10000 + components[1] * 100 + components[2],
253+
_ => panic!("Malformed version"),
254+
}
255+
}
241256
}
242257
}
243258

src/tools/compiletest/src/header/tests.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,8 @@ fn llvm_version() {
122122
config.llvm_version = Some("9.3.1-rust-1.43.0-dev".to_owned());
123123
assert!(!parse_rs(&config, "// min-llvm-version 9.2").ignore);
124124

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

130129
#[test]

0 commit comments

Comments
 (0)