Skip to content
Open
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
74 changes: 68 additions & 6 deletions tests/run-make/fmt-write-bloat/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,86 @@
//! present.
//!
//! Some CI jobs try to run faster by disabling debug assertions (through setting
//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of
//! additional `usize` formatting and padding related symbols.
//! `NO_DEBUG_ASSERTIONS=1`). If std debug assertions are disabled, then we can check for the
//! absence of additional `usize` formatting and padding related symbols.
// ignore-tidy-linelength

//@ ignore-cross-compile

use run_make_support::artifact_names::bin_name;
use std::path::Path;

use run_make_support::env::std_debug_assertions_enabled;
use run_make_support::rustc;
use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil};
use run_make_support::symbols::object_contains_any_symbol_substring;
use run_make_support::{bin_name, is_windows_msvc, rfs, rustc};

fn main() {
rustc().input("main.rs").opt().run();
// panic machinery identifiers, these should not appear in the final binary
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
if std_debug_assertions_enabled() {
// if debug assertions are allowed, we need to allow these,
// otherwise, add them to the list of symbols to deny.
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
}
assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms));

let expect_no_panic_symbols = bin_name("expect_no_panic_symbols");
let expect_no_panic_symbols = Path::new(&expect_no_panic_symbols);
rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run();

let expect_panic_symbols = bin_name("expect_panic_symbols");
let expect_panic_symbols = Path::new(&expect_panic_symbols);
rustc().input("main.rs").output(&expect_panic_symbols).run();

if is_windows_msvc() {
// FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output.

let expect_no_filecheck_pattern = r#"
CHECK: main
CHECK-NOT: {{.*}}Display{{.*}}
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
"#;
let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt");
rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern);

let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil()
.arg("dump")
.arg("-publics")
.input(expect_no_panic_symbols.with_extension("pdb"))
.run();
llvm_filecheck()
.patterns(expect_no_filecheck_path)
.stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8())
.run();

// NOTE: on different platforms, they may not go through the same code path. E.g. on
// `i686-msvc`, we do not go through `panic_fmt` (only `panic`). So for the check here we
// only try to match for mangled `core::panicking` module path.
let expect_filecheck_pattern = r#"
CHECK: main
CHECK: {{.*}}core{{.*}}panicking{{.*}}
// _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize...
CHECK: {{.*}}Display{{.*}}
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
"#;
Comment on lines +70 to +76
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: these are by no means pretty, and in the future we almost certainly want our own DIA wrappers in run_make_support or somewhere. But I don't feel like implementing that (at least in this PR), so I'll go with the dumb llvm-pdbutil approach for now.

let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt");
rfs::write(&expect_filecheck_path, expect_filecheck_pattern);

let expect_panic_symbols_pdbutil_dump = llvm_pdbutil()
.arg("dump")
.arg("-publics")
.input(expect_panic_symbols.with_extension("pdb"))
.run();
llvm_filecheck()
.patterns(expect_filecheck_path)
.stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8())
.run();
} else {
// At least the `main` symbol (or `_main`) should be present.
assert!(object_contains_any_symbol_substring(&expect_no_panic_symbols, &["main"]));
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &["main"]));

assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms));
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms));
}
}
Loading