1use std::collections::HashSet;
2use std::env;
3use std::fs::File;
4use std::io::BufReader;
5use std::io::prelude::*;
6use std::path::{Path, PathBuf};
7use std::process::Command;
8
9use semver::Version;
10use tracing::*;
11
12use crate::common::{Config, Debugger, FailMode, Mode, PassMode};
13use crate::debuggers::{extract_cdb_version, extract_gdb_version};
14use crate::header::auxiliary::{AuxProps, parse_and_update_aux};
15use crate::header::needs::CachedNeedsConditions;
16use crate::util::static_regex;
17
18pub(crate) mod auxiliary;
19mod cfg;
20mod needs;
21#[cfg(test)]
22mod tests;
23
24pub struct HeadersCache {
25 needs: CachedNeedsConditions,
26}
27
28impl HeadersCache {
29 pub fn load(config: &Config) -> Self {
30 Self { needs: CachedNeedsConditions::load(config) }
31 }
32}
33
34#[derive(Default)]
37pub struct EarlyProps {
38 pub(crate) aux: AuxProps,
42 pub revisions: Vec<String>,
43}
44
45impl EarlyProps {
46 pub fn from_file(config: &Config, testfile: &Path) -> Self {
47 let file = File::open(testfile).expect("open test file to parse earlyprops");
48 Self::from_reader(config, testfile, file)
49 }
50
51 pub fn from_reader<R: Read>(config: &Config, testfile: &Path, rdr: R) -> Self {
52 let mut props = EarlyProps::default();
53 let mut poisoned = false;
54 iter_header(
55 config.mode,
56 &config.suite,
57 &mut poisoned,
58 testfile,
59 rdr,
60 &mut |DirectiveLine { raw_directive: ln, .. }| {
61 parse_and_update_aux(config, ln, &mut props.aux);
62 config.parse_and_update_revisions(testfile, ln, &mut props.revisions);
63 },
64 );
65
66 if poisoned {
67 eprintln!("errors encountered during EarlyProps parsing: {}", testfile.display());
68 panic!("errors encountered during EarlyProps parsing");
69 }
70
71 props
72 }
73}
74
75#[derive(Clone, Debug)]
76pub struct TestProps {
77 pub error_patterns: Vec<String>,
79 pub regex_error_patterns: Vec<String>,
81 pub compile_flags: Vec<String>,
83 pub run_flags: Vec<String>,
85 pub doc_flags: Vec<String>,
87 pub pp_exact: Option<PathBuf>,
90 pub(crate) aux: AuxProps,
92 pub rustc_env: Vec<(String, String)>,
94 pub unset_rustc_env: Vec<String>,
97 pub exec_env: Vec<(String, String)>,
99 pub unset_exec_env: Vec<String>,
102 pub build_aux_docs: bool,
104 pub unique_doc_out_dir: bool,
107 pub force_host: bool,
109 pub check_stdout: bool,
111 pub check_run_results: bool,
113 pub dont_check_compiler_stdout: bool,
115 pub dont_check_compiler_stderr: bool,
117 pub no_prefer_dynamic: bool,
123 pub pretty_mode: String,
125 pub pretty_compare_only: bool,
127 pub forbid_output: Vec<String>,
129 pub revisions: Vec<String>,
131 pub incremental_dir: Option<PathBuf>,
136 pub incremental: bool,
151 pub known_bug: bool,
157 pass_mode: Option<PassMode>,
159 ignore_pass: bool,
161 pub fail_mode: Option<FailMode>,
163 pub check_test_line_numbers_match: bool,
165 pub normalize_stdout: Vec<(String, String)>,
167 pub normalize_stderr: Vec<(String, String)>,
168 pub failure_status: Option<i32>,
169 pub dont_check_failure_status: bool,
171 pub run_rustfix: bool,
174 pub rustfix_only_machine_applicable: bool,
176 pub assembly_output: Option<String>,
177 pub should_ice: bool,
179 pub stderr_per_bitwidth: bool,
181 pub mir_unit_test: Option<String>,
183 pub remap_src_base: bool,
186 pub llvm_cov_flags: Vec<String>,
189 pub filecheck_flags: Vec<String>,
191 pub no_auto_check_cfg: bool,
193 pub has_enzyme: bool,
195 pub add_core_stubs: bool,
198}
199
200mod directives {
201 pub const ERROR_PATTERN: &'static str = "error-pattern";
202 pub const REGEX_ERROR_PATTERN: &'static str = "regex-error-pattern";
203 pub const COMPILE_FLAGS: &'static str = "compile-flags";
204 pub const RUN_FLAGS: &'static str = "run-flags";
205 pub const DOC_FLAGS: &'static str = "doc-flags";
206 pub const SHOULD_ICE: &'static str = "should-ice";
207 pub const BUILD_AUX_DOCS: &'static str = "build-aux-docs";
208 pub const UNIQUE_DOC_OUT_DIR: &'static str = "unique-doc-out-dir";
209 pub const FORCE_HOST: &'static str = "force-host";
210 pub const CHECK_STDOUT: &'static str = "check-stdout";
211 pub const CHECK_RUN_RESULTS: &'static str = "check-run-results";
212 pub const DONT_CHECK_COMPILER_STDOUT: &'static str = "dont-check-compiler-stdout";
213 pub const DONT_CHECK_COMPILER_STDERR: &'static str = "dont-check-compiler-stderr";
214 pub const NO_PREFER_DYNAMIC: &'static str = "no-prefer-dynamic";
215 pub const PRETTY_MODE: &'static str = "pretty-mode";
216 pub const PRETTY_COMPARE_ONLY: &'static str = "pretty-compare-only";
217 pub const AUX_BIN: &'static str = "aux-bin";
218 pub const AUX_BUILD: &'static str = "aux-build";
219 pub const AUX_CRATE: &'static str = "aux-crate";
220 pub const PROC_MACRO: &'static str = "proc-macro";
221 pub const AUX_CODEGEN_BACKEND: &'static str = "aux-codegen-backend";
222 pub const EXEC_ENV: &'static str = "exec-env";
223 pub const RUSTC_ENV: &'static str = "rustc-env";
224 pub const UNSET_EXEC_ENV: &'static str = "unset-exec-env";
225 pub const UNSET_RUSTC_ENV: &'static str = "unset-rustc-env";
226 pub const FORBID_OUTPUT: &'static str = "forbid-output";
227 pub const CHECK_TEST_LINE_NUMBERS_MATCH: &'static str = "check-test-line-numbers-match";
228 pub const IGNORE_PASS: &'static str = "ignore-pass";
229 pub const FAILURE_STATUS: &'static str = "failure-status";
230 pub const DONT_CHECK_FAILURE_STATUS: &'static str = "dont-check-failure-status";
231 pub const RUN_RUSTFIX: &'static str = "run-rustfix";
232 pub const RUSTFIX_ONLY_MACHINE_APPLICABLE: &'static str = "rustfix-only-machine-applicable";
233 pub const ASSEMBLY_OUTPUT: &'static str = "assembly-output";
234 pub const STDERR_PER_BITWIDTH: &'static str = "stderr-per-bitwidth";
235 pub const INCREMENTAL: &'static str = "incremental";
236 pub const KNOWN_BUG: &'static str = "known-bug";
237 pub const TEST_MIR_PASS: &'static str = "test-mir-pass";
238 pub const REMAP_SRC_BASE: &'static str = "remap-src-base";
239 pub const LLVM_COV_FLAGS: &'static str = "llvm-cov-flags";
240 pub const FILECHECK_FLAGS: &'static str = "filecheck-flags";
241 pub const NO_AUTO_CHECK_CFG: &'static str = "no-auto-check-cfg";
242 pub const ADD_CORE_STUBS: &'static str = "add-core-stubs";
243 pub const INCORRECT_COMPILER_FLAGS: &'static str = "compiler-flags";
245}
246
247impl TestProps {
248 pub fn new() -> Self {
249 TestProps {
250 error_patterns: vec![],
251 regex_error_patterns: vec![],
252 compile_flags: vec![],
253 run_flags: vec![],
254 doc_flags: vec![],
255 pp_exact: None,
256 aux: Default::default(),
257 revisions: vec![],
258 rustc_env: vec![
259 ("RUSTC_ICE".to_string(), "0".to_string()),
260 ("RUST_BACKTRACE".to_string(), "short".to_string()),
261 ],
262 unset_rustc_env: vec![("RUSTC_LOG_COLOR".to_string())],
263 exec_env: vec![],
264 unset_exec_env: vec![],
265 build_aux_docs: false,
266 unique_doc_out_dir: false,
267 force_host: false,
268 check_stdout: false,
269 check_run_results: false,
270 dont_check_compiler_stdout: false,
271 dont_check_compiler_stderr: false,
272 no_prefer_dynamic: false,
273 pretty_mode: "normal".to_string(),
274 pretty_compare_only: false,
275 forbid_output: vec![],
276 incremental_dir: None,
277 incremental: false,
278 known_bug: false,
279 pass_mode: None,
280 fail_mode: None,
281 ignore_pass: false,
282 check_test_line_numbers_match: false,
283 normalize_stdout: vec![],
284 normalize_stderr: vec![],
285 failure_status: None,
286 dont_check_failure_status: false,
287 run_rustfix: false,
288 rustfix_only_machine_applicable: false,
289 assembly_output: None,
290 should_ice: false,
291 stderr_per_bitwidth: false,
292 mir_unit_test: None,
293 remap_src_base: false,
294 llvm_cov_flags: vec![],
295 filecheck_flags: vec![],
296 no_auto_check_cfg: false,
297 has_enzyme: false,
298 add_core_stubs: false,
299 }
300 }
301
302 pub fn from_aux_file(&self, testfile: &Path, revision: Option<&str>, config: &Config) -> Self {
303 let mut props = TestProps::new();
304
305 props.incremental_dir = self.incremental_dir.clone();
307 props.ignore_pass = true;
308 props.load_from(testfile, revision, config);
309
310 props
311 }
312
313 pub fn from_file(testfile: &Path, revision: Option<&str>, config: &Config) -> Self {
314 let mut props = TestProps::new();
315 props.load_from(testfile, revision, config);
316 props.exec_env.push(("RUSTC".to_string(), config.rustc_path.display().to_string()));
317
318 match (props.pass_mode, props.fail_mode) {
319 (None, None) if config.mode == Mode::Ui => props.fail_mode = Some(FailMode::Check),
320 (Some(_), Some(_)) => panic!("cannot use a *-fail and *-pass mode together"),
321 _ => {}
322 }
323
324 props
325 }
326
327 fn load_from(&mut self, testfile: &Path, test_revision: Option<&str>, config: &Config) {
332 let mut has_edition = false;
333 if !testfile.is_dir() {
334 let file = File::open(testfile).unwrap();
335
336 let mut poisoned = false;
337
338 iter_header(
339 config.mode,
340 &config.suite,
341 &mut poisoned,
342 testfile,
343 file,
344 &mut |directive @ DirectiveLine { raw_directive: ln, .. }| {
345 if !directive.applies_to_test_revision(test_revision) {
346 return;
347 }
348
349 use directives::*;
350
351 config.push_name_value_directive(
352 ln,
353 ERROR_PATTERN,
354 &mut self.error_patterns,
355 |r| r,
356 );
357 config.push_name_value_directive(
358 ln,
359 REGEX_ERROR_PATTERN,
360 &mut self.regex_error_patterns,
361 |r| r,
362 );
363
364 config.push_name_value_directive(ln, DOC_FLAGS, &mut self.doc_flags, |r| r);
365
366 fn split_flags(flags: &str) -> Vec<String> {
367 flags
370 .split('\'')
371 .enumerate()
372 .flat_map(|(i, f)| {
373 if i % 2 == 1 { vec![f] } else { f.split_whitespace().collect() }
374 })
375 .map(move |s| s.to_owned())
376 .collect::<Vec<_>>()
377 }
378
379 if let Some(flags) = config.parse_name_value_directive(ln, COMPILE_FLAGS) {
380 self.compile_flags.extend(split_flags(&flags));
381 }
382 if config.parse_name_value_directive(ln, INCORRECT_COMPILER_FLAGS).is_some() {
383 panic!("`compiler-flags` directive should be spelled `compile-flags`");
384 }
385
386 if let Some(edition) = config.parse_edition(ln) {
387 self.compile_flags.push(format!("--edition={}", edition.trim()));
388 has_edition = true;
389 }
390
391 config.parse_and_update_revisions(testfile, ln, &mut self.revisions);
392
393 if let Some(flags) = config.parse_name_value_directive(ln, RUN_FLAGS) {
394 self.run_flags.extend(split_flags(&flags));
395 }
396
397 if self.pp_exact.is_none() {
398 self.pp_exact = config.parse_pp_exact(ln, testfile);
399 }
400
401 config.set_name_directive(ln, SHOULD_ICE, &mut self.should_ice);
402 config.set_name_directive(ln, BUILD_AUX_DOCS, &mut self.build_aux_docs);
403 config.set_name_directive(ln, UNIQUE_DOC_OUT_DIR, &mut self.unique_doc_out_dir);
404
405 config.set_name_directive(ln, FORCE_HOST, &mut self.force_host);
406 config.set_name_directive(ln, CHECK_STDOUT, &mut self.check_stdout);
407 config.set_name_directive(ln, CHECK_RUN_RESULTS, &mut self.check_run_results);
408 config.set_name_directive(
409 ln,
410 DONT_CHECK_COMPILER_STDOUT,
411 &mut self.dont_check_compiler_stdout,
412 );
413 config.set_name_directive(
414 ln,
415 DONT_CHECK_COMPILER_STDERR,
416 &mut self.dont_check_compiler_stderr,
417 );
418 config.set_name_directive(ln, NO_PREFER_DYNAMIC, &mut self.no_prefer_dynamic);
419
420 if let Some(m) = config.parse_name_value_directive(ln, PRETTY_MODE) {
421 self.pretty_mode = m;
422 }
423
424 config.set_name_directive(
425 ln,
426 PRETTY_COMPARE_ONLY,
427 &mut self.pretty_compare_only,
428 );
429
430 parse_and_update_aux(config, ln, &mut self.aux);
432
433 config.push_name_value_directive(
434 ln,
435 EXEC_ENV,
436 &mut self.exec_env,
437 Config::parse_env,
438 );
439 config.push_name_value_directive(
440 ln,
441 UNSET_EXEC_ENV,
442 &mut self.unset_exec_env,
443 |r| r,
444 );
445 config.push_name_value_directive(
446 ln,
447 RUSTC_ENV,
448 &mut self.rustc_env,
449 Config::parse_env,
450 );
451 config.push_name_value_directive(
452 ln,
453 UNSET_RUSTC_ENV,
454 &mut self.unset_rustc_env,
455 |r| r,
456 );
457 config.push_name_value_directive(
458 ln,
459 FORBID_OUTPUT,
460 &mut self.forbid_output,
461 |r| r,
462 );
463 config.set_name_directive(
464 ln,
465 CHECK_TEST_LINE_NUMBERS_MATCH,
466 &mut self.check_test_line_numbers_match,
467 );
468
469 self.update_pass_mode(ln, test_revision, config);
470 self.update_fail_mode(ln, config);
471
472 config.set_name_directive(ln, IGNORE_PASS, &mut self.ignore_pass);
473
474 if let Some(NormalizeRule { kind, regex, replacement }) =
475 config.parse_custom_normalization(ln)
476 {
477 let rule_tuple = (regex, replacement);
478 match kind {
479 NormalizeKind::Stdout => self.normalize_stdout.push(rule_tuple),
480 NormalizeKind::Stderr => self.normalize_stderr.push(rule_tuple),
481 NormalizeKind::Stderr32bit => {
482 if config.target_cfg().pointer_width == 32 {
483 self.normalize_stderr.push(rule_tuple);
484 }
485 }
486 NormalizeKind::Stderr64bit => {
487 if config.target_cfg().pointer_width == 64 {
488 self.normalize_stderr.push(rule_tuple);
489 }
490 }
491 }
492 }
493
494 if let Some(code) = config
495 .parse_name_value_directive(ln, FAILURE_STATUS)
496 .and_then(|code| code.trim().parse::<i32>().ok())
497 {
498 self.failure_status = Some(code);
499 }
500
501 config.set_name_directive(
502 ln,
503 DONT_CHECK_FAILURE_STATUS,
504 &mut self.dont_check_failure_status,
505 );
506
507 config.set_name_directive(ln, RUN_RUSTFIX, &mut self.run_rustfix);
508 config.set_name_directive(
509 ln,
510 RUSTFIX_ONLY_MACHINE_APPLICABLE,
511 &mut self.rustfix_only_machine_applicable,
512 );
513 config.set_name_value_directive(
514 ln,
515 ASSEMBLY_OUTPUT,
516 &mut self.assembly_output,
517 |r| r.trim().to_string(),
518 );
519 config.set_name_directive(
520 ln,
521 STDERR_PER_BITWIDTH,
522 &mut self.stderr_per_bitwidth,
523 );
524 config.set_name_directive(ln, INCREMENTAL, &mut self.incremental);
525
526 if let Some(known_bug) = config.parse_name_value_directive(ln, KNOWN_BUG) {
529 let known_bug = known_bug.trim();
530 if known_bug == "unknown"
531 || known_bug.split(',').all(|issue_ref| {
532 issue_ref
533 .trim()
534 .split_once('#')
535 .filter(|(_, number)| {
536 number.chars().all(|digit| digit.is_numeric())
537 })
538 .is_some()
539 })
540 {
541 self.known_bug = true;
542 } else {
543 panic!(
544 "Invalid known-bug value: {known_bug}\nIt requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`."
545 );
546 }
547 } else if config.parse_name_directive(ln, KNOWN_BUG) {
548 panic!(
549 "Invalid known-bug attribute, requires comma-separated issue references (`#000` or `chalk#000`) or `known-bug: unknown`."
550 );
551 }
552
553 config.set_name_value_directive(
554 ln,
555 TEST_MIR_PASS,
556 &mut self.mir_unit_test,
557 |s| s.trim().to_string(),
558 );
559 config.set_name_directive(ln, REMAP_SRC_BASE, &mut self.remap_src_base);
560
561 if let Some(flags) = config.parse_name_value_directive(ln, LLVM_COV_FLAGS) {
562 self.llvm_cov_flags.extend(split_flags(&flags));
563 }
564
565 if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
566 self.filecheck_flags.extend(split_flags(&flags));
567 }
568
569 config.set_name_directive(ln, NO_AUTO_CHECK_CFG, &mut self.no_auto_check_cfg);
570
571 self.update_add_core_stubs(ln, config);
572 },
573 );
574
575 if poisoned {
576 eprintln!("errors encountered during TestProps parsing: {}", testfile.display());
577 panic!("errors encountered during TestProps parsing");
578 }
579 }
580
581 if self.should_ice {
582 self.failure_status = Some(101);
583 }
584
585 if config.mode == Mode::Incremental {
586 self.incremental = true;
587 }
588
589 if config.mode == Mode::Crashes {
590 self.rustc_env = vec![
594 ("RUST_BACKTRACE".to_string(), "0".to_string()),
595 ("RUSTC_ICE".to_string(), "0".to_string()),
596 ];
597 }
598
599 for key in &["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
600 if let Ok(val) = env::var(key) {
601 if !self.exec_env.iter().any(|&(ref x, _)| x == key) {
602 self.exec_env.push(((*key).to_owned(), val))
603 }
604 }
605 }
606
607 if let (Some(edition), false) = (&config.edition, has_edition) {
608 self.compile_flags.push(format!("--edition={}", edition));
609 }
610 }
611
612 fn update_fail_mode(&mut self, ln: &str, config: &Config) {
613 let check_ui = |mode: &str| {
614 if config.mode != Mode::Ui && config.mode != Mode::Crashes {
616 panic!("`{}-fail` header is only supported in UI tests", mode);
617 }
618 };
619 if config.mode == Mode::Ui && config.parse_name_directive(ln, "compile-fail") {
620 panic!("`compile-fail` header is useless in UI tests");
621 }
622 let fail_mode = if config.parse_name_directive(ln, "check-fail") {
623 check_ui("check");
624 Some(FailMode::Check)
625 } else if config.parse_name_directive(ln, "build-fail") {
626 check_ui("build");
627 Some(FailMode::Build)
628 } else if config.parse_name_directive(ln, "run-fail") {
629 check_ui("run");
630 Some(FailMode::Run)
631 } else {
632 None
633 };
634 match (self.fail_mode, fail_mode) {
635 (None, Some(_)) => self.fail_mode = fail_mode,
636 (Some(_), Some(_)) => panic!("multiple `*-fail` headers in a single test"),
637 (_, None) => {}
638 }
639 }
640
641 fn update_pass_mode(&mut self, ln: &str, revision: Option<&str>, config: &Config) {
642 let check_no_run = |s| match (config.mode, s) {
643 (Mode::Ui, _) => (),
644 (Mode::Crashes, _) => (),
645 (Mode::Codegen, "build-pass") => (),
646 (Mode::Incremental, _) => {
647 if revision.is_some() && !self.revisions.iter().all(|r| r.starts_with("cfail")) {
648 panic!("`{s}` header is only supported in `cfail` incremental tests")
649 }
650 }
651 (mode, _) => panic!("`{s}` header is not supported in `{mode}` tests"),
652 };
653 let pass_mode = if config.parse_name_directive(ln, "check-pass") {
654 check_no_run("check-pass");
655 Some(PassMode::Check)
656 } else if config.parse_name_directive(ln, "build-pass") {
657 check_no_run("build-pass");
658 Some(PassMode::Build)
659 } else if config.parse_name_directive(ln, "run-pass") {
660 check_no_run("run-pass");
661 Some(PassMode::Run)
662 } else {
663 None
664 };
665 match (self.pass_mode, pass_mode) {
666 (None, Some(_)) => self.pass_mode = pass_mode,
667 (Some(_), Some(_)) => panic!("multiple `*-pass` headers in a single test"),
668 (_, None) => {}
669 }
670 }
671
672 pub fn pass_mode(&self, config: &Config) -> Option<PassMode> {
673 if !self.ignore_pass && self.fail_mode.is_none() {
674 if let mode @ Some(_) = config.force_pass_mode {
675 return mode;
676 }
677 }
678 self.pass_mode
679 }
680
681 pub fn local_pass_mode(&self) -> Option<PassMode> {
683 self.pass_mode
684 }
685
686 pub fn update_add_core_stubs(&mut self, ln: &str, config: &Config) {
687 let add_core_stubs = config.parse_name_directive(ln, directives::ADD_CORE_STUBS);
688 if add_core_stubs {
689 if !matches!(config.mode, Mode::Ui | Mode::Codegen | Mode::Assembly) {
690 panic!(
691 "`add-core-stubs` is currently only supported for ui, codegen and assembly test modes"
692 );
693 }
694
695 if self.local_pass_mode().is_some_and(|pm| pm == PassMode::Run) {
698 panic!("`add-core-stubs` cannot be used to run the test binary");
701 }
702
703 self.add_core_stubs = add_core_stubs;
704 }
705 }
706}
707
708fn line_directive<'line>(
711 line_number: usize,
712 original_line: &'line str,
713) -> Option<DirectiveLine<'line>> {
714 let after_comment =
716 original_line.trim_start().strip_prefix(COMPILETEST_DIRECTIVE_PREFIX)?.trim_start();
717
718 let revision;
719 let raw_directive;
720
721 if let Some(after_open_bracket) = after_comment.strip_prefix('[') {
722 let Some((line_revision, after_close_bracket)) = after_open_bracket.split_once(']') else {
724 panic!(
725 "malformed condition directive: expected `{COMPILETEST_DIRECTIVE_PREFIX}[foo]`, found `{original_line}`"
726 )
727 };
728
729 revision = Some(line_revision);
730 raw_directive = after_close_bracket.trim_start();
731 } else {
732 revision = None;
733 raw_directive = after_comment;
734 };
735
736 Some(DirectiveLine { line_number, revision, raw_directive })
737}
738
739include!("directive-list.rs");
744
745const KNOWN_HTMLDOCCK_DIRECTIVE_NAMES: &[&str] = &[
746 "count",
747 "!count",
748 "files",
749 "!files",
750 "has",
751 "!has",
752 "has-dir",
753 "!has-dir",
754 "hasraw",
755 "!hasraw",
756 "matches",
757 "!matches",
758 "matchesraw",
759 "!matchesraw",
760 "snapshot",
761 "!snapshot",
762];
763
764const KNOWN_JSONDOCCK_DIRECTIVE_NAMES: &[&str] =
765 &["count", "!count", "has", "!has", "is", "!is", "ismany", "!ismany", "set", "!set"];
766
767struct DirectiveLine<'ln> {
781 line_number: usize,
782 revision: Option<&'ln str>,
786 raw_directive: &'ln str,
792}
793
794impl<'ln> DirectiveLine<'ln> {
795 fn applies_to_test_revision(&self, test_revision: Option<&str>) -> bool {
796 self.revision.is_none() || self.revision == test_revision
797 }
798}
799
800pub(crate) struct CheckDirectiveResult<'ln> {
801 is_known_directive: bool,
802 trailing_directive: Option<&'ln str>,
803}
804
805pub(crate) fn check_directive<'a>(
806 directive_ln: &'a str,
807 mode: Mode,
808 original_line: &str,
809) -> CheckDirectiveResult<'a> {
810 let (directive_name, post) = directive_ln.split_once([':', ' ']).unwrap_or((directive_ln, ""));
811
812 let trailing = post.trim().split_once(' ').map(|(pre, _)| pre).unwrap_or(post);
813 let is_known = |s: &str| {
814 KNOWN_DIRECTIVE_NAMES.contains(&s)
815 || match mode {
816 Mode::Rustdoc | Mode::RustdocJson => {
817 original_line.starts_with("//@")
818 && match mode {
819 Mode::Rustdoc => KNOWN_HTMLDOCCK_DIRECTIVE_NAMES,
820 Mode::RustdocJson => KNOWN_JSONDOCCK_DIRECTIVE_NAMES,
821 _ => unreachable!(),
822 }
823 .contains(&s)
824 }
825 _ => false,
826 }
827 };
828 let trailing_directive = {
829 matches!(directive_ln.get(directive_name.len()..), Some(s) if s.starts_with(' '))
831 && is_known(trailing)
833 }
834 .then_some(trailing);
835
836 CheckDirectiveResult { is_known_directive: is_known(&directive_name), trailing_directive }
837}
838
839const COMPILETEST_DIRECTIVE_PREFIX: &str = "//@";
840
841fn iter_header(
842 mode: Mode,
843 _suite: &str,
844 poisoned: &mut bool,
845 testfile: &Path,
846 rdr: impl Read,
847 it: &mut dyn FnMut(DirectiveLine<'_>),
848) {
849 if testfile.is_dir() {
850 return;
851 }
852
853 if mode == Mode::CoverageRun {
858 let extra_directives: &[&str] = &[
859 "needs-profiler-runtime",
860 "ignore-cross-compile",
864 ];
865 for raw_directive in extra_directives {
867 it(DirectiveLine { line_number: 0, revision: None, raw_directive });
868 }
869 }
870
871 let mut rdr = BufReader::with_capacity(1024, rdr);
872 let mut ln = String::new();
873 let mut line_number = 0;
874
875 loop {
876 line_number += 1;
877 ln.clear();
878 if rdr.read_line(&mut ln).unwrap() == 0 {
879 break;
880 }
881 let ln = ln.trim();
882
883 let Some(directive_line) = line_directive(line_number, ln) else {
884 continue;
885 };
886
887 if testfile.extension().map(|e| e == "rs").unwrap_or(false) {
889 let CheckDirectiveResult { is_known_directive, trailing_directive } =
890 check_directive(directive_line.raw_directive, mode, ln);
891
892 if !is_known_directive {
893 *poisoned = true;
894
895 eprintln!(
896 "error: detected unknown compiletest test directive `{}` in {}:{}",
897 directive_line.raw_directive,
898 testfile.display(),
899 line_number,
900 );
901
902 return;
903 }
904
905 if let Some(trailing_directive) = &trailing_directive {
906 *poisoned = true;
907
908 eprintln!(
909 "error: detected trailing compiletest test directive `{}` in {}:{}\n \
910 help: put the trailing directive in it's own line: `//@ {}`",
911 trailing_directive,
912 testfile.display(),
913 line_number,
914 trailing_directive,
915 );
916
917 return;
918 }
919 }
920
921 it(directive_line);
922 }
923}
924
925impl Config {
926 fn parse_and_update_revisions(&self, testfile: &Path, line: &str, existing: &mut Vec<String>) {
927 const FORBIDDEN_REVISION_NAMES: [&str; 2] = [
928 "true", "false",
932 ];
933
934 const FILECHECK_FORBIDDEN_REVISION_NAMES: [&str; 9] =
935 ["CHECK", "COM", "NEXT", "SAME", "EMPTY", "NOT", "COUNT", "DAG", "LABEL"];
936
937 if let Some(raw) = self.parse_name_value_directive(line, "revisions") {
938 if self.mode == Mode::RunMake {
939 panic!("`run-make` tests do not support revisions: {}", testfile.display());
940 }
941
942 let mut duplicates: HashSet<_> = existing.iter().cloned().collect();
943 for revision in raw.split_whitespace() {
944 if !duplicates.insert(revision.to_string()) {
945 panic!(
946 "duplicate revision: `{}` in line `{}`: {}",
947 revision,
948 raw,
949 testfile.display()
950 );
951 }
952
953 if FORBIDDEN_REVISION_NAMES.contains(&revision) {
954 panic!(
955 "revision name `{revision}` is not permitted: `{}` in line `{}`: {}",
956 revision,
957 raw,
958 testfile.display()
959 );
960 }
961
962 if matches!(self.mode, Mode::Assembly | Mode::Codegen | Mode::MirOpt)
963 && FILECHECK_FORBIDDEN_REVISION_NAMES.contains(&revision)
964 {
965 panic!(
966 "revision name `{revision}` is not permitted in a test suite that uses \
967 `FileCheck` annotations as it is confusing when used as custom `FileCheck` \
968 prefix: `{revision}` in line `{}`: {}",
969 raw,
970 testfile.display()
971 );
972 }
973
974 existing.push(revision.to_string());
975 }
976 }
977 }
978
979 fn parse_env(nv: String) -> (String, String) {
980 let mut strs: Vec<String> = nv.splitn(2, '=').map(str::to_owned).collect();
982
983 match strs.len() {
984 1 => (strs.pop().unwrap(), String::new()),
985 2 => {
986 let end = strs.pop().unwrap();
987 (strs.pop().unwrap(), end)
988 }
989 n => panic!("Expected 1 or 2 strings, not {}", n),
990 }
991 }
992
993 fn parse_pp_exact(&self, line: &str, testfile: &Path) -> Option<PathBuf> {
994 if let Some(s) = self.parse_name_value_directive(line, "pp-exact") {
995 Some(PathBuf::from(&s))
996 } else if self.parse_name_directive(line, "pp-exact") {
997 testfile.file_name().map(PathBuf::from)
998 } else {
999 None
1000 }
1001 }
1002
1003 fn parse_custom_normalization(&self, raw_directive: &str) -> Option<NormalizeRule> {
1004 let (directive_name, raw_value) = raw_directive.split_once(':')?;
1007
1008 let kind = match directive_name {
1009 "normalize-stdout" => NormalizeKind::Stdout,
1010 "normalize-stderr" => NormalizeKind::Stderr,
1011 "normalize-stderr-32bit" => NormalizeKind::Stderr32bit,
1012 "normalize-stderr-64bit" => NormalizeKind::Stderr64bit,
1013 _ => return None,
1014 };
1015
1016 let Some((regex, replacement)) = parse_normalize_rule(raw_value) else {
1017 panic!(
1018 "couldn't parse custom normalization rule: `{raw_directive}`\n\
1019 help: expected syntax is: `{directive_name}: \"REGEX\" -> \"REPLACEMENT\"`"
1020 );
1021 };
1022 Some(NormalizeRule { kind, regex, replacement })
1023 }
1024
1025 fn parse_name_directive(&self, line: &str, directive: &str) -> bool {
1026 line.starts_with(directive)
1029 && matches!(line.as_bytes().get(directive.len()), None | Some(&b' ') | Some(&b':'))
1030 }
1031
1032 fn parse_negative_name_directive(&self, line: &str, directive: &str) -> bool {
1033 line.starts_with("no-") && self.parse_name_directive(&line[3..], directive)
1034 }
1035
1036 pub fn parse_name_value_directive(&self, line: &str, directive: &str) -> Option<String> {
1037 let colon = directive.len();
1038 if line.starts_with(directive) && line.as_bytes().get(colon) == Some(&b':') {
1039 let value = line[(colon + 1)..].to_owned();
1040 debug!("{}: {}", directive, value);
1041 Some(expand_variables(value, self))
1042 } else {
1043 None
1044 }
1045 }
1046
1047 fn parse_edition(&self, line: &str) -> Option<String> {
1048 self.parse_name_value_directive(line, "edition")
1049 }
1050
1051 fn set_name_directive(&self, line: &str, directive: &str, value: &mut bool) {
1052 match value {
1053 true => {
1054 if self.parse_negative_name_directive(line, directive) {
1055 *value = false;
1056 }
1057 }
1058 false => {
1059 if self.parse_name_directive(line, directive) {
1060 *value = true;
1061 }
1062 }
1063 }
1064 }
1065
1066 fn set_name_value_directive<T>(
1067 &self,
1068 line: &str,
1069 directive: &str,
1070 value: &mut Option<T>,
1071 parse: impl FnOnce(String) -> T,
1072 ) {
1073 if value.is_none() {
1074 *value = self.parse_name_value_directive(line, directive).map(parse);
1075 }
1076 }
1077
1078 fn push_name_value_directive<T>(
1079 &self,
1080 line: &str,
1081 directive: &str,
1082 values: &mut Vec<T>,
1083 parse: impl FnOnce(String) -> T,
1084 ) {
1085 if let Some(value) = self.parse_name_value_directive(line, directive).map(parse) {
1086 values.push(value);
1087 }
1088 }
1089}
1090
1091fn expand_variables(mut value: String, config: &Config) -> String {
1093 const CWD: &str = "{{cwd}}";
1094 const SRC_BASE: &str = "{{src-base}}";
1095 const TEST_SUITE_BUILD_BASE: &str = "{{build-base}}";
1096 const RUST_SRC_BASE: &str = "{{rust-src-base}}";
1097 const SYSROOT_BASE: &str = "{{sysroot-base}}";
1098 const TARGET_LINKER: &str = "{{target-linker}}";
1099 const TARGET: &str = "{{target}}";
1100
1101 if value.contains(CWD) {
1102 let cwd = env::current_dir().unwrap();
1103 value = value.replace(CWD, &cwd.to_string_lossy());
1104 }
1105
1106 if value.contains(SRC_BASE) {
1107 value = value.replace(SRC_BASE, &config.src_test_suite_root.to_str().unwrap());
1108 }
1109
1110 if value.contains(TEST_SUITE_BUILD_BASE) {
1111 value =
1112 value.replace(TEST_SUITE_BUILD_BASE, &config.build_test_suite_root.to_str().unwrap());
1113 }
1114
1115 if value.contains(SYSROOT_BASE) {
1116 value = value.replace(SYSROOT_BASE, &config.sysroot_base.to_str().unwrap());
1117 }
1118
1119 if value.contains(TARGET_LINKER) {
1120 value = value.replace(TARGET_LINKER, config.target_linker.as_deref().unwrap_or(""));
1121 }
1122
1123 if value.contains(TARGET) {
1124 value = value.replace(TARGET, &config.target);
1125 }
1126
1127 if value.contains(RUST_SRC_BASE) {
1128 let src_base = config.sysroot_base.join("lib/rustlib/src/rust");
1129 src_base.try_exists().expect(&*format!("{} should exists", src_base.display()));
1130 let src_base = src_base.read_link().unwrap_or(src_base);
1131 value = value.replace(RUST_SRC_BASE, &src_base.to_string_lossy());
1132 }
1133
1134 value
1135}
1136
1137struct NormalizeRule {
1138 kind: NormalizeKind,
1139 regex: String,
1140 replacement: String,
1141}
1142
1143enum NormalizeKind {
1144 Stdout,
1145 Stderr,
1146 Stderr32bit,
1147 Stderr64bit,
1148}
1149
1150fn parse_normalize_rule(raw_value: &str) -> Option<(String, String)> {
1156 let captures = static_regex!(
1158 r#"(?x) # (verbose mode regex)
1159 ^
1160 \s* # (leading whitespace)
1161 "(?<regex>[^"]*)" # "REGEX"
1162 \s+->\s+ # ->
1163 "(?<replacement>[^"]*)" # "REPLACEMENT"
1164 $
1165 "#
1166 )
1167 .captures(raw_value)?;
1168 let regex = captures["regex"].to_owned();
1169 let replacement = captures["replacement"].to_owned();
1170 let replacement = replacement.replace("\\n", "\n");
1174 Some((regex, replacement))
1175}
1176
1177pub fn extract_llvm_version(version: &str) -> Version {
1187 let version = version.trim();
1190 let uninterested = |c: char| !c.is_ascii_digit() && c != '.';
1191 let version_without_suffix = match version.split_once(uninterested) {
1192 Some((prefix, _suffix)) => prefix,
1193 None => version,
1194 };
1195
1196 let components: Vec<u64> = version_without_suffix
1197 .split('.')
1198 .map(|s| s.parse().expect("llvm version component should consist of only digits"))
1199 .collect();
1200
1201 match &components[..] {
1202 [major] => Version::new(*major, 0, 0),
1203 [major, minor] => Version::new(*major, *minor, 0),
1204 [major, minor, patch] => Version::new(*major, *minor, *patch),
1205 _ => panic!("malformed llvm version string, expected only 1-3 components: {version}"),
1206 }
1207}
1208
1209pub fn extract_llvm_version_from_binary(binary_path: &str) -> Option<Version> {
1210 let output = Command::new(binary_path).arg("--version").output().ok()?;
1211 if !output.status.success() {
1212 return None;
1213 }
1214 let version = String::from_utf8(output.stdout).ok()?;
1215 for line in version.lines() {
1216 if let Some(version) = line.split("LLVM version ").nth(1) {
1217 return Some(extract_llvm_version(version));
1218 }
1219 }
1220 None
1221}
1222
1223pub fn llvm_has_libzstd(config: &Config) -> bool {
1227 fn is_zstd_in_config(llvm_bin_dir: &Path) -> Option<()> {
1235 let llvm_config_path = llvm_bin_dir.join("llvm-config");
1236 let output = Command::new(llvm_config_path).arg("--system-libs").output().ok()?;
1237 assert!(output.status.success(), "running llvm-config --system-libs failed");
1238
1239 let libs = String::from_utf8(output.stdout).ok()?;
1240 for lib in libs.split_whitespace() {
1241 if lib.ends_with("libzstd.a") && Path::new(lib).exists() {
1242 return Some(());
1243 }
1244 }
1245
1246 None
1247 }
1248
1249 #[cfg(unix)]
1259 fn is_lld_built_with_zstd(llvm_bin_dir: &Path) -> Option<()> {
1260 let lld_path = llvm_bin_dir.join("lld");
1261 if lld_path.exists() {
1262 let lld_symlink_path = llvm_bin_dir.join("ld.lld");
1265 if !lld_symlink_path.exists() {
1266 std::os::unix::fs::symlink(lld_path, &lld_symlink_path).ok()?;
1267 }
1268
1269 let output = Command::new(&lld_symlink_path)
1272 .arg("--compress-debug-sections=zstd")
1273 .output()
1274 .ok()?;
1275 assert!(!output.status.success());
1276
1277 let stderr = String::from_utf8(output.stderr).ok()?;
1280 let zstd_available = !stderr.contains("LLVM was not built with LLVM_ENABLE_ZSTD");
1281
1282 std::fs::remove_file(lld_symlink_path).ok()?;
1285
1286 if zstd_available {
1287 return Some(());
1288 }
1289 }
1290
1291 None
1292 }
1293
1294 #[cfg(not(unix))]
1295 fn is_lld_built_with_zstd(_llvm_bin_dir: &Path) -> Option<()> {
1296 None
1297 }
1298
1299 if let Some(llvm_bin_dir) = &config.llvm_bin_dir {
1300 if is_zstd_in_config(llvm_bin_dir).is_some() {
1302 return true;
1303 }
1304
1305 if config.target == "x86_64-unknown-linux-gnu"
1313 && config.host == config.target
1314 && is_lld_built_with_zstd(llvm_bin_dir).is_some()
1315 {
1316 return true;
1317 }
1318 }
1319
1320 false
1322}
1323
1324fn extract_version_range<'a, F, VersionTy: Clone>(
1330 line: &'a str,
1331 parse: F,
1332) -> Option<(VersionTy, VersionTy)>
1333where
1334 F: Fn(&'a str) -> Option<VersionTy>,
1335{
1336 let mut splits = line.splitn(2, "- ").map(str::trim);
1337 let min = splits.next().unwrap();
1338 if min.ends_with('-') {
1339 return None;
1340 }
1341
1342 let max = splits.next();
1343
1344 if min.is_empty() {
1345 return None;
1346 }
1347
1348 let min = parse(min)?;
1349 let max = match max {
1350 Some("") => return None,
1351 Some(max) => parse(max)?,
1352 _ => min.clone(),
1353 };
1354
1355 Some((min, max))
1356}
1357
1358pub fn make_test_description<R: Read>(
1359 config: &Config,
1360 cache: &HeadersCache,
1361 name: test::TestName,
1362 path: &Path,
1363 src: R,
1364 test_revision: Option<&str>,
1365 poisoned: &mut bool,
1366) -> test::TestDesc {
1367 let mut ignore = false;
1368 let mut ignore_message = None;
1369 let mut should_fail = false;
1370
1371 let mut local_poisoned = false;
1372
1373 iter_header(
1375 config.mode,
1376 &config.suite,
1377 &mut local_poisoned,
1378 path,
1379 src,
1380 &mut |directive @ DirectiveLine { line_number, raw_directive: ln, .. }| {
1381 if !directive.applies_to_test_revision(test_revision) {
1382 return;
1383 }
1384
1385 macro_rules! decision {
1386 ($e:expr) => {
1387 match $e {
1388 IgnoreDecision::Ignore { reason } => {
1389 ignore = true;
1390 ignore_message = Some(&*Box::leak(Box::<str>::from(reason)));
1394 }
1395 IgnoreDecision::Error { message } => {
1396 eprintln!("error: {}:{line_number}: {message}", path.display());
1397 *poisoned = true;
1398 return;
1399 }
1400 IgnoreDecision::Continue => {}
1401 }
1402 };
1403 }
1404
1405 decision!(cfg::handle_ignore(config, ln));
1406 decision!(cfg::handle_only(config, ln));
1407 decision!(needs::handle_needs(&cache.needs, config, ln));
1408 decision!(ignore_llvm(config, path, ln));
1409 decision!(ignore_cdb(config, ln));
1410 decision!(ignore_gdb(config, ln));
1411 decision!(ignore_lldb(config, ln));
1412
1413 if config.target == "wasm32-unknown-unknown"
1414 && config.parse_name_directive(ln, directives::CHECK_RUN_RESULTS)
1415 {
1416 decision!(IgnoreDecision::Ignore {
1417 reason: "ignored on WASM as the run results cannot be checked there".into(),
1418 });
1419 }
1420
1421 should_fail |= config.parse_name_directive(ln, "should-fail");
1422 },
1423 );
1424
1425 if local_poisoned {
1426 eprintln!("errors encountered when trying to make test description: {}", path.display());
1427 panic!("errors encountered when trying to make test description");
1428 }
1429
1430 let should_panic = match config.mode {
1434 crate::common::Pretty => test::ShouldPanic::No,
1435 _ if should_fail => test::ShouldPanic::Yes,
1436 _ => test::ShouldPanic::No,
1437 };
1438
1439 test::TestDesc {
1440 name,
1441 ignore,
1442 ignore_message,
1443 source_file: "",
1444 start_line: 0,
1445 start_col: 0,
1446 end_line: 0,
1447 end_col: 0,
1448 should_panic,
1449 compile_fail: false,
1450 no_run: false,
1451 test_type: test::TestType::Unknown,
1452 }
1453}
1454
1455fn ignore_cdb(config: &Config, line: &str) -> IgnoreDecision {
1456 if config.debugger != Some(Debugger::Cdb) {
1457 return IgnoreDecision::Continue;
1458 }
1459
1460 if let Some(actual_version) = config.cdb_version {
1461 if let Some(rest) = line.strip_prefix("min-cdb-version:").map(str::trim) {
1462 let min_version = extract_cdb_version(rest).unwrap_or_else(|| {
1463 panic!("couldn't parse version range: {:?}", rest);
1464 });
1465
1466 if actual_version < min_version {
1469 return IgnoreDecision::Ignore {
1470 reason: format!("ignored when the CDB version is lower than {rest}"),
1471 };
1472 }
1473 }
1474 }
1475 IgnoreDecision::Continue
1476}
1477
1478fn ignore_gdb(config: &Config, line: &str) -> IgnoreDecision {
1479 if config.debugger != Some(Debugger::Gdb) {
1480 return IgnoreDecision::Continue;
1481 }
1482
1483 if let Some(actual_version) = config.gdb_version {
1484 if let Some(rest) = line.strip_prefix("min-gdb-version:").map(str::trim) {
1485 let (start_ver, end_ver) = extract_version_range(rest, extract_gdb_version)
1486 .unwrap_or_else(|| {
1487 panic!("couldn't parse version range: {:?}", rest);
1488 });
1489
1490 if start_ver != end_ver {
1491 panic!("Expected single GDB version")
1492 }
1493 if actual_version < start_ver {
1496 return IgnoreDecision::Ignore {
1497 reason: format!("ignored when the GDB version is lower than {rest}"),
1498 };
1499 }
1500 } else if let Some(rest) = line.strip_prefix("ignore-gdb-version:").map(str::trim) {
1501 let (min_version, max_version) = extract_version_range(rest, extract_gdb_version)
1502 .unwrap_or_else(|| {
1503 panic!("couldn't parse version range: {:?}", rest);
1504 });
1505
1506 if max_version < min_version {
1507 panic!("Malformed GDB version range: max < min")
1508 }
1509
1510 if actual_version >= min_version && actual_version <= max_version {
1511 if min_version == max_version {
1512 return IgnoreDecision::Ignore {
1513 reason: format!("ignored when the GDB version is {rest}"),
1514 };
1515 } else {
1516 return IgnoreDecision::Ignore {
1517 reason: format!("ignored when the GDB version is between {rest}"),
1518 };
1519 }
1520 }
1521 }
1522 }
1523 IgnoreDecision::Continue
1524}
1525
1526fn ignore_lldb(config: &Config, line: &str) -> IgnoreDecision {
1527 if config.debugger != Some(Debugger::Lldb) {
1528 return IgnoreDecision::Continue;
1529 }
1530
1531 if let Some(actual_version) = config.lldb_version {
1532 if let Some(rest) = line.strip_prefix("min-lldb-version:").map(str::trim) {
1533 let min_version = rest.parse().unwrap_or_else(|e| {
1534 panic!("Unexpected format of LLDB version string: {}\n{:?}", rest, e);
1535 });
1536 if actual_version < min_version {
1539 return IgnoreDecision::Ignore {
1540 reason: format!("ignored when the LLDB version is {rest}"),
1541 };
1542 }
1543 }
1544 }
1545 IgnoreDecision::Continue
1546}
1547
1548fn ignore_llvm(config: &Config, path: &Path, line: &str) -> IgnoreDecision {
1549 if let Some(needed_components) =
1550 config.parse_name_value_directive(line, "needs-llvm-components")
1551 {
1552 let components: HashSet<_> = config.llvm_components.split_whitespace().collect();
1553 if let Some(missing_component) = needed_components
1554 .split_whitespace()
1555 .find(|needed_component| !components.contains(needed_component))
1556 {
1557 if env::var_os("COMPILETEST_REQUIRE_ALL_LLVM_COMPONENTS").is_some() {
1558 panic!(
1559 "missing LLVM component {}, and COMPILETEST_REQUIRE_ALL_LLVM_COMPONENTS is set: {}",
1560 missing_component,
1561 path.display()
1562 );
1563 }
1564 return IgnoreDecision::Ignore {
1565 reason: format!("ignored when the {missing_component} LLVM component is missing"),
1566 };
1567 }
1568 }
1569 if let Some(actual_version) = &config.llvm_version {
1570 if let Some(version_string) = config.parse_name_value_directive(line, "min-llvm-version") {
1573 let min_version = extract_llvm_version(&version_string);
1574 if *actual_version < min_version {
1576 return IgnoreDecision::Ignore {
1577 reason: format!(
1578 "ignored when the LLVM version {actual_version} is older than {min_version}"
1579 ),
1580 };
1581 }
1582 } else if let Some(version_string) =
1583 config.parse_name_value_directive(line, "max-llvm-major-version")
1584 {
1585 let max_version = extract_llvm_version(&version_string);
1586 if actual_version.major > max_version.major {
1588 return IgnoreDecision::Ignore {
1589 reason: format!(
1590 "ignored when the LLVM version ({actual_version}) is newer than major\
1591 version {}",
1592 max_version.major
1593 ),
1594 };
1595 }
1596 } else if let Some(version_string) =
1597 config.parse_name_value_directive(line, "min-system-llvm-version")
1598 {
1599 let min_version = extract_llvm_version(&version_string);
1600 if config.system_llvm && *actual_version < min_version {
1603 return IgnoreDecision::Ignore {
1604 reason: format!(
1605 "ignored when the system LLVM version {actual_version} is older than {min_version}"
1606 ),
1607 };
1608 }
1609 } else if let Some(version_range) =
1610 config.parse_name_value_directive(line, "ignore-llvm-version")
1611 {
1612 let (v_min, v_max) =
1614 extract_version_range(&version_range, |s| Some(extract_llvm_version(s)))
1615 .unwrap_or_else(|| {
1616 panic!("couldn't parse version range: \"{version_range}\"");
1617 });
1618 if v_max < v_min {
1619 panic!("malformed LLVM version range where {v_max} < {v_min}")
1620 }
1621 if *actual_version >= v_min && *actual_version <= v_max {
1623 if v_min == v_max {
1624 return IgnoreDecision::Ignore {
1625 reason: format!("ignored when the LLVM version is {actual_version}"),
1626 };
1627 } else {
1628 return IgnoreDecision::Ignore {
1629 reason: format!(
1630 "ignored when the LLVM version is between {v_min} and {v_max}"
1631 ),
1632 };
1633 }
1634 }
1635 } else if let Some(version_string) =
1636 config.parse_name_value_directive(line, "exact-llvm-major-version")
1637 {
1638 let version = extract_llvm_version(&version_string);
1640 if actual_version.major != version.major {
1641 return IgnoreDecision::Ignore {
1642 reason: format!(
1643 "ignored when the actual LLVM major version is {}, but the test only targets major version {}",
1644 actual_version.major, version.major
1645 ),
1646 };
1647 }
1648 }
1649 }
1650 IgnoreDecision::Continue
1651}
1652
1653enum IgnoreDecision {
1654 Ignore { reason: String },
1655 Continue,
1656 Error { message: String },
1657}