Skip to content

Commit

Permalink
[driver][darwin] Set the 'simulator' environment when it's specified
Browse files Browse the repository at this point in the history
in '-target'

rdar://35742458

Differential Revision: https://reviews.llvm.org/D41076

llvm-svn: 321102
  • Loading branch information
hyp committed Dec 19, 2017
1 parent b2a0319 commit 91f9cfc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
27 changes: 21 additions & 6 deletions clang/lib/Driver/ToolChains/Darwin.cpp
Expand Up @@ -1181,9 +1181,12 @@ struct DarwinPlatform {
};

using DarwinPlatformKind = Darwin::DarwinPlatformKind;
using DarwinEnvironmentKind = Darwin::DarwinEnvironmentKind;

DarwinPlatformKind getPlatform() const { return Platform; }

DarwinEnvironmentKind getEnvironment() const { return Environment; }

StringRef getOSVersion() const {
if (Kind == OSVersionArg)
return Argument->getValue();
Expand Down Expand Up @@ -1234,8 +1237,17 @@ struct DarwinPlatform {
}

static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
StringRef OSVersion, Arg *A) {
return DarwinPlatform(TargetArg, getPlatformFromOS(OS), OSVersion, A);
StringRef OSVersion, Arg *A,
llvm::Triple::EnvironmentType Env) {
DarwinPlatform Result(TargetArg, getPlatformFromOS(OS), OSVersion, A);
switch (Env) {
case llvm::Triple::Simulator:
Result.Environment = DarwinEnvironmentKind::Simulator;
break;
default:
break;
}
return Result;
}
static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
Arg *A) {
Expand Down Expand Up @@ -1282,6 +1294,7 @@ struct DarwinPlatform {

SourceKind Kind;
DarwinPlatformKind Platform;
DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
std::string OSVersion;
Arg *Argument;
StringRef EnvVarName;
Expand Down Expand Up @@ -1478,7 +1491,8 @@ Optional<DarwinPlatform> getDeploymentTargetFromTargetArg(
return None;
std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
return DarwinPlatform::createFromTarget(Triple.getOS(), OSVersion,
Args.getLastArg(options::OPT_target));
Args.getLastArg(options::OPT_target),
Triple.getEnvironment());
}

} // namespace
Expand Down Expand Up @@ -1584,10 +1598,11 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
} else
llvm_unreachable("unknown kind of Darwin platform");

DarwinEnvironmentKind Environment = NativeEnvironment;
DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
// Recognize iOS targets with an x86 architecture as the iOS simulator.
if (Platform != MacOS && (getTriple().getArch() == llvm::Triple::x86 ||
getTriple().getArch() == llvm::Triple::x86_64))
if (Environment == NativeEnvironment && Platform != MacOS &&
(getTriple().getArch() == llvm::Triple::x86 ||
getTriple().getArch() == llvm::Triple::x86_64))
Environment = Simulator;

setTarget(Platform, Environment, Major, Minor, Micro);
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Driver/darwin-version.c
Expand Up @@ -262,3 +262,13 @@
// RUN: %clang -target uknown-apple-macos10.11.2 -arch=armv7k -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TIGNORE-ARCH1 %s
// CHECK-VERSION-TIGNORE-ARCH1: "unknown-apple-macosx10.11.2"

// Target can be used to specify the environment:

// RUN: %clang -target x86_64-apple-ios11-simulator -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TENV-SIM1 %s
// CHECK-VERSION-TENV-SIM1: "x86_64-apple-ios11.0.0-simulator"

// RUN: %clang -target armv7k-apple-ios10.1-simulator -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TENV-SIM2 %s
// CHECK-VERSION-TENV-SIM2: "thumbv7k-apple-ios10.1.0-simulator"

0 comments on commit 91f9cfc

Please sign in to comment.