Skip to content

Commit 89c50a8

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 d85276b + 9059fc3 commit 89c50a8

File tree

1 file changed

+75
-11
lines changed

1 file changed

+75
-11
lines changed

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

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,91 @@
99
//!
1010
//! In this test, we try to check that the `usize` formatting and padding code are not present in
1111
//! the final binary by checking that panic symbols such as `panic_bounds_check` are **not**
12-
//! present.
13-
//!
14-
//! 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.
12+
//! present when optimizations are enabled.
13+
14+
// ignore-tidy-linelength
1715

1816
//@ ignore-cross-compile
1917

20-
use run_make_support::artifact_names::bin_name;
18+
use std::path::Path;
19+
2120
use run_make_support::env::std_debug_assertions_enabled;
22-
use run_make_support::rustc;
21+
use run_make_support::llvm::{llvm_filecheck, llvm_pdbutil};
2322
use run_make_support::symbols::object_contains_any_symbol_substring;
23+
use run_make_support::{bin_name, is_windows_msvc, rfs, rustc};
2424

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

0 commit comments

Comments
 (0)