@@ -471,12 +471,17 @@ pub struct MiriMachine<'mir, 'tcx> {
471471 pub ( crate ) gc_interval : u32 ,
472472 /// The number of blocks that passed since the last BorTag GC pass.
473473 pub ( crate ) since_gc : u32 ,
474+
474475 /// The number of CPUs to be reported by miri.
475476 pub ( crate ) num_cpus : u32 ,
477+
476478 /// Determines Miri's page size and associated values
477479 pub ( crate ) page_size : u64 ,
478480 pub ( crate ) stack_addr : u64 ,
479481 pub ( crate ) stack_size : u64 ,
482+
483+ /// Whether to collect a backtrace when each allocation is created, just in case it leaks.
484+ pub ( crate ) collect_leak_backtraces : bool ,
480485}
481486
482487impl < ' mir , ' tcx > MiriMachine < ' mir , ' tcx > {
@@ -585,6 +590,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
585590 page_size,
586591 stack_addr,
587592 stack_size,
593+ collect_leak_backtraces : config. collect_leak_backtraces ,
588594 }
589595 }
590596
@@ -732,6 +738,7 @@ impl VisitTags for MiriMachine<'_, '_> {
732738 page_size : _,
733739 stack_addr : _,
734740 stack_size : _,
741+ collect_leak_backtraces : _,
735742 } = self ;
736743
737744 threads. visit_tags ( visit) ;
@@ -975,7 +982,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
975982 // If an allocation is leaked, we want to report a backtrace to indicate where it was
976983 // allocated. We don't need to record a backtrace for allocations which are allowed to
977984 // leak.
978- let backtrace = if kind. may_leak ( ) { None } else { Some ( ecx. generate_stacktrace ( ) ) } ;
985+ let backtrace = if kind. may_leak ( ) || !ecx. machine . collect_leak_backtraces {
986+ None
987+ } else {
988+ Some ( ecx. generate_stacktrace ( ) )
989+ } ;
979990
980991 let alloc: Allocation < Provenance , Self :: AllocExtra > = alloc. adjust_from_tcx (
981992 & ecx. tcx ,
0 commit comments