[driver] Set the 'simulator' environment for Darwin when compiling for

iOS/tvOS/watchOS simulator

rdar://35135215

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

llvm-svn: 320073
This commit is contained in:
Alex Lorenz 2017-12-07 19:04:10 +00:00
parent d182aaa69d
commit 6cdef0efb7
10 changed files with 34 additions and 30 deletions

View File

@ -93,7 +93,7 @@ public:
private:
const Driver &D;
const llvm::Triple Triple;
llvm::Triple Triple;
const llvm::opt::ArgList &Args;
// We need to initialize CachedRTTIArg before CachedRTTIMode
const llvm::opt::Arg *const CachedRTTIArg;
@ -136,6 +136,8 @@ protected:
ToolChain(const Driver &D, const llvm::Triple &T,
const llvm::opt::ArgList &Args);
void setTripleEnvironment(llvm::Triple::EnvironmentType Env);
virtual Tool *buildAssembler() const;
virtual Tool *buildLinker() const;
virtual Tool *getTool(Action::ActionClass AC) const;

View File

@ -4885,10 +4885,7 @@ void CGObjCCommonMac::EmitImageInfo() {
}
// Indicate whether we're compiling this to run on a simulator.
const llvm::Triple &Triple = CGM.getTarget().getTriple();
if ((Triple.isiOS() || Triple.isWatchOS()) &&
(Triple.getArch() == llvm::Triple::x86 ||
Triple.getArch() == llvm::Triple::x86_64))
if (CGM.getTarget().getTriple().isSimulatorEnvironment())
Mod.addModuleFlag(llvm::Module::Error, "Objective-C Is Simulated",
eImageInfo_ImageIsSimulated);

View File

@ -81,6 +81,12 @@ ToolChain::ToolChain(const Driver &D, const llvm::Triple &T,
getFilePaths().push_back(CandidateLibPath);
}
void ToolChain::setTripleEnvironment(llvm::Triple::EnvironmentType Env) {
Triple.setEnvironment(Env);
if (EffectiveTriple != llvm::Triple())
EffectiveTriple.setEnvironment(Env);
}
ToolChain::~ToolChain() {
}

View File

@ -1214,14 +1214,6 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
if (iOSVersion)
ExplicitIOSDeploymentTargetStr = iOSVersion->getAsString(Args);
// Add a macro to differentiate between m(iphone|tv|watch)os-version-min=X.Y and
// -m(iphone|tv|watch)simulator-version-min=X.Y.
if (Args.hasArg(options::OPT_mios_simulator_version_min_EQ) ||
Args.hasArg(options::OPT_mtvos_simulator_version_min_EQ) ||
Args.hasArg(options::OPT_mwatchos_simulator_version_min_EQ))
Args.append(Args.MakeSeparateArg(nullptr, Opts.getOption(options::OPT_D),
" __APPLE_EMBEDDED_SIMULATOR__=1"));
if (OSXVersion && (iOSVersion || TvOSVersion || WatchOSVersion)) {
getDriver().Diag(diag::err_drv_argument_not_allowed_with)
<< OSXVersion->getAsString(Args)

View File

@ -329,6 +329,9 @@ protected:
TargetInitialized = true;
TargetPlatform = Platform;
TargetVersion = VersionTuple(Major, Minor, Micro);
if (Platform == IPhoneOSSimulator || Platform == TvOSSimulator ||
Platform == WatchOSSimulator)
const_cast<Darwin *>(this)->setTripleEnvironment(llvm::Triple::Simulator);
}
bool isTargetIPhoneOS() const {

View File

@ -998,6 +998,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__nullable", "_Nullable");
}
// Add a macro to differentiate between regular iOS/tvOS/watchOS targets and
// the corresponding simulator targets.
if (TI.getTriple().isOSDarwin() && TI.getTriple().isSimulatorEnvironment())
Builder.defineMacro("__APPLE_EMBEDDED_SIMULATOR__", "1");
// OpenMP definition
// OpenMP 2.2:
// In implementations that support a preprocessor, the _OPENMP

View File

@ -60,7 +60,7 @@
//
// CHECK-SIMULATOR: clang
// CHECK-SIMULATOR: "-cc1"
// CHECK-SIMULATOR: "-triple" "x86_64-apple-ios8.0.0"
// CHECK-SIMULATOR: "-triple" "x86_64-apple-ios8.0.0-simulator"
// CHECK-SIMULATOR: ld
// CHECK-SIMULATOR: "-ios_simulator_version_min" "8.0.0"
//

View File

@ -4,9 +4,8 @@
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mappletvsimulator-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=SIM %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mwatchos-simulator-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=SIM %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mwatchsimulator-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=SIM %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mios-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=DEV %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mtvos-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=DEV %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mwatchos-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=DEV %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mios-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=SIM %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mtvos-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=SIM %s
// RUN: %clang -target x86_64-apple-darwin10 -arch x86_64 -mwatchos-version-min=6.0.0 -E -dM %s | FileCheck -check-prefix=SIM %s
// SIM: #define __APPLE_EMBEDDED_SIMULATOR__ 1
// DEV-NOT: __APPLE_EMBEDDED_SIMULATOR__

View File

