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