From 7ca4d1f6a155e802b31cfc1f0971f3916aa8e02d Mon Sep 17 00:00:00 2001 From: Zalathar Date: Tue, 29 Jul 2025 10:29:32 +1000 Subject: coverage: Regression test for "function name is empty" bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bug was triggered by a particular usage of the `?` try operator in a proc-macro expansion. Thanks to lqd for the minimization. Co-authored-by: Rémy Rakic --- tests/coverage/try-in-macro.bang.coverage | 44 +++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/coverage/try-in-macro.bang.coverage (limited to 'tests/coverage/try-in-macro.bang.coverage') diff --git a/tests/coverage/try-in-macro.bang.coverage b/tests/coverage/try-in-macro.bang.coverage new file mode 100644 index 00000000000..457a161f3c7 --- /dev/null +++ b/tests/coverage/try-in-macro.bang.coverage @@ -0,0 +1,44 @@ + LL| |//! Regression test for . + LL| |//! + LL| |//! The changes in exposed a + LL| |//! latent bug that would sometimes cause the compiler to emit a covfun record + LL| |//! for a function, but not emit a corresponding PGO symbol name entry, because + LL| |//! the function did not have any physical coverage counters. The `llvm-cov` + LL| |//! tool would then fail to resolve the covfun record's function name hash, + LL| |//! and exit with the cryptic error: + LL| |//! + LL| |//! ```text + LL| |//! malformed instrumentation profile data: function name is empty + LL| |//! ``` + LL| |//! + LL| |//! The bug was then triggered in the wild by the macro-expansion of + LL| |//! `#[derive(arbitrary::Arbitrary)]`. + LL| |//! + LL| |//! This test uses a minimized form of the `Arbitrary` derive macro that was + LL| |//! found to still trigger the original bug. The bug could also be triggered + LL| |//! by a bang proc-macro or an attribute proc-macro. + LL| | + LL| |//@ edition: 2024 + LL| |//@ revisions: attr bang derive + LL| |//@ proc-macro: try_in_macro_helper.rs + LL| | + LL| |trait Arbitrary { + LL| | fn try_size_hint() -> Option; + LL| |} + LL| | + LL| |// Expand via an attribute proc-macro. + LL| |#[cfg_attr(attr, try_in_macro_helper::attr)] + LL| |const _: () = (); + LL| | + LL| |// Expand via a regular bang-style proc-macro. + LL| |#[cfg(bang)] + LL| |try_in_macro_helper::bang!(); + LL| | + LL| |// Expand via a derive proc-macro. + LL| |#[cfg_attr(derive, derive(try_in_macro_helper::Arbitrary))] + LL| |enum MyEnum {} + LL| | + LL| 1|fn main() { + LL| 1| MyEnum::try_size_hint(); + LL| 1|} + -- cgit 1.4.1-3-g733a5