@@ -471,12 +471,17 @@ pub struct MiriMachine<'mir, 'tcx> {
471
471
pub ( crate ) gc_interval : u32 ,
472
472
/// The number of blocks that passed since the last BorTag GC pass.
473
473
pub ( crate ) since_gc : u32 ,
474
+
474
475
/// The number of CPUs to be reported by miri.
475
476
pub ( crate ) num_cpus : u32 ,
477
+
476
478
/// Determines Miri's page size and associated values
477
479
pub ( crate ) page_size : u64 ,
478
480
pub ( crate ) stack_addr : u64 ,
479
481
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 ,
480
485
}
481
486
482
487
impl < ' mir , ' tcx > MiriMachine < ' mir , ' tcx > {
@@ -585,6 +590,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> {
585
590
page_size,
586
591
stack_addr,
587
592
stack_size,
593
+ collect_leak_backtraces : config. collect_leak_backtraces ,
588
594
}
589
595
}
590
596
@@ -732,6 +738,7 @@ impl VisitTags for MiriMachine<'_, '_> {
732
738
page_size : _,
733
739
stack_addr : _,
734
740
stack_size : _,
741
+ collect_leak_backtraces : _,
735
742
} = self ;
736
743
737
744
threads. visit_tags ( visit) ;
@@ -975,7 +982,11 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> {
975
982
// If an allocation is leaked, we want to report a backtrace to indicate where it was
976
983
// allocated. We don't need to record a backtrace for allocations which are allowed to
977
984
// 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
+ } ;
979
990
980
991
let alloc: Allocation < Provenance , Self :: AllocExtra > = alloc. adjust_from_tcx (
981
992
& ecx. tcx ,
0 commit comments