@ -41,7 +41,7 @@
// RUN: %clang -target x86_64-apple-darwin -mios-simulator-version-min=11.0 -c -### %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS10 %s
// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0
// CHECK-VERSION-IOS10: x86_64-apple-ios11.0.0-simulator
// RUN: %clang -target arm64-apple-ios11.1 -c -### %s 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS11 %s
@ -85,13 +85,13 @@
// CHECK-VERSION-TVOS83: "thumbv7-apple-tvos8.3.0"
// RUN: %clang -target i386-apple-darwin -mtvos-simulator-version-min=8.3 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TVSIM83 %s
// CHECK-VERSION-TVSIM83: "i386-apple-tvos8.3.0"
// CHECK-VERSION-TVSIM83: "i386-apple-tvos8.3.0-simulator"
// RUN: %clang -target armv7k-apple-darwin -mwatchos-version-min=2.0 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-WATCHOS20 %s
// CHECK-VERSION-WATCHOS20: "thumbv7k-apple-watchos2.0.0"
// RUN: %clang -target i386-apple-darwin -mwatchos-simulator-version-min=2.0 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-WATCHSIM20 %s
// CHECK-VERSION-WATCHSIM20: "i386-apple-watchos2.0.0"
// CHECK-VERSION-WATCHSIM20: "i386-apple-watchos2.0.0-simulator"
// Check environment variable gets interpreted correctly
// RUN: env MACOSX_DEPLOYMENT_TARGET=10.5 IPHONEOS_DEPLOYMENT_TARGET=2.0 \
@ -117,7 +117,7 @@
// RUN: env TVOS_DEPLOYMENT_TARGET=8.3.1 \
// RUN: %clang -target i386-apple-darwin9 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TVOSSIM %s
// CHECK-VERSION-TVOSSIM: "i386-apple-tvos8.3.1"
// CHECK-VERSION-TVOSSIM: "i386-apple-tvos8.3.1-simulator"
// RUN: env MACOSX_DEPLOYMENT_TARGET=10.5 WATCHOS_DEPLOYMENT_TARGET=2.0 \
// RUN: %clang -target armv7-apple-darwin9 -c %s -### 2>&1 | \
@ -126,16 +126,16 @@
// RUN: env WATCHOS_DEPLOYMENT_TARGET=2.0 \
// RUN: %clang -target i386-apple-darwin9 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-WATCHOSSIM %s
// CHECK-VERSION-WATCHOSSIM: "i386-apple-watchos2.0.0"
// CHECK-VERSION-WATCHOSSIM: "i386-apple-watchos2.0.0-simulator"
// RUN: %clang -target x86_64-apple-ios11.0.0 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-IOS-TARGET %s
// CHECK-VERSION-IOS-TARGET: "x86_64-apple-ios11.0.0"
// CHECK-VERSION-IOS-TARGET: "x86_64-apple-ios11.0.0-simulator"
// RUN: %clang -target x86_64-apple-tvos11.0 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TVOS-TARGET %s
// CHECK-VERSION-TVOS-TARGET: "x86_64-apple-tvos11.0.0"
// CHECK-VERSION-TVOS-TARGET: "x86_64-apple-tvos11.0.0-simulator"
// RUN: %clang -target x86_64-apple-watchos4.0 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-WATCHOS-TARGET %s
// CHECK-VERSION-WATCHOS-TARGET: "x86_64-apple-watchos4.0.0"
// CHECK-VERSION-WATCHOS-TARGET: "x86_64-apple-watchos4.0.0-simulator"

View File

@ -334,10 +334,10 @@
// CHECK-TSAN-ARM-IOS: unsupported option '-fsanitize=thread' for target 'arm-apple-ios'
// RUN: %clang -target i386-apple-iossimulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-I386-IOSSIMULATOR
// CHECK-TSAN-I386-IOSSIMULATOR: unsupported option '-fsanitize=thread' for target 'i386-apple-iossimulator'
// CHECK-TSAN-I386-IOSSIMULATOR: unsupported option '-fsanitize=thread' for target 'i386-apple-iossimulator-simulator'
// RUN: %clang -target i386-apple-tvossimulator -fsanitize=thread %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-I386-TVOSSIMULATOR
// CHECK-TSAN-I386-TVOSSIMULATOR: unsupported option '-fsanitize=thread' for target 'i386-apple-tvossimulator'
// CHECK-TSAN-I386-TVOSSIMULATOR: unsupported option '-fsanitize=thread' for target 'i386-apple-tvossimulator-simulator'
// RUN: %clang -target x86_64-linux-gnu -fsanitize=thread -fsanitize-thread-memory-access %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-TSAN-MEMORY-ACCESS
// CHECK-TSAN-MEMORY-ACCESS-NOT: -cc1{{.*}}tsan-instrument-memory-accesses=0
@ -423,11 +423,11 @@
// RUN: %clang -target i386-apple-iossimulator -fsanitize=efficiency-cache-frag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-I386-IOSSIMULATOR
// RUN: %clang -target i386-apple-iossimulator -fsanitize=efficiency-working-set %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-I386-IOSSIMULATOR
// CHECK-ESAN-I386-IOSSIMULATOR: unsupported option '-fsanitize=efficiency-{{.*}}' for target 'i386-apple-iossimulator'
// CHECK-ESAN-I386-IOSSIMULATOR: unsupported option '-fsanitize=efficiency-{{.*}}' for target 'i386-apple-iossimulator-simulator'
// RUN: %clang -target i386-apple-tvossimulator -fsanitize=efficiency-cache-frag %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-I386-TVOSSIMULATOR
// RUN: %clang -target i386-apple-tvossimulator -fsanitize=efficiency-working-set %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-ESAN-I386-TVOSSIMULATOR
// CHECK-ESAN-I386-TVOSSIMULATOR: unsupported option '-fsanitize=efficiency-{{.*}}' for target 'i386-apple-tvossimulator'
// CHECK-ESAN-I386-TVOSSIMULATOR: unsupported option '-fsanitize=efficiency-{{.*}}' for target 'i386-apple-tvossimulator-simulator'