cargo-careful: empty libtest harness under cargo-careful fails valgrind

Steps to reproduce:

mkdir /tmp/memory-error && cd /tmp/memory-error
cargo init --lib
cargo +nightly careful test --no-run
valgrind --track-origins=yes target/debug/deps/memory_error-394e695bdd4a1e0f

Valgrind output:

==741342== Memcheck, a memory error detector
==741342== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==741342== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info
==741342== Command: target/debug/deps/memory_error-394e695bdd4a1e0f
==741342== 
==741342== Conditional jump or move depends on uninitialised value(s)
==741342==    at 0x16673A: runtime<u8> (raw.rs:93)
==741342==    by 0x16673A: from_raw_parts<u8> (intrinsics.rs:2220)
==741342==    by 0x16673A: deref<u8, alloc::alloc::Global> (mod.rs:2533)
==741342==    by 0x16673A: index (string.rs:2185)
==741342==    by 0x16673A: eq (string.rs:2185)
==741342==    by 0x16673A: eq (lib.rs:626)
==741342==    by 0x16673A: eq<getopts::Name, getopts::Name> (lib.rs:933)
==741342==    by 0x16673A: {closure#0} (lib.rs:933)
==741342==    by 0x16673A: position<getopts::Opt, getopts::find_opt::{closure_env#0}> (macros.rs:295)
==741342==    by 0x16673A: getopts::find_opt (lib.rs:933)
==741342==    by 0x166084: getopts::Matches::opt_vals (lib.rs:797)
==741342==    by 0x16634A: getopts::Matches::opt_present (lib.rs:813)
==741342==    by 0x13C548: test::cli::parse_opts (cli.rs:207)
==741342==    by 0x15A0FC: test::test_main (lib.rs:95)
==741342==    by 0x15B0D1: test::test_main_static (lib.rs:131)
==741342==    by 0x123112: memory_error::main (lib.rs:1)
==741342==    by 0x12307A: core::ops::function::FnOnce::call_once (function.rs:251)
==741342==    by 0x12315D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:122)
==741342==    by 0x122CE0: std::rt::lang_start::{{closure}} (rt.rs:166)
==741342==    by 0x18AA53: call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (function.rs:286)
==741342==    by 0x18AA53: do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panicking.rs:464)
==741342==    by 0x18AA53: try<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (panicking.rs:428)
==741342==    by 0x18AA53: catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panic.rs:137)
==741342==    by 0x18AA53: {closure#2} (rt.rs:148)
==741342==    by 0x18AA53: do_call<std::rt::lang_start_internal::{closure_env#2}, isize> (panicking.rs:464)
==741342==    by 0x18AA53: try<isize, std::rt::lang_start_internal::{closure_env#2}> (panicking.rs:428)
==741342==    by 0x18AA53: catch_unwind<std::rt::lang_start_internal::{closure_env#2}, isize> (panic.rs:137)
==741342==    by 0x18AA53: std::rt::lang_start_internal (rt.rs:148)
==741342==    by 0x122CB9: std::rt::lang_start (rt.rs:165)
==741342==  Uninitialised value was created by a stack allocation
==741342==    at 0x165FE7: getopts::Matches::opt_vals (lib.rs:796)
==741342== 
==741342== Conditional jump or move depends on uninitialised value(s)
==741342==    at 0x16680E: runtime<u8> (raw.rs:93)
==741342==    by 0x16680E: from_raw_parts<u8> (intrinsics.rs:2220)
==741342==    by 0x16680E: deref<u8, alloc::alloc::Global> (mod.rs:2533)
==741342==    by 0x16680E: index (string.rs:2185)
==741342==    by 0x16680E: eq (string.rs:2185)
==741342==    by 0x16680E: eq (lib.rs:626)
==741342==    by 0x16680E: eq<getopts::Name, getopts::Name> (lib.rs:940)
==741342==    by 0x16680E: {closure#1} (lib.rs:940)
==741342==    by 0x16680E: any<getopts::Opt, getopts::find_opt::{closure_env#1}> (macros.rs:242)
==741342==    by 0x16680E: getopts::find_opt (lib.rs:940)
==741342==    by 0x166084: getopts::Matches::opt_vals (lib.rs:797)
==741342==    by 0x16634A: getopts::Matches::opt_present (lib.rs:813)
==741342==    by 0x13C548: test::cli::parse_opts (cli.rs:207)
==741342==    by 0x15A0FC: test::test_main (lib.rs:95)
==741342==    by 0x15B0D1: test::test_main_static (lib.rs:131)
==741342==    by 0x123112: memory_error::main (lib.rs:1)
==741342==    by 0x12307A: core::ops::function::FnOnce::call_once (function.rs:251)
==741342==    by 0x12315D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:122)
==741342==    by 0x122CE0: std::rt::lang_start::{{closure}} (rt.rs:166)
==741342==    by 0x18AA53: call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (function.rs:286)
==741342==    by 0x18AA53: do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panicking.rs:464)
==741342==    by 0x18AA53: try<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (panicking.rs:428)
==741342==    by 0x18AA53: catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panic.rs:137)
==741342==    by 0x18AA53: {closure#2} (rt.rs:148)
==741342==    by 0x18AA53: do_call<std::rt::lang_start_internal::{closure_env#2}, isize> (panicking.rs:464)
==741342==    by 0x18AA53: try<isize, std::rt::lang_start_internal::{closure_env#2}> (panicking.rs:428)
==741342==    by 0x18AA53: catch_unwind<std::rt::lang_start_internal::{closure_env#2}, isize> (panic.rs:137)
==741342==    by 0x18AA53: std::rt::lang_start_internal (rt.rs:148)
==741342==    by 0x122CB9: std::rt::lang_start (rt.rs:165)
==741342==  Uninitialised value was created by a stack allocation
==741342==    at 0x165FE7: getopts::Matches::opt_vals (lib.rs:796)
==741342== 
==741342== Conditional jump or move depends on uninitialised value(s)
==741342==    at 0x16673A: runtime<u8> (raw.rs:93)
==741342==    by 0x16673A: from_raw_parts<u8> (intrinsics.rs:2220)
==741342==    by 0x16673A: deref<u8, alloc::alloc::Global> (mod.rs:2533)
==741342==    by 0x16673A: index (string.rs:2185)
==741342==    by 0x16673A: eq (string.rs:2185)
==741342==    by 0x16673A: eq (lib.rs:626)
==741342==    by 0x16673A: eq<getopts::Name, getopts::Name> (lib.rs:933)
==741342==    by 0x16673A: {closure#0} (lib.rs:933)
==741342==    by 0x16673A: position<getopts::Opt, getopts::find_opt::{closure_env#0}> (macros.rs:295)
==741342==    by 0x16673A: getopts::find_opt (lib.rs:933)
==741342==    by 0x166084: getopts::Matches::opt_vals (lib.rs:797)
==741342==    by 0x166643: getopts::Matches::opt_str (lib.rs:804)
==741342==    by 0x13C764: get_allow_unstable (cli.rs:471)
==741342==    by 0x13C764: parse_opts_impl (cli.rs:252)
==741342==    by 0x13C764: test::cli::parse_opts (cli.rs:214)
==741342==    by 0x15A0FC: test::test_main (lib.rs:95)
==741342==    by 0x15B0D1: test::test_main_static (lib.rs:131)
==741342==    by 0x123112: memory_error::main (lib.rs:1)
==741342==    by 0x12307A: core::ops::function::FnOnce::call_once (function.rs:251)
==741342==    by 0x12315D: std::sys_common::backtrace::__rust_begin_short_backtrace (backtrace.rs:122)
==741342==    by 0x122CE0: std::rt::lang_start::{{closure}} (rt.rs:166)
==741342==    by 0x18AA53: call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (function.rs:286)
==741342==    by 0x18AA53: do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panicking.rs:464)
==741342==    by 0x18AA53: try<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> (panicking.rs:428)
==741342==    by 0x18AA53: catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> (panic.rs:137)
==741342==    by 0x18AA53: {closure#2} (rt.rs:148)
==741342==    by 0x18AA53: do_call<std::rt::lang_start_internal::{closure_env#2}, isize> (panicking.rs:464)
==741342==    by 0x18AA53: try<isize, std::rt::lang_start_internal::{closure_env#2}> (panicking.rs:428)
==741342==    by 0x18AA53: catch_unwind<std::rt::lang_start_internal::{closure_env#2}, isize> (panic.rs:137)
==741342==    by 0x18AA53: std::rt::lang_start_internal (rt.rs:148)
==741342==    by 0x122CB9: std::rt::lang_start (rt.rs:165)
==741342==  Uninitialised value was created by a stack allocation
==741342==    at 0x165FE7: getopts::Matches::opt_vals (lib.rs:796)
==741342== 

running 1 test
test tests::it_works ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.12s

==741342== 
==741342== HEAP SUMMARY:
==741342==     in use at exit: 0 bytes in 0 blocks
==741342==   total heap usage: 479 allocs, 479 frees, 53,506 bytes allocated
==741342== 
==741342== All heap blocks were freed -- no leaks are possible
==741342== 
==741342== For lists of detected and suppressed errors, rerun with: -s
==741342== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

I’ve tried to debug this with gdb and adding prints, but it disappears if you look at it too closely so gave up after a bit of trying

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 17 (7 by maintainers)

Most upvoted comments

Assuming the line numbers are correct, it points at this debug assertion

https://github.com/rust-lang/rust/blob/075084f772abbc53263fc946c047a01e0dd65f80/library/core/src/slice/raw.rs#L93-L96

None of this can really be uninit though, given that Miri has been all over that code, so my assumption is that LLVM did something odd to the assembly that confuses valgrind, or some such thing. That’s way outside of what I can debug, sorry.