Skip to content

Commit 891041f

Browse files
committed
deny usage of FileCheck prefixes as revision names
1 parent c156614 commit 891041f

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/tools/compiletest/src/header.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ fn iter_header(
934934

935935
impl Config {
936936
fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
937+
const FORBIDDEN_REVISION_NAMES: [&str; 9] =
938+
["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
939+
937940
if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
938941
if self.mode == Mode::RunMake {
939942
panic!("`run-make` tests do not support revisions: {}", testfile.display());
@@ -948,6 +951,13 @@ impl Config {
948951
raw,
949952
testfile.display()
950953
);
954+
} else if FORBIDDEN_REVISION_NAMES.contains(&revision.as_str()) {
955+
panic!(
956+
"invalid revision: `{}` in line `{}`: {}",
957+
revision,
958+
raw,
959+
testfile.display()
960+
);
951961
}
952962
existing.push(revision);
953963
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,21 @@ fn test_duplicate_revisions() {
553553
parse_rs(&config, "//@ revisions: rpass1 rpass1");
554554
}
555555

556+
#[test]
557+
fn test_forbidden_revisions() {
558+
let config: Config = cfg().build();
559+
let revisions = ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
560+
for rev in revisions {
561+
let res = std::panic::catch_unwind(|| {
562+
parse_rs(&config, format!("//@ revisions: {rev}").as_str());
563+
});
564+
assert!(res.is_err());
565+
if let Some(msg) = res.unwrap_err().downcast_ref::<String>() {
566+
assert!(msg.contains(format!("invalid revision: `{rev}` in line ` {rev}`").as_str()))
567+
}
568+
}
569+
}
570+
556571
#[test]
557572
fn ignore_arch() {
558573
let archs = [

0 commit comments

Comments
 (0)