@@ -292,6 +292,9 @@ fn process_builtin_attrs(
292
292
codegen_fn_attrs. linkage = linkage;
293
293
}
294
294
}
295
+ AttributeKind :: Sanitize { span, .. } => {
296
+ interesting_spans. sanitize = Some ( * span) ;
297
+ }
295
298
_ => { }
296
299
}
297
300
}
@@ -309,7 +312,6 @@ fn process_builtin_attrs(
309
312
codegen_fn_attrs. flags |= CodegenFnAttrFlags :: ALLOCATOR_ZEROED
310
313
}
311
314
sym:: thread_local => codegen_fn_attrs. flags |= CodegenFnAttrFlags :: THREAD_LOCAL ,
312
- sym:: sanitize => interesting_spans. sanitize = Some ( attr. span ( ) ) ,
313
315
sym:: instruction_set => {
314
316
codegen_fn_attrs. instruction_set = parse_instruction_set_attr ( tcx, attr)
315
317
}
@@ -559,79 +561,9 @@ fn opt_trait_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
559
561
}
560
562
}
561
563
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
-
632
564
fn disabled_sanitizers_for ( tcx : TyCtxt < ' _ > , did : LocalDefId ) -> SanitizerSet {
633
565
// Backtrack to the crate root.
634
- let disabled = match tcx. opt_local_parent ( did) {
566
+ let mut disabled = match tcx. opt_local_parent ( did) {
635
567
// Check the parent (recursively).
636
568
Some ( parent) => tcx. disabled_sanitizers_for ( parent) ,
637
569
// We reached the crate root without seeing an attribute, so
@@ -640,8 +572,10 @@ fn disabled_sanitizers_for(tcx: TyCtxt<'_>, did: LocalDefId) -> SanitizerSet {
640
572
} ;
641
573
642
574
// 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;
645
579
}
646
580
disabled
647
581
}
0 commit comments