diff --git a/swift/internal/feature_names.bzl b/swift/internal/feature_names.bzl index f19b52295..e2abe7d0d 100644 --- a/swift/internal/feature_names.bzl +++ b/swift/internal/feature_names.bzl @@ -325,6 +325,10 @@ SWIFT_FEATURE_OBJC_LINK_FLAGS = "swift.objc_link_flag" # all Swift compilations to always be linked. SWIFT_FEATURE__FORCE_ALWAYSLINK_TRUE = "swift._force_alwayslink_true" +# If enabled, requests the `-enforce-exclusivity=checked` swiftc flag which +# enables runtime checking of exclusive memory access on mutation. +SWIFT_FEATURE_CHECKED_EXCLUSIVITY = "swift.checked_exclusivity" + # Disables Swift sandbox which prevents issues with nested sandboxing when Swift code contains system-provided macros. # If enabled '#Preview' macro provided by SwiftUI fails to build and probably other system-provided macros. # Enabled by default for Swift 5.10+ on macOS. diff --git a/swift/toolchains/config/compile_config.bzl b/swift/toolchains/config/compile_config.bzl index d5be70b43..18c4d03d5 100644 --- a/swift/toolchains/config/compile_config.bzl +++ b/swift/toolchains/config/compile_config.bzl @@ -34,6 +34,7 @@ load( load( "//swift/internal:feature_names.bzl", "SWIFT_FEATURE_CACHEABLE_SWIFTMODULES", + "SWIFT_FEATURE_CHECKED_EXCLUSIVITY", "SWIFT_FEATURE_CODEVIEW_DEBUG_INFO", "SWIFT_FEATURE_COVERAGE", "SWIFT_FEATURE_COVERAGE_PREFIX_MAP", @@ -249,6 +250,13 @@ def compile_action_configs( configurators = [_emit_objc_header_path_configurator], ), + # Configure enforce exclusivity checks if enabled. + ActionConfigInfo( + actions = [SWIFT_ACTION_COMPILE], + configurators = [add_arg("-enforce-exclusivity=checked")], + features = [SWIFT_FEATURE_CHECKED_EXCLUSIVITY], + ), + # Configure Const value extraction. ActionConfigInfo( actions = [SWIFT_ACTION_COMPILE],