Split a complex conditional into separate statements

This commit is contained in:
Chris Wailes 2024-03-13 11:13:25 -07:00
parent 2a9d1ed538
commit bf2858a05f

View File

@ -1201,21 +1201,29 @@ fn add_sanitizer_libraries(
crate_type: CrateType,
linker: &mut dyn Linker,
) {
// On macOS and Windows using MSVC the runtimes are distributed as dylibs
// which should be linked to both executables and dynamic libraries.
// Everywhere else the runtimes are currently distributed as static
// libraries which should be linked to executables only.
let needs_runtime = !sess.target.is_like_android
&& !sess.opts.unstable_opts.external_clangrt
&& match crate_type {
CrateType::Executable => true,
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
sess.target.is_like_osx || sess.target.is_like_msvc
if sess.target.is_like_android {
// Sanitizer runtime libraries are provided dynamically on Android
// targets.
return;
}
CrateType::Rlib | CrateType::Staticlib => false,
};
if !needs_runtime {
if sess.opts.unstable_opts.external_clangrt {
// Linking against in-tree sanitizer runtimes is disabled via
// `-Z external-clangrt`
return;
}
// On macOS the runtimes are distributed as dylibs which should be linked to
// both executables and dynamic shared objects. On most other platforms the
// runtimes are currently distributed as static libraries which should be
// linked to executables only.
if matches!(crate_type, CrateType::Rlib | CrateType::Staticlib) {
return;
}
if matches!(crate_type, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro)
&& (sess.target.is_like_osx || sess.target.is_like_msvc)
{
return;
}