@@ -20,6 +20,7 @@ use rustc_middle::ty::layout::{
2020 FnAbiError , FnAbiOfHelpers , FnAbiRequest , LayoutError , LayoutOfHelpers , TyAndLayout ,
2121} ;
2222use rustc_middle:: ty:: { self , Instance , Ty , TyCtxt } ;
23+ use rustc_session:: config:: OptLevel ;
2324use rustc_span:: Span ;
2425use rustc_symbol_mangling:: typeid:: {
2526 kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
@@ -551,6 +552,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
551552 layout : TyAndLayout < ' tcx > ,
552553 offset : Size ,
553554 ) {
555+ if bx. cx . sess ( ) . opts . optimize == OptLevel :: No {
556+ // Don't emit metadata we're not going to use
557+ return ;
558+ }
559+
554560 if !scalar. is_uninit_valid ( ) {
555561 bx. noundef_metadata ( load) ;
556562 }
@@ -667,6 +673,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
667673 return ;
668674 }
669675
676+ if self . cx . sess ( ) . opts . optimize == OptLevel :: No {
677+ // Don't emit metadata we're not going to use
678+ return ;
679+ }
680+
670681 unsafe {
671682 let llty = self . cx . val_ty ( load) ;
672683 let v = [
0 commit comments