Skip to content

Commit 8fcb32a

Browse files
Auto merge of #143669 - jieyouxu:fmt-write-bloat, r=<try>
Make sure `fmt-write-bloat` doesn't vacuously pass on no symbols try-job: aarch64-apple try-job: aarch64-msvc-1 try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1
2 parents 1a3cdd3 + 5cf773c commit 8fcb32a

File tree

1 file changed

+66
-6
lines changed

1 file changed

+66
-6
lines changed

tests/run-make/fmt-write-bloat/rmake.rs

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,84 @@
1212
//! present.
1313
//!
1414
//! Some CI jobs try to run faster by disabling debug assertions (through setting
15-
//! `NO_DEBUG_ASSERTIONS=1`). If debug assertions are disabled, then we can check for the absence of
16-
//! additional `usize` formatting and padding related symbols.
15+
//! `NO_DEBUG_ASSERTIONS=1`). If std debug assertions are disabled, then we can check for the
16+
//! absence of additional `usize` formatting and padding related symbols.
17+
18+
// ignore-tidy-linelength
1719

1820
//@ ignore-cross-compile
1921

20-
use run_make_support::artifact_names::bin_name;
22+
use std::path::Path;
23+
2124
use run_make_support::env::std_debug_assertions_enabled;
22-
use run_make_support::rustc;
25+
use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil};
2326
use run_make_support::symbols::object_contains_any_symbol_substring;
27+
use run_make_support::{is_windows_msvc, rfs, rustc};
2428

2529
fn main() {
26-
rustc().input("main.rs").opt().run();
2730
// panic machinery identifiers, these should not appear in the final binary
2831
let mut panic_syms = vec!["panic_bounds_check", "Debug"];
2932
if std_debug_assertions_enabled() {
3033
// if debug assertions are allowed, we need to allow these,
3134
// otherwise, add them to the list of symbols to deny.
3235
panic_syms.extend_from_slice(&["panicking", "panic_fmt", "pad_integral", "Display"]);
3336
}
34-
assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms));
37+
38+
let expect_no_panic_symbols = Path::new("expect_no_panic_symbols");
39+
rustc().input("main.rs").output(&expect_no_panic_symbols).opt().run();
40+
41+
let expect_panic_symbols = Path::new("expect_panic_symbols");
42+
rustc().input("main.rs").output(&expect_panic_symbols).run();
43+
44+
if is_windows_msvc() {
45+
// FIXME(#143737): use actual DIA wrappers instead of parsing `llvm-pdbutil` textual output.
46+
47+
let expect_no_filecheck_pattern = r#"
48+
CHECK: main
49+
CHECK-NOT: {{.*}}Display{{.*}}
50+
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
51+
"#;
52+
let expect_no_filecheck_path = Path::new("expect_no_panic_symbols_filecheck.txt");
53+
rfs::write(&expect_no_filecheck_path, expect_no_filecheck_pattern);
54+
55+
let expect_no_panic_symbols_pdbutil_dump = llvm_pdbutil()
56+
.arg("dump")
57+
.arg("-publics")
58+
.input(expect_no_panic_symbols.with_extension("pdb"))
59+
.run();
60+
llvm_filecheck()
61+
.patterns(expect_no_filecheck_path)
62+
.stdin_buf(expect_no_panic_symbols_pdbutil_dump.stdout_utf8())
63+
.run();
64+
65+
// NOTE: on different platforms, they may not go through the same code path. E.g. on
66+
// `i686-msvc`, we do not go through `panic_fmt` (only `panic`). So for the check here we
67+
// only try to match for mangled `core::panicking` module path.
68+
let expect_filecheck_pattern = r#"
69+
CHECK: main
70+
CHECK: {{.*}}core{{.*}}panicking{{.*}}
71+
// _ZN4core3fmt3num3imp54_$LT$impl$u20$core..fmt..Display$u20$for$u20$usize...
72+
CHECK: {{.*}}Display{{.*}}
73+
CHECK-NOT: {{.*}}panic_bounds_check{{.*}}
74+
"#;
75+
let expect_filecheck_path = Path::new("expect_panic_symbols_filecheck.txt");
76+
rfs::write(&expect_filecheck_path, expect_filecheck_pattern);
77+
78+
let expect_panic_symbols_pdbutil_dump = llvm_pdbutil()
79+
.arg("dump")
80+
.arg("-publics")
81+
.input(expect_panic_symbols.with_extension("pdb"))
82+
.run();
83+
llvm_filecheck()
84+
.patterns(expect_filecheck_path)
85+
.stdin_buf(expect_panic_symbols_pdbutil_dump.stdout_utf8())
86+
.run();
87+
} else {
88+
// At least the `main` symbol (or `_main`) should be present.
89+
assert!(object_contains_any_symbol_substring(&expect_no_panic_symbols, &["main"]));
90+
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &["main"]));
91+
92+
assert!(!object_contains_any_symbol_substring(&expect_no_panic_symbols, &panic_syms));
93+
assert!(object_contains_any_symbol_substring(&expect_panic_symbols, &panic_syms));
94+
}
3595
}

0 commit comments

Comments
 (0)