Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/doc/rustc-dev-guide/src/tests/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ See [Pretty-printer](compiletest.md#pretty-printer-tests).
The following directives affect how certain command-line tools are invoked, in
test suites that use those tools:

- `skip-filecheck` avoids running LLVM's `FileCheck` tool in tests that would normally run it to check output.
- Used by codegen tests, assembly tests, and mir-opt tests.
- `filecheck-flags` adds extra flags when running LLVM's `FileCheck` tool.
- Used by [codegen tests](compiletest.md#codegen-tests),
[assembly tests](compiletest.md#assembly-tests), and
Expand Down
5 changes: 4 additions & 1 deletion src/tools/compiletest/src/directives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ pub(crate) struct TestProps {
/// Extra flags to pass to `llvm-cov` when producing coverage reports.
/// Only used by the "coverage-run" test mode.
pub(crate) llvm_cov_flags: Vec<String>,
/// Don't run LLVM's `filecheck` tool to check compiler output,
/// in tests that would normally run it.
pub(crate) skip_filecheck: bool,
/// Extra flags to pass to LLVM's `filecheck` tool, in tests that use it.
pub(crate) filecheck_flags: Vec<String>,
/// Don't automatically insert any `--check-cfg` args
Expand Down Expand Up @@ -308,6 +311,7 @@ impl TestProps {
mir_unit_test: None,
remap_src_base: false,
llvm_cov_flags: vec![],
skip_filecheck: false,
filecheck_flags: vec![],
no_auto_check_cfg: false,
add_minicore: false,
Expand Down Expand Up @@ -438,7 +442,6 @@ impl TestProps {
let check_no_run = |s| match (config.mode, s) {
(TestMode::Ui, _) => (),
(TestMode::Crashes, _) => (),
(TestMode::Codegen, "build-pass") => (),
(mode, _) => panic!("`{s}` directive is not supported in `{mode}` tests"),
};
let pass_mode = if config.parse_name_directive(ln, "check-pass") {
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/directives/directive_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
"rustc-env",
"rustfix-only-machine-applicable",
"should-fail",
"skip-filecheck",
"stderr-per-bitwidth",
"test-mir-pass",
"unique-doc-out-dir",
Expand Down
14 changes: 13 additions & 1 deletion src/tools/compiletest/src/directives/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::sync::{Arc, LazyLock};

use crate::common::Config;
use crate::common::{Config, TestMode};
use crate::directives::{
DirectiveLine, NormalizeKind, NormalizeRule, TestProps, parse_and_update_aux,
parse_edition_range, split_flags,
Expand Down Expand Up @@ -312,6 +312,18 @@ fn make_directive_handlers_map() -> HashMap<&'static str, Handler> {
props.llvm_cov_flags.extend(split_flags(&flags));
}
}),
handler("skip-filecheck", |config, ln, props| {
let directive_name = ln.name;
// FIXME(Zalathar): Someday we should add unified support for declaring
// and checking which modes are supported by each directive.
if !matches!(config.mode, TestMode::Assembly | TestMode::Codegen | TestMode::MirOpt) {
panic!(
"directive `//@ {directive_name}` is not supported by this test suite (mode: {mode:?})",
mode = config.mode
);
}
config.set_name_directive(ln, directive_name, &mut props.skip_filecheck);
}),
handler(FILECHECK_FLAGS, |config, ln, props| {
if let Some(flags) = config.parse_name_value_directive(ln, FILECHECK_FLAGS) {
props.filecheck_flags.extend(split_flags(&flags));
Expand Down
8 changes: 5 additions & 3 deletions src/tools/compiletest/src/runtest/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ impl TestCx<'_> {
self.fatal_proc_rec("compilation failed!", &proc_res);
}

let proc_res = self.verify_with_filecheck(&output_path);
if !proc_res.status.success() {
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
if !self.props.skip_filecheck {
let proc_res = self.verify_with_filecheck(&output_path);
if !proc_res.status.success() {
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
}
}
}

Expand Down
13 changes: 6 additions & 7 deletions src/tools/compiletest/src/runtest/codegen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{PassMode, TestCx};
use super::TestCx;

impl TestCx<'_> {
pub(super) fn run_codegen_test(&self) {
Expand All @@ -11,12 +11,11 @@ impl TestCx<'_> {
self.fatal_proc_rec("compilation failed!", &proc_res);
}

if let Some(PassMode::Build) = self.pass_mode() {
return;
}
let proc_res = self.verify_with_filecheck(&output_path);
if !proc_res.status.success() {
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
if !self.props.skip_filecheck {
let proc_res = self.verify_with_filecheck(&output_path);
if !proc_res.status.success() {
self.fatal_proc_rec("verification with 'FileCheck' failed", &proc_res);
}
}
}
}
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/runtest/mir_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TestCx<'_> {
let test_dir = self.testpaths.file.parent().unwrap();
let test_crate = self.testpaths.file.file_stem().unwrap().replace('-', "_");

let MiroptTest { run_filecheck, suffix, files, passes: _ } = test_info;
let MiroptTest { suffix, files, passes: _ } = test_info;

if self.config.bless {
for e in glob(&format!("{}/{}.*{}.mir", test_dir, test_crate, suffix)).unwrap() {
Expand Down Expand Up @@ -89,7 +89,7 @@ impl TestCx<'_> {
}
}

if run_filecheck {
if !self.props.skip_filecheck {
let output_path = self.output_base_name().with_extension("mir");
let proc_res = self.verify_with_filecheck(&output_path);
if !proc_res.status.success() {
Expand Down
14 changes: 6 additions & 8 deletions src/tools/miropt-test-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub struct MiroptTestFile {
}

pub struct MiroptTest {
pub run_filecheck: bool,
pub suffix: String,
pub files: Vec<MiroptTestFile>,
/// Vec of passes under test to be dumped
Expand Down Expand Up @@ -57,13 +56,15 @@ pub fn files_for_miropt_test(
let test_crate = testfile.file_stem().unwrap().to_str().unwrap().replace('-', "_");

let suffix = output_file_suffix(testfile, bit_width, panic_strategy);
let mut run_filecheck = true;
let mut passes = Vec::new();

for l in test_file_contents.lines() {
// FIXME(Zalathar): Remove this `skip-filecheck` migration error in 2027,
// or perhaps earlier if it seems no longer useful.
if l.starts_with("// skip-filecheck") {
run_filecheck = false;
continue;
panic!(
"error: `// skip-filecheck` is no longer supported, use `//@ skip-filecheck` instead."
);
}
if l.starts_with("// EMIT_MIR ") {
let test_name = l.trim_start_matches("// EMIT_MIR ").trim();
Expand Down Expand Up @@ -128,10 +129,7 @@ pub fn files_for_miropt_test(

out.push(MiroptTestFile { expected_file, from_file, to_file });
}
if !run_filecheck && l.trim_start().starts_with("// CHECK") {
panic!("error: test contains filecheck directive but is marked `skip-filecheck`");
}
}

MiroptTest { run_filecheck, suffix, files: out, passes }
MiroptTest { suffix, files: out, passes }
}
3 changes: 2 additions & 1 deletion tests/codegen-llvm/scalable-vectors/tuple-intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ build-pass
// FIXME: The FileCheck directives in this test are unchecked and probably broken.
//@ skip-filecheck
//@ only-aarch64
#![crate_type = "lib"]
#![allow(incomplete_features, internal_features)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen-llvm/simd/simd-wide-sum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//@ edition: 2021
//@ only-x86_64
//@ [mir-opt3]compile-flags: -Zmir-opt-level=3
//@ [mir-opt3]build-pass
//@ [mir-opt3] skip-filecheck

// mir-opt3 is a regression test for https://github.com/rust-lang/rust/issues/98016

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The LLVM FileCheck tool is used to verify the contents of output MIR against `CH
present in the test file. This works on the runtime MIR, generated by `--emit=mir`, and not
on the output of a individual passes.

Use `// skip-filecheck` to prevent FileCheck from running.
Use `//@ skip-filecheck` to prevent FileCheck from running.

To check MIR for function `foo`, start with a `// CHECK-LABEL fn foo(` directive.

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/address_of.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
// EMIT_MIR address_of.address_of_reborrow.SimplifyCfg-initial.after.mir

fn address_of_reborrow() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/async_closure_fake_read_for_by_move.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ edition:2021
// skip-filecheck
//@ skip-filecheck

enum Foo {
Bar,
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/async_closure_shims.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ edition:2021
// skip-filecheck
//@ skip-filecheck

#![allow(unused)]

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/async_drop_live_dead.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ edition:2024
// skip-filecheck
//@ skip-filecheck
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY

#![feature(async_drop)]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/async_drop_mir_pin.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@edition: 2024
//@ test-mir-pass: MentionedItems
// skip-filecheck
//@ skip-filecheck
#![feature(async_drop)]
#![allow(incomplete_features)]
use std::future::AsyncDrop;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/box_conditional_drop_allocator.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
//@ test-mir-pass: ElaborateDrops
//@ needs-unwind
#![feature(allocator_api)]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/build_correct_coerce.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck

// Validate that we record the target for the `as` coercion as `for<'a> fn(&'a (), &'a ())`,
// and not `for<'a, 'b>(&'a (), &'b ())`. We previously did the latter due to a bug in
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/async_await.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
// This test makes sure that the coroutine MIR pass eliminates all calls to
// `get_context`, and that the MIR argument type for an async fn and all locals
// related to `yield` are `&mut Context`, and its return type is `Poll`.
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/coroutine.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
//@ edition:2024
//@ compile-flags: -Zmir-opt-level=0 -C panic=abort

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/aggregate_exprs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/arbitrary_let.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/arrays.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/as_cast.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/assume.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/composite_return.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/operators.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
//@ compile-flags: --crate-type=lib
#![feature(custom_mir, core_intrinsics)]
use std::intrinsics::mir::*;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/projections.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/references.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/simple_assign.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/custom/terminators.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![feature(custom_mir, core_intrinsics)]

extern crate core;
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/enum_cast.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: -Zmir-opt-level=0
// skip-filecheck
//@ skip-filecheck
// EMIT_MIR enum_cast.foo.built.after.mir
// EMIT_MIR enum_cast.bar.built.after.mir
// EMIT_MIR enum_cast.boo.built.after.mir
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/eq_never_type.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: -Zmir-opt-level=0
// skip-filecheck
//@ skip-filecheck
#![feature(never_type)]
#![allow(unreachable_code)]

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/issue_101867.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: -Zmir-opt-level=0
// skip-filecheck
//@ skip-filecheck
// EMIT_MIR issue_101867.main.built.after.mir
fn main() {
let x: Option<u8> = Some(1);
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/issue_110508.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: -Zmir-opt-level=0
// skip-filecheck
//@ skip-filecheck
// EMIT_MIR issue_110508.{impl#0}-BAR.built.after.mir
// EMIT_MIR issue_110508.{impl#0}-SELF_BAR.built.after.mir

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/issue_49232.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//@ compile-flags: -Zmir-opt-level=0
// skip-filecheck
//@ skip-filecheck
// We must mark a variable whose initialization fails due to an
// abort statement as StorageDead.

Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/logical_or_in_conditional.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
//@ compile-flags: -Zmir-opt-level=0 -Z validate-mir
//@ edition: 2024
struct Droppy(u8);
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/loop_match_diverges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
#![allow(incomplete_features)]
#![feature(loop_match)]
#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/match/deref-patterns/string.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
//@ compile-flags: -Z mir-opt-level=0 -C panic=abort

#![feature(deref_patterns)]
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/match/exponential_or.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
// Test that simple or-patterns don't get expanded to exponentially large CFGs

// EMIT_MIR exponential_or.match_tuple.SimplifyCfg-initial.after.mir
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/match/match_false_edges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
fn guard() -> bool {
false
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/building/match/simple_match.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// skip-filecheck
//@ skip-filecheck
// Test that we don't generate unnecessarily large MIR for very simple matches

// EMIT_MIR simple_match.match_bool.built.after.mir
Expand Down
Loading
Loading