2024-07-24 14:05:58 -04:00
|
|
|
//! Before #78122, writing any `fmt::Arguments` would trigger the inclusion of `usize` formatting
|
|
|
|
|
//! and padding code in the resulting binary, because indexing used in `fmt::write` would generate
|
|
|
|
|
//! code using `panic_bounds_check`, which prints the index and length.
|
|
|
|
|
//!
|
|
|
|
|
//! These bounds checks are not necessary, as `fmt::Arguments` never contains any out-of-bounds
|
|
|
|
|
//! indexes. The test is a `run-make` test, because it needs to check the result after linking. A
|
|
|
|
|
//! codegen or assembly test doesn't check the parts that will be pulled in from `core` by the
|
|
|
|
|
//! linker.
|
|
|
|
|
//!
|
|
|
|
|
//! In this test, we try to check that the `usize` formatting and padding code are not present in
|
|
|
|
|
//! the final binary by checking that panic symbols such as `panic_bounds_check` are **not**
|
|
|
|
|
//! 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.
|
|
|
|
|
|
|
|
|
|
//@ ignore-cross-compile
|
|
|
|
|
|
2025-06-21 11:50:44 -07:00
|
|
|
use run_make_support::artifact_names::bin_name;
|
2025-07-11 20:01:42 +08:00
|
|
|
use run_make_support::env::std_debug_assertions_enabled;
|
2024-07-30 13:33:25 -04:00
|
|
|
use run_make_support::rustc;
|
2025-07-12 21:16:46 +08:00
|
|
|
use run_make_support::symbols::object_contains_any_symbol_substring;
|
2024-07-24 14:05:58 -04:00
|
|
|
|
|
|
|
|
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"];
|
2025-07-11 20:01:42 +08:00
|
|
|
if std_debug_assertions_enabled() {
|
2024-07-24 14:05:58 -04:00
|
|
|
// 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"]);
|
|
|
|
|
}
|
2025-07-12 21:16:46 +08:00
|
|
|
assert!(!object_contains_any_symbol_substring(bin_name("main"), &panic_syms));
|
2024-07-24 14:05:58 -04:00
|
|
|
}
|