[PATCH] D41076: [driver][darwin] Set the 'simulator' environment when it's specified in '-target'

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 11 10:42:08 PST 2017


arphaman created this revision.

This patch ensures that '-target' can be used to set the 'simulator' environment component in the target triple.


Repository:
  rC Clang

https://reviews.llvm.org/D41076

Files:
  lib/Driver/ToolChains/Darwin.cpp
  test/Driver/darwin-version.c


Index: test/Driver/darwin-version.c
===================================================================
--- test/Driver/darwin-version.c
+++ test/Driver/darwin-version.c
@@ -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"
Index: lib/Driver/ToolChains/Darwin.cpp
===================================================================
--- lib/Driver/ToolChains/Darwin.cpp
+++ lib/Driver/ToolChains/Darwin.cpp
@@ -1181,9 +1181,12 @@
   };
 
   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();
@@ -1234,8 +1237,17 @@
   }
 
   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) {
@@ -1282,6 +1294,7 @@
 
   SourceKind Kind;
   DarwinPlatformKind Platform;
+  DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
   std::string OSVersion;
   Arg *Argument;
   StringRef EnvVarName;
@@ -1478,7 +1491,8 @@
     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
@@ -1584,10 +1598,11 @@
   } 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41076.126402.patch
Type: text/x-patch
Size: 3609 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171211/90e92beb/attachment.bin>


More information about the cfe-commits mailing list