@@ -292,6 +292,9 @@ fn process_builtin_attrs(
292292 codegen_fn_attrs. linkage = linkage;
293293 }
294294 }
295+ AttributeKind :: Sanitize { span, .. } => {
296+ interesting_spans. sanitize = Some ( * span) ;
297+ }
295298 _ => { }
296299 }
297300 }
@@ -309,7 +312,6 @@ fn process_builtin_attrs(
309312 codegen_fn_attrs. flags |= CodegenFnAttrFlags :: ALLOCATOR_ZEROED
310313 }
311314 sym:: thread_local => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: THREAD_LOCAL ,
312- sym:: sanitize => interesting_spans. sanitize = Some ( attr. span ( ) ) ,
313315 sym:: instruction_set => {
314316 codegen_fn_attrs. instruction_set = parse_instruction_set_attr ( tcx, attr)
315317 }
@@ -559,79 +561,9 @@ fn opt_trait_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
559561 }
560562}
561563
562- /// For an attr that has the `sanitize` attribute, read the list of
563- /// disabled sanitizers. `current_attr` holds the information about
564- /// previously parsed attributes.
565- fn parse_sanitize_attr (
566- tcx : TyCtxt < ' _ > ,
567- attr : & Attribute ,
568- current_attr : SanitizerSet ,
569- ) -> SanitizerSet {
570- let mut result = current_attr;
571- if let Some ( list) = attr. meta_item_list ( ) {
572- for item in list. iter ( ) {
573- let MetaItemInner :: MetaItem ( set) = item else {
574- tcx. dcx ( ) . emit_err ( errors:: InvalidSanitize { span : attr. span ( ) } ) ;
575- break ;
576- } ;
577- let segments = set. path . segments . iter ( ) . map ( |x| x. ident . name ) . collect :: < Vec < _ > > ( ) ;
578- match segments. as_slice ( ) {
579- // Similar to clang, sanitize(address = ..) and
580- // sanitize(kernel_address = ..) control both ASan and KASan
581- // Source: https://reviews.llvm.org/D44981.
582- [ sym:: address] | [ sym:: kernel_address] if set. value_str ( ) == Some ( sym:: off) => {
583- result |= SanitizerSet :: ADDRESS | SanitizerSet :: KERNELADDRESS
584- }
585- [ sym:: address] | [ sym:: kernel_address] if set. value_str ( ) == Some ( sym:: on) => {
586- result &= !SanitizerSet :: ADDRESS ;
587- result &= !SanitizerSet :: KERNELADDRESS ;
588- }
589- [ sym:: cfi] if set. value_str ( ) == Some ( sym:: off) => result |= SanitizerSet :: CFI ,
590- [ sym:: cfi] if set. value_str ( ) == Some ( sym:: on) => result &= !SanitizerSet :: CFI ,
591- [ sym:: kcfi] if set. value_str ( ) == Some ( sym:: off) => result |= SanitizerSet :: KCFI ,
592- [ sym:: kcfi] if set. value_str ( ) == Some ( sym:: on) => result &= !SanitizerSet :: KCFI ,
593- [ sym:: memory] if set. value_str ( ) == Some ( sym:: off) => {
594- result |= SanitizerSet :: MEMORY
595- }
596- [ sym:: memory] if set. value_str ( ) == Some ( sym:: on) => {
597- result &= !SanitizerSet :: MEMORY
598- }
599- [ sym:: memtag] if set. value_str ( ) == Some ( sym:: off) => {
600- result |= SanitizerSet :: MEMTAG
601- }
602- [ sym:: memtag] if set. value_str ( ) == Some ( sym:: on) => {
603- result &= !SanitizerSet :: MEMTAG
604- }
605- [ sym:: shadow_call_stack] if set. value_str ( ) == Some ( sym:: off) => {
606- result |= SanitizerSet :: SHADOWCALLSTACK
607- }
608- [ sym:: shadow_call_stack] if set. value_str ( ) == Some ( sym:: on) => {
609- result &= !SanitizerSet :: SHADOWCALLSTACK
610- }
611- [ sym:: thread] if set. value_str ( ) == Some ( sym:: off) => {
612- result |= SanitizerSet :: THREAD
613- }
614- [ sym:: thread] if set. value_str ( ) == Some ( sym:: on) => {
615- result &= !SanitizerSet :: THREAD
616- }
617- [ sym:: hwaddress] if set. value_str ( ) == Some ( sym:: off) => {
618- result |= SanitizerSet :: HWADDRESS
619- }
620- [ sym:: hwaddress] if set. value_str ( ) == Some ( sym:: on) => {
621- result &= !SanitizerSet :: HWADDRESS
622- }
623- _ => {
624- tcx. dcx ( ) . emit_err ( errors:: InvalidSanitize { span : attr. span ( ) } ) ;
625- }
626- }
627- }
628- }
629- result
630- }
631-
632564fn disabled_sanitizers_for ( tcx : TyCtxt < ' _ > , did : LocalDefId ) -> SanitizerSet {
633565 // Backtrack to the crate root.
634- let disabled = match tcx. opt_local_parent ( did) {
566+ let mut disabled = match tcx. opt_local_parent ( did) {
635567 // Check the parent (recursively).
636568 Some ( parent) => tcx. disabled_sanitizers_for ( parent) ,
637569 // We reached the crate root without seeing an attribute, so
@@ -640,8 +572,10 @@ fn disabled_sanitizers_for(tcx: TyCtxt<'_>, did: LocalDefId) -> SanitizerSet {
640572 } ;
641573
642574 // Check for a sanitize annotation directly on this def.
643- if let Some ( attr) = tcx. get_attr ( did, sym:: sanitize) {
644- return parse_sanitize_attr ( tcx, attr, disabled) ;
575+ if let Some ( ( on_set, off_set) ) = find_attr ! ( tcx. get_all_attrs( did) , AttributeKind :: Sanitize { on_set, off_set, ..} => ( on_set, off_set) )
576+ {
577+ disabled &= !* on_set;
578+ disabled |= * off_set;
645579 }
646580 disabled
647581}
0 commit comments