@@ -307,6 +307,10 @@ impl Session {
307307 & self . opts . unstable_opts . coverage_options
308308 }
309309
310+ pub fn is_sanitizer_address_enabled ( & self ) -> bool {
311+ self . sanitizers ( ) . contains ( SanitizerSet :: ADDRESS )
312+ }
313+
310314 pub fn is_sanitizer_cfi_enabled ( & self ) -> bool {
311315 self . sanitizers ( ) . contains ( SanitizerSet :: CFI )
312316 }
@@ -327,6 +331,10 @@ impl Session {
327331 self . opts . unstable_opts . sanitizer_cfi_normalize_integers == Some ( true )
328332 }
329333
334+ pub fn is_sanitizer_hwaddress_enabled ( & self ) -> bool {
335+ self . sanitizers ( ) . contains ( SanitizerSet :: HWADDRESS )
336+ }
337+
330338 pub fn is_sanitizer_kcfi_arity_enabled ( & self ) -> bool {
331339 self . opts . unstable_opts . sanitizer_kcfi_arity == Some ( true )
332340 }
@@ -335,6 +343,26 @@ impl Session {
335343 self . sanitizers ( ) . contains ( SanitizerSet :: KCFI )
336344 }
337345
346+ pub fn is_sanitizer_kernel_address_enabled ( & self ) -> bool {
347+ self . sanitizers ( ) . contains ( SanitizerSet :: KERNELADDRESS )
348+ }
349+
350+ pub fn is_sanitizer_memory_enabled ( & self ) -> bool {
351+ self . sanitizers ( ) . contains ( SanitizerSet :: MEMORY )
352+ }
353+
354+ pub fn is_sanitizer_memory_recover_enabled ( & self ) -> bool {
355+ self . opts . unstable_opts . sanitizer_recover . contains ( SanitizerSet :: MEMORY )
356+ }
357+
358+ pub fn is_sanitizer_memory_track_origins_enabled ( & self ) -> bool {
359+ self . opts . unstable_opts . sanitizer_memory_track_origins != 0
360+ }
361+
362+ pub fn is_sanitizer_thread_enabled ( & self ) -> bool {
363+ self . sanitizers ( ) . contains ( SanitizerSet :: THREAD )
364+ }
365+
338366 pub fn is_split_lto_unit_enabled ( & self ) -> bool {
339367 self . opts . unstable_opts . split_lto_unit == Some ( true )
340368 }
@@ -512,7 +540,10 @@ impl Session {
512540 // AddressSanitizer and KernelAddressSanitizer uses lifetimes to detect use after scope bugs.
513541 // MemorySanitizer uses lifetimes to detect use of uninitialized stack variables.
514542 // HWAddressSanitizer will use lifetimes to detect use after scope bugs in the future.
515- || self . sanitizers ( ) . intersects ( SanitizerSet :: ADDRESS | SanitizerSet :: KERNELADDRESS | SanitizerSet :: MEMORY | SanitizerSet :: HWADDRESS )
543+ || self . is_sanitizer_address_enabled ( )
544+ || self . is_sanitizer_kernel_address_enabled ( )
545+ || self . is_sanitizer_memory_enabled ( )
546+ || self . is_sanitizer_hwaddress_enabled ( )
516547 }
517548
518549 pub fn diagnostic_width ( & self ) -> usize {
@@ -655,7 +686,7 @@ impl Session {
655686 let more_names = self . opts . output_types . contains_key ( & OutputType :: LlvmAssembly )
656687 || self . opts . output_types . contains_key ( & OutputType :: Bitcode )
657688 // AddressSanitizer and MemorySanitizer use alloca name when reporting an issue.
658- || self . opts . unstable_opts . sanitizer . intersects ( SanitizerSet :: ADDRESS | SanitizerSet :: MEMORY ) ;
689+ || self . is_sanitizer_address_enabled ( ) || self . is_sanitizer_memory_enabled ( ) ;
659690 !more_names
660691 }
661692 }
@@ -901,7 +932,7 @@ impl Session {
901932 }
902933
903934 pub fn sanitizers ( & self ) -> SanitizerSet {
904- return self . opts . unstable_opts . sanitizer | self . target . options . default_sanitizers ;
935+ return self . opts . cg . sanitize | self . target . options . default_sanitizers ;
905936 }
906937}
907938
@@ -1169,14 +1200,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
11691200 }
11701201 }
11711202
1172- // Sanitizers can only be used on platforms that we know have working sanitizer codegen.
1173- let supported_sanitizers = sess. target . options . supported_sanitizers ;
1174- let mut unsupported_sanitizers = sess. opts . unstable_opts . sanitizer - supported_sanitizers;
1203+ let supported_sanitizers = if sess. unstable_options ( ) {
1204+ sess. target . options . supported_sanitizers | sess. target . options . stable_sanitizers
1205+ } else {
1206+ sess. target . options . stable_sanitizers
1207+ } ;
1208+ let mut unsupported_sanitizers = sess. sanitizers ( ) - supported_sanitizers;
1209+
11751210 // Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled
11761211 // we should allow Shadow Call Stack sanitizer.
11771212 if sess. opts . unstable_opts . fixed_x18 && sess. target . arch == Arch :: AArch64 {
11781213 unsupported_sanitizers -= SanitizerSet :: SHADOWCALLSTACK ;
11791214 }
1215+
11801216 match unsupported_sanitizers. into_iter ( ) . count ( ) {
11811217 0 => { }
11821218 1 => {
@@ -1191,18 +1227,15 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
11911227 }
11921228
11931229 // Cannot mix and match mutually-exclusive sanitizers.
1194- if let Some ( ( first, second) ) = sess. opts . unstable_opts . sanitizer . mutually_exclusive ( ) {
1230+ if let Some ( ( first, second) ) = sess. opts . cg . sanitize . mutually_exclusive ( ) {
11951231 sess. dcx ( ) . emit_err ( errors:: CannotMixAndMatchSanitizers {
11961232 first : first. to_string ( ) ,
11971233 second : second. to_string ( ) ,
11981234 } ) ;
11991235 }
12001236
12011237 // Cannot enable crt-static with sanitizers on Linux
1202- if sess. crt_static ( None )
1203- && !sess. opts . unstable_opts . sanitizer . is_empty ( )
1204- && !sess. target . is_like_msvc
1205- {
1238+ if sess. crt_static ( None ) && !sess. sanitizers ( ) . is_empty ( ) && !sess. target . is_like_msvc {
12061239 sess. dcx ( ) . emit_err ( errors:: CannotEnableCrtStaticLinux ) ;
12071240 }
12081241
0 commit comments