]> granicus.if.org Git - clang/commitdiff
[driver] Set the 'simulator' environment for Darwin when compiling for
authorAlex Lorenz <arphaman@gmail.com>
Thu, 7 Dec 2017 19:04:10 +0000 (19:04 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Thu, 7 Dec 2017 19:04:10 +0000 (19:04 +0000)
iOS/tvOS/watchOS simulator

rdar://35135215

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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@320073 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/ToolChain.h
lib/CodeGen/CGObjCMac.cpp
lib/Driver/ToolChain.cpp
lib/Driver/ToolChains/Darwin.cpp
lib/Driver/ToolChains/Darwin.h
lib/Frontend/InitPreprocessor.cpp
test/Driver/darwin-sdkroot.c
test/Driver/darwin-simulator-macro.c
test/Driver/darwin-version.c
test/Driver/fsanitize.c

index 95f1461c495927c82af930ad84a25d0f84a0629c..13f54d3718b4c30023ba6f5fef997227cad8f73d 100644 (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;
index 6c47da8ab99a3a8dd972a107fa9a2ba4952e0eec..ef4e6cd4f01b3aa35eab4438cec951b8dc1df930 100644 (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);
 
index 328b88559b70f9373d3b263f9a2d9a11926a76db..f96a1182e3cab529a92064afd3447d4e32628e1c 100644 (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() {
 }
 
index 7c401aa9dd552ad2c900cad436917cb833ab820e..2b0e59a6b596b12e0498de5e561043b43b5a0c0e 100644 (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)
index c861f172fe1fd3a013c039f9d0771de75e5c2262..6d6493a6d1b7e6f2a2bc644c0e286b437e0378b0 100644 (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 {
index 617b6aabcc758c26e4cbe0834afc2f8adba580fc..a7ce2868a633999fae15e81e30c4aeab3d7fad45 100644 (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
index 4f1fca2785b04b3c50ac0ed9cb42011417498f30..8b3782ea22a71d7eaac7e795c24aef91bab36330 100644 (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"
 //
index 6971e9303a6da4d1136fc36daf47c61a2f8b2cb1..cf172997d67fbab1bb9e3a349e6e7565391de615 100644 (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__
index 3ff49aca6c0277531d7fa8263193ea2baaa0849b..a7947880354b6872990857f2f54fb8f736f2cd2a 100644 (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
 // 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 \
 // 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 | \
 // 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"
index 3de6fa0b35a4a4e97a25fadfd82bbf6edf029246..cd965469d926807a7efca680142895e53c005472 100644 (file)
 // 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
 
 // 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'