Author: arphaman Date: Wed Apr 25 15:23:26 2018 New Revision: 330878 URL: http://llvm.org/viewvc/llvm-project?rev=330878&view=rev Log: [driver][darwin] Do not infer -simulator environment for OS version env vars with non-simulator SDKs
rdar://37955008 Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp cfe/trunk/test/Driver/darwin-infer-simulator-sdkroot.c Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=330878&r1=330877&r2=330878&view=diff ============================================================================== --- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original) +++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Wed Apr 25 15:23:26 2018 @@ -1197,6 +1197,11 @@ struct DarwinPlatform { DarwinEnvironmentKind getEnvironment() const { return Environment; } + void setEnvironment(DarwinEnvironmentKind Kind) { + Environment = Kind; + InferSimulatorFromArch = false; + } + StringRef getOSVersion() const { if (Kind == OSVersionArg) return Argument->getValue(); @@ -1214,7 +1219,7 @@ struct DarwinPlatform { bool isExplicitlySpecified() const { return Kind <= DeploymentTargetEnv; } /// Returns true if the simulator environment can be inferred from the arch. - bool canInferSimulatorFromArch() const { return Kind != InferredFromSDK; } + bool canInferSimulatorFromArch() const { return InferSimulatorFromArch; } /// Adds the -m<os>-version-min argument to the compiler invocation. void addOSVersionMinArgument(DerivedArgList &Args, const OptTable &Opts) { @@ -1290,6 +1295,7 @@ struct DarwinPlatform { DarwinPlatform Result(InferredFromSDK, Platform, Value); if (IsSimulator) Result.Environment = DarwinEnvironmentKind::Simulator; + Result.InferSimulatorFromArch = false; return Result; } static DarwinPlatform createFromArch(llvm::Triple::OSType OS, @@ -1324,7 +1330,7 @@ private: DarwinPlatformKind Platform; DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment; std::string OSVersion; - bool HasOSVersion = true; + bool HasOSVersion = true, InferSimulatorFromArch = true; Arg *Argument; StringRef EnvVarName; }; @@ -1593,9 +1599,16 @@ void Darwin::AddDeploymentTarget(Derived OSTarget = getDeploymentTargetFromOSVersionArg(Args, getDriver()); // If no deployment target was specified on the command line, check for // environment defines. - if (!OSTarget) + if (!OSTarget) { OSTarget = getDeploymentTargetFromEnvironmentVariables(getDriver(), getTriple()); + if (OSTarget) { + // Don't infer simulator from the arch when the SDK is also specified. + Optional<DarwinPlatform> SDKTarget = inferDeploymentTargetFromSDK(Args); + if (SDKTarget) + OSTarget->setEnvironment(SDKTarget->getEnvironment()); + } + } // If there is no command-line argument to specify the Target version and // no environment variable defined, see if we can set the default based // on -isysroot. Modified: cfe/trunk/test/Driver/darwin-infer-simulator-sdkroot.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-infer-simulator-sdkroot.c?rev=330878&r1=330877&r2=330878&view=diff ============================================================================== --- cfe/trunk/test/Driver/darwin-infer-simulator-sdkroot.c (original) +++ cfe/trunk/test/Driver/darwin-infer-simulator-sdkroot.c Wed Apr 25 15:23:26 2018 @@ -6,6 +6,8 @@ // RUN: mkdir -p %t/SDKs/iPhoneOS8.0.0.sdk // RUN: env SDKROOT=%t/SDKs/iPhoneOS8.0.0.sdk %clang %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-IPHONE %s +// RUN: env SDKROOT=%t/SDKs/iPhoneOS8.0.0.sdk IPHONEOS_DEPLOYMENT_TARGET=8.0 %clang %s -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-IPHONE %s // CHECK-IPHONE: clang // CHECK-IPHONE: "-cc1" // CHECK-IPHONE: -apple-ios8.0.0" @@ -29,6 +31,8 @@ // RUN: mkdir -p %t/SDKs/WatchOS3.0.sdk // RUN: env SDKROOT=%t/SDKs/WatchOS3.0.sdk %clang %s -### 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-WATCH %s +// RUN: env WATCHOS_DEPLOYMENT_TARGET=3.0 %clang %s -isysroot %t/SDKs/WatchOS3.0.sdk -### 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-WATCH %s // // CHECK-WATCH: clang // CHECK-WATCH: "-cc1" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits