@@ -360,8 +360,12 @@ impl Session {
360
360
self . opts . unstable_opts . coverage_options . no_mir_spans
361
361
}
362
362
363
+ pub fn is_sanitizer_address_enabled ( & self ) -> bool {
364
+ self . opts . cg . sanitize . contains ( SanitizerSet :: ADDRESS )
365
+ }
366
+
363
367
pub fn is_sanitizer_cfi_enabled ( & self ) -> bool {
364
- self . opts . unstable_opts . sanitizer . contains ( SanitizerSet :: CFI )
368
+ self . opts . cg . sanitize . contains ( SanitizerSet :: CFI )
365
369
}
366
370
367
371
pub fn is_sanitizer_cfi_canonical_jump_tables_disabled ( & self ) -> bool {
@@ -380,8 +384,32 @@ impl Session {
380
384
self . opts . unstable_opts . sanitizer_cfi_normalize_integers == Some ( true )
381
385
}
382
386
387
+ pub fn is_sanitizer_hwaddress_enabled ( & self ) -> bool {
388
+ self . opts . cg . sanitize . contains ( SanitizerSet :: HWADDRESS )
389
+ }
390
+
383
391
pub fn is_sanitizer_kcfi_enabled ( & self ) -> bool {
384
- self . opts . unstable_opts . sanitizer . contains ( SanitizerSet :: KCFI )
392
+ self . opts . cg . sanitize . contains ( SanitizerSet :: KCFI )
393
+ }
394
+
395
+ pub fn is_sanitizer_kernel_address_enabled ( & self ) -> bool {
396
+ self . opts . cg . sanitize . contains ( SanitizerSet :: KERNELADDRESS )
397
+ }
398
+
399
+ pub fn is_sanitizer_memory_enabled ( & self ) -> bool {
400
+ self . opts . cg . sanitize . contains ( SanitizerSet :: MEMORY )
401
+ }
402
+
403
+ pub fn is_sanitizer_memory_recover_enabled ( & self ) -> bool {
404
+ self . opts . unstable_opts . sanitizer_recover . contains ( SanitizerSet :: MEMORY )
405
+ }
406
+
407
+ pub fn is_sanitizer_memory_track_origins_enabled ( & self ) -> bool {
408
+ self . opts . unstable_opts . sanitizer_memory_track_origins != 0
409
+ }
410
+
411
+ pub fn is_sanitizer_thread_enabled ( & self ) -> bool {
412
+ self . opts . cg . sanitize . contains ( SanitizerSet :: THREAD )
385
413
}
386
414
387
415
pub fn is_split_lto_unit_enabled ( & self ) -> bool {
@@ -563,7 +591,10 @@ impl Session {
563
591
// AddressSanitizer and KernelAddressSanitizer uses lifetimes to detect use after scope bugs.
564
592
// MemorySanitizer uses lifetimes to detect use of uninitialized stack variables.
565
593
// HWAddressSanitizer will use lifetimes to detect use after scope bugs in the future.
566
- || self . opts . unstable_opts . sanitizer . intersects ( SanitizerSet :: ADDRESS | SanitizerSet :: KERNELADDRESS | SanitizerSet :: MEMORY | SanitizerSet :: HWADDRESS )
594
+ || self . is_sanitizer_address_enabled ( )
595
+ || self . is_sanitizer_kernel_address_enabled ( )
596
+ || self . is_sanitizer_memory_enabled ( )
597
+ || self . is_sanitizer_hwaddress_enabled ( )
567
598
}
568
599
569
600
pub fn diagnostic_width ( & self ) -> usize {
@@ -691,7 +722,7 @@ impl Session {
691
722
let more_names = self . opts . output_types . contains_key ( & OutputType :: LlvmAssembly )
692
723
|| self . opts . output_types . contains_key ( & OutputType :: Bitcode )
693
724
// AddressSanitizer and MemorySanitizer use alloca name when reporting an issue.
694
- || self . opts . unstable_opts . sanitizer . intersects ( SanitizerSet :: ADDRESS | SanitizerSet :: MEMORY ) ;
725
+ || self . is_sanitizer_address_enabled ( ) || self . is_sanitizer_memory_enabled ( ) ;
695
726
!more_names
696
727
}
697
728
}
@@ -1136,14 +1167,19 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
1136
1167
}
1137
1168
}
1138
1169
1139
- // Sanitizers can only be used on platforms that we know have working sanitizer codegen.
1140
- let supported_sanitizers = sess. target . options . supported_sanitizers ;
1141
- let mut unsupported_sanitizers = sess. opts . unstable_opts . sanitizer - supported_sanitizers;
1170
+ let supported_sanitizers = if sess. unstable_options ( ) {
1171
+ sess. target . options . supported_sanitizers | sess. target . options . stable_sanitizers
1172
+ } else {
1173
+ sess. target . options . stable_sanitizers
1174
+ } ;
1175
+ let mut unsupported_sanitizers = sess. opts . cg . sanitize - supported_sanitizers;
1176
+
1142
1177
// Niche: if `fixed-x18`, or effectively switching on `reserved-x18` flag, is enabled
1143
1178
// we should allow Shadow Call Stack sanitizer.
1144
1179
if sess. opts . unstable_opts . fixed_x18 && sess. target . arch == "aarch64" {
1145
1180
unsupported_sanitizers -= SanitizerSet :: SHADOWCALLSTACK ;
1146
1181
}
1182
+
1147
1183
match unsupported_sanitizers. into_iter ( ) . count ( ) {
1148
1184
0 => { }
1149
1185
1 => {
@@ -1158,18 +1194,15 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
1158
1194
}
1159
1195
1160
1196
// Cannot mix and match mutually-exclusive sanitizers.
1161
- if let Some ( ( first, second) ) = sess. opts . unstable_opts . sanitizer . mutually_exclusive ( ) {
1197
+ if let Some ( ( first, second) ) = sess. opts . cg . sanitize . mutually_exclusive ( ) {
1162
1198
sess. dcx ( ) . emit_err ( errors:: CannotMixAndMatchSanitizers {
1163
1199
first : first. to_string ( ) ,
1164
1200
second : second. to_string ( ) ,
1165
1201
} ) ;
1166
1202
}
1167
1203
1168
1204
// Cannot enable crt-static with sanitizers on Linux
1169
- if sess. crt_static ( None )
1170
- && !sess. opts . unstable_opts . sanitizer . is_empty ( )
1171
- && !sess. target . is_like_msvc
1172
- {
1205
+ if sess. crt_static ( None ) && !sess. opts . cg . sanitize . is_empty ( ) && !sess. target . is_like_msvc {
1173
1206
sess. dcx ( ) . emit_err ( errors:: CannotEnableCrtStaticLinux ) ;
1174
1207
}
1175
1208
0 commit comments