From 42c9f3c9116c85411d8c1ad3a4bb256f44f71794 Mon Sep 17 00:00:00 2001 From: JF Bastien Date: Tue, 30 Jul 2019 20:01:46 +0000 Subject: [PATCH] [NFC] simplify Darwin environment handling The previous code detected conflicts through copy-pasta, this versions uses a 'loop'. llvm-svn: 367350 --- clang/lib/Driver/ToolChains/Darwin.cpp | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 5de7d71..5f6ad8c 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1480,22 +1480,6 @@ getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver, Targets[I.index()] = Env; } - // Do not allow conflicts with the watchOS target. - if (!Targets[Darwin::WatchOS].empty() && - (!Targets[Darwin::IPhoneOS].empty() || !Targets[Darwin::TvOS].empty())) { - TheDriver.Diag(diag::err_drv_conflicting_deployment_targets) - << "WATCHOS_DEPLOYMENT_TARGET" - << (!Targets[Darwin::IPhoneOS].empty() ? "IPHONEOS_DEPLOYMENT_TARGET" - : "TVOS_DEPLOYMENT_TARGET"); - } - - // Do not allow conflicts with the tvOS target. - if (!Targets[Darwin::TvOS].empty() && !Targets[Darwin::IPhoneOS].empty()) { - TheDriver.Diag(diag::err_drv_conflicting_deployment_targets) - << "TVOS_DEPLOYMENT_TARGET" - << "IPHONEOS_DEPLOYMENT_TARGET"; - } - // Allow conflicts among OSX and iOS for historical reasons, but choose the // default platform. if (!Targets[Darwin::MacOS].empty() && @@ -1508,6 +1492,18 @@ getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver, else Targets[Darwin::IPhoneOS] = Targets[Darwin::WatchOS] = Targets[Darwin::TvOS] = ""; + } else { + // Don't allow conflicts in any other platform. + int FirstTarget = llvm::array_lengthof(Targets); + for (int I = 0; I != llvm::array_lengthof(Targets); ++I) { + if (Targets[I].empty()) + continue; + if (FirstTarget == llvm::array_lengthof(Targets)) + FirstTarget = I; + else + TheDriver.Diag(diag::err_drv_conflicting_deployment_targets) + << Targets[FirstTarget] << Targets[I]; + } } for (const auto &Target : llvm::enumerate(llvm::makeArrayRef(Targets))) { -- 2.7.4