Skip to content

Commit 15edf4f

Browse files
committed
compiletest: Force directive to be first complete word in header comment.
Refactored some related code to take advantage of this change.
1 parent fa62a0c commit 15edf4f

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

src/test/codegen/fastcall-inreg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
// ignore-tce
3838
// ignore-thumb
3939
// ignore-thumbeb
40-
// ignore-x86_64 no-ignore-x86
40+
// ignore-x86_64
4141
// ignore-xcore
4242
// ignore-nvptx
4343
// ignore-nvptx64

src/test/run-pass/i128-ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// ignore-windows
1616

1717
// Ignore 32 bit targets:
18-
// ignore-x86, ignore-arm
18+
// ignore-x86
19+
// ignore-arm
1920

2021
// ignore-emscripten
2122

src/tools/compiletest/src/header.rs

+31-28
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,12 @@ impl EarlyProps {
8080
return false;
8181
}
8282

83-
if !line.contains("ignore-gdb-version") &&
84-
config.parse_name_directive(line, "ignore-gdb") {
83+
if config.parse_name_directive(line, "ignore-gdb") {
8584
return true;
8685
}
8786

8887
if let Some(actual_version) = config.gdb_version {
89-
if line.contains("min-gdb-version") {
88+
if line.starts_with("min-gdb-version") {
9089
let (start_ver, end_ver) = extract_gdb_version_range(line);
9190

9291
if start_ver != end_ver {
@@ -95,7 +94,7 @@ impl EarlyProps {
9594
// Ignore if actual version is smaller the minimum required
9695
// version
9796
actual_version < start_ver
98-
} else if line.contains("ignore-gdb-version") {
97+
} else if line.starts_with("ignore-gdb-version") {
9998
let (min_version, max_version) = extract_gdb_version_range(line);
10099

101100
if max_version < min_version {
@@ -119,20 +118,21 @@ impl EarlyProps {
119118
fn extract_gdb_version_range(line: &str) -> (u32, u32) {
120119
const ERROR_MESSAGE: &'static str = "Malformed GDB version directive";
121120

122-
let range_components = line.split(' ')
123-
.flat_map(|word| word.split('-'))
124-
.filter(|word| word.len() > 0)
125-
.skip_while(|word| extract_gdb_version(word).is_none())
126-
.collect::<Vec<&str>>();
121+
let range_components = line.split(&[' ', '-'][..])
122+
.filter(|word| !word.is_empty())
123+
.map(extract_gdb_version)
124+
.skip_while(Option::is_none)
125+
.take(3) // 3 or more = invalid, so take at most 3.
126+
.collect::<Vec<Option<u32>>>();
127127

128128
match range_components.len() {
129129
1 => {
130-
let v = extract_gdb_version(range_components[0]).unwrap();
130+
let v = range_components[0].unwrap();
131131
(v, v)
132132
}
133133
2 => {
134-
let v_min = extract_gdb_version(range_components[0]).unwrap();
135-
let v_max = extract_gdb_version(range_components[1]).expect(ERROR_MESSAGE);
134+
let v_min = range_components[0].unwrap();
135+
let v_max = range_components[1].expect(ERROR_MESSAGE);
136136
(v_min, v_max)
137137
}
138138
_ => panic!(ERROR_MESSAGE),
@@ -149,10 +149,10 @@ impl EarlyProps {
149149
}
150150

151151
if let Some(ref actual_version) = config.lldb_version {
152-
if line.contains("min-lldb-version") {
153-
let min_version = line.trim()
154-
.split(' ')
155-
.last()
152+
if line.starts_with("min-lldb-version") {
153+
let min_version = line.trim_right()
154+
.rsplit(' ')
155+
.next()
156156
.expect("Malformed lldb version directive");
157157
// Ignore if actual version is smaller the minimum required
158158
// version
@@ -167,10 +167,10 @@ impl EarlyProps {
167167

168168
fn ignore_llvm(config: &Config, line: &str) -> bool {
169169
if let Some(ref actual_version) = config.llvm_version {
170-
if line.contains("min-llvm-version") {
171-
let min_version = line.trim()
172-
.split(' ')
173-
.last()
170+
if line.starts_with("min-llvm-version") {
171+
let min_version = line.trim_right()
172+
.rsplit(' ')
173+
.next()
174174
.expect("Malformed llvm version directive");
175175
// Ignore if actual version is smaller the minimum required
176176
// version
@@ -413,14 +413,14 @@ fn iter_header(testfile: &Path, cfg: Option<&str>, it: &mut FnMut(&str)) {
413413
None => false,
414414
};
415415
if matches {
416-
it(&ln[close_brace + 1..]);
416+
it(ln[(close_brace + 1) ..].trim_left());
417417
}
418418
} else {
419419
panic!("malformed condition directive: expected `//[foo]`, found `{}`",
420420
ln)
421421
}
422422
} else if ln.starts_with("//") {
423-
it(&ln[2..]);
423+
it(ln[2..].trim_left());
424424
}
425425
}
426426
return;
@@ -528,15 +528,18 @@ impl Config {
528528
}
529529

530530
fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
531-
// This 'no-' rule is a quick hack to allow pretty-expanded and
532-
// no-pretty-expanded to coexist
533-
line.contains(directive) && !line.contains(&("no-".to_owned() + directive))
531+
// Ensure the directive is a whole word. Do not match "ignore-x86" when
532+
// the line says "ignore-x86_64".
533+
line.starts_with(directive) && match line.as_bytes().get(directive.len()) {
534+
None | Some(&b' ') | Some(&b':') => true,
535+
_ => false
536+
}
534537
}
535538

536539
pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
537-
let keycolon = format!("{}:", directive);
538-
if let Some(colon) = line.find(&keycolon) {
539-
let value = line[(colon + keycolon.len())..line.len()].to_owned();
540+
let colon = directive.len();
541+
if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
542+
let value = line[(colon + 1) ..].to_owned();
540543
debug!("{}: {}", directive, value);
541544
Some(expand_variables(value, self))
542545
} else {

0 commit comments

Comments
 (0)