@@ -3,7 +3,7 @@ use std::str::FromStr;
33use rustc_abi:: { Align , ExternAbi } ;
44use rustc_ast:: expand:: autodiff_attrs:: { AutoDiffAttrs , DiffActivity , DiffMode } ;
55use rustc_ast:: { LitKind , MetaItem , MetaItemInner , attr} ;
6- use rustc_hir:: attrs:: { AttributeKind , InlineAttr , InstructionSetAttr , UsedBy } ;
6+ use rustc_hir:: attrs:: { AttributeKind , InlineAttr , InstructionSetAttr , RtsanSetting , UsedBy } ;
77use rustc_hir:: def:: DefKind ;
88use rustc_hir:: def_id:: { DefId , LOCAL_CRATE , LocalDefId } ;
99use rustc_hir:: { self as hir, Attribute , LangItem , find_attr, lang_items} ;
@@ -349,9 +349,12 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
349349 codegen_fn_attrs. alignment =
350350 Ord :: max ( codegen_fn_attrs. alignment , tcx. sess . opts . unstable_opts . min_function_alignment ) ;
351351
352- // Compute the disabled sanitizers.
353- codegen_fn_attrs. sanitizers . disabled |=
354- tcx. sanitizer_settings_for ( did) . disabled ;
352+ // Per sanitizer override if it's in the default state
353+ let sanitizers = tcx. sanitizer_settings_for ( did) ;
354+ codegen_fn_attrs. sanitizers . disabled |= sanitizers. disabled ;
355+ if codegen_fn_attrs. sanitizers . rtsan_setting == RtsanSetting :: default ( ) {
356+ codegen_fn_attrs. sanitizers . rtsan_setting = sanitizers. rtsan_setting ;
357+ }
355358 // On trait methods, inherit the `#[align]` of the trait's method prototype.
356359 codegen_fn_attrs. alignment = Ord :: max ( codegen_fn_attrs. alignment , tcx. inherited_align ( did) ) ;
357360
@@ -587,7 +590,7 @@ fn sanitizer_settings_for(tcx: TyCtxt<'_>, did: LocalDefId) -> SanitizerFnAttrs
587590 } ;
588591
589592 // Check for a sanitize annotation directly on this def.
590- if let Some ( ( on_set, off_set) ) = find_attr ! ( tcx. get_all_attrs( did) , AttributeKind :: Sanitize { on_set, off_set, ..} => ( on_set, off_set) )
593+ if let Some ( ( on_set, off_set, rtsan ) ) = find_attr ! ( tcx. get_all_attrs( did) , AttributeKind :: Sanitize { on_set, off_set, rtsan , ..} => ( on_set, off_set, rtsan ) )
591594 {
592595 // the on set is the set of sanitizers explicitly enabled.
593596 // we mask those out since we want the set of disabled sanitizers here
@@ -598,6 +601,11 @@ fn sanitizer_settings_for(tcx: TyCtxt<'_>, did: LocalDefId) -> SanitizerFnAttrs
598601 // the on set and off set are distjoint since there's a third option: unset.
599602 // a node may not set the sanitizer setting in which case it inherits from parents.
600603 // the code above in this function does this backtracking
604+
605+ // if rtsan was specified here override the parent
606+ if let Some ( rtsan) = rtsan {
607+ settings. rtsan_setting = * rtsan;
608+ }
601609 }
602610 settings
603611}
0 commit comments