r321559 - [driver][darwin] Take the OS version from -m<os>-version-min argument when
Alex Lorenz via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 29 09:42:40 PST 2017
Author: arphaman
Date: Fri Dec 29 09:42:40 2017
New Revision: 321559
URL: http://llvm.org/viewvc/llvm-project?rev=321559&view=rev
Log:
[driver][darwin] Take the OS version from -m<os>-version-min argument when
-target has no OS version
This ensures that Clang won't warn about redundant -m<os>-version-min
argument for an invocation like
`-target x86_64-apple-macos -mmacos-version-min=10.11`
Modified:
cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
cfe/trunk/test/Driver/darwin-version.c
Modified: cfe/trunk/lib/Driver/ToolChains/Darwin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Darwin.cpp?rev=321559&r1=321558&r2=321559&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Darwin.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Darwin.cpp Fri Dec 29 09:42:40 2017
@@ -1192,6 +1192,13 @@ struct DarwinPlatform {
return OSVersion;
}
+ void setOSVersion(StringRef S) {
+ assert(Kind == TargetArg && "Unexpected kind!");
+ OSVersion = S;
+ }
+
+ bool hasOSVersion() const { return HasOSVersion; }
+
/// Returns true if the target OS was explicitly specified.
bool isExplicitlySpecified() const { return Kind <= DeploymentTargetEnv; }
@@ -1235,17 +1242,21 @@ struct DarwinPlatform {
llvm_unreachable("Unsupported Darwin Source Kind");
}
- static DarwinPlatform createFromTarget(llvm::Triple::OSType OS,
- StringRef OSVersion, Arg *A,
- llvm::Triple::EnvironmentType Env) {
- DarwinPlatform Result(TargetArg, getPlatformFromOS(OS), OSVersion, A);
- switch (Env) {
+ static DarwinPlatform createFromTarget(const llvm::Triple &TT,
+ StringRef OSVersion, Arg *A) {
+ DarwinPlatform Result(TargetArg, getPlatformFromOS(TT.getOS()), OSVersion,
+ A);
+ switch (TT.getEnvironment()) {
case llvm::Triple::Simulator:
Result.Environment = DarwinEnvironmentKind::Simulator;
break;
default:
break;
}
+ unsigned Major, Minor, Micro;
+ TT.getOSVersion(Major, Minor, Micro);
+ if (Major == 0)
+ Result.HasOSVersion = false;
return Result;
}
static DarwinPlatform createOSVersionArg(DarwinPlatformKind Platform,
@@ -1295,6 +1306,7 @@ private:
DarwinPlatformKind Platform;
DarwinEnvironmentKind Environment = DarwinEnvironmentKind::NativeEnvironment;
std::string OSVersion;
+ bool HasOSVersion = true;
Arg *Argument;
StringRef EnvVarName;
};
@@ -1489,9 +1501,8 @@ Optional<DarwinPlatform> getDeploymentTa
Triple.getOS() == llvm::Triple::UnknownOS)
return None;
std::string OSVersion = getOSVersion(Triple.getOS(), Triple, TheDriver);
- return DarwinPlatform::createFromTarget(Triple.getOS(), OSVersion,
- Args.getLastArg(options::OPT_target),
- Triple.getEnvironment());
+ return DarwinPlatform::createFromTarget(Triple, OSVersion,
+ Args.getLastArg(options::OPT_target));
}
} // namespace
@@ -1537,12 +1548,20 @@ void Darwin::AddDeploymentTarget(Derived
(VersionTuple(TargetMajor, TargetMinor, TargetMicro) !=
VersionTuple(ArgMajor, ArgMinor, ArgMicro) ||
TargetExtra != ArgExtra))) {
- // Warn about -m<os>-version-min that doesn't match the OS version
- // that's specified in the target.
- std::string OSVersionArg = OSVersionArgTarget->getAsString(Args, Opts);
- std::string TargetArg = OSTarget->getAsString(Args, Opts);
- getDriver().Diag(clang::diag::warn_drv_overriding_flag_option)
- << OSVersionArg << TargetArg;
+ // Select the OS version from the -m<os>-version-min argument when
+ // the -target does not include an OS version.
+ if (OSTarget->getPlatform() == OSVersionArgTarget->getPlatform() &&
+ !OSTarget->hasOSVersion()) {
+ OSTarget->setOSVersion(OSVersionArgTarget->getOSVersion());
+ } else {
+ // Warn about -m<os>-version-min that doesn't match the OS version
+ // that's specified in the target.
+ std::string OSVersionArg =
+ OSVersionArgTarget->getAsString(Args, Opts);
+ std::string TargetArg = OSTarget->getAsString(Args, Opts);
+ getDriver().Diag(clang::diag::warn_drv_overriding_flag_option)
+ << OSVersionArg << TargetArg;
+ }
}
}
} else {
Modified: cfe/trunk/test/Driver/darwin-version.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-version.c?rev=321559&r1=321558&r2=321559&view=diff
==============================================================================
--- cfe/trunk/test/Driver/darwin-version.c (original)
+++ cfe/trunk/test/Driver/darwin-version.c Fri Dec 29 09:42:40 2017
@@ -205,7 +205,8 @@
// RUN: %clang -target x86_64-apple-ios -miphonesimulator-version-min=10.0 -c %s -### 2>&1 | \
// RUN: FileCheck --check-prefix=CHECK-VERSION-TNO-OSV3 %s
-// CHECK-VERSION-TNO-OSV3: overriding '-mios-simulator-version-min=10.0' option with '--target=x86_64-apple-ios'
+// CHECK-VERSION-TNO-OSV3: "x86_64-apple-ios10.0.0-simulator"
+// CHECK-VERSION-TNO-OSV3-NOT: overriding '-mios-simulator-version-min
// CHECK-VERSION-TNO-OSV3-NOT: argument unused during compilation
// RUN: %clang -target arm64-apple-ios10.1.0 -miphoneos-version-min=10.1.0.1 -c %s -### 2>&1 | \
@@ -235,6 +236,24 @@
// RUN: FileCheck --check-prefix=CHECK-VERSION-TIGNORE-OSV4 %s
// CHECK-VERSION-TIGNORE-OSV4: "thumbv7k-apple-watchos3.0.0"
+// Target without OS version inlcudes the OS given by -m<os>-version-min arguments:
+
+// RUN: %clang -target x86_64-apple-macos -mmacos-version-min=10.11 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-USE-OS-ARG1 %s
+// CHECK-VERSION-USE-OS-ARG1: "x86_64-apple-macosx10.11.0"
+
+// RUN: %clang -target arm64-apple-ios -mios-version-min=9.0 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-USE-OS-ARG2 %s
+// CHECK-VERSION-USE-OS-ARG2: "arm64-apple-ios9.0.0"
+
+// RUN: %clang -target arm64-apple-tvos -mtvos-version-min=10.0 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-USE-OS-ARG3 %s
+// CHECK-VERSION-USE-OS-ARG3: "arm64-apple-tvos10.0.0"
+
+// RUN: %clang -target armv7k-apple-watchos -mwatchos-version-min=4 -c %s -### 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-VERSION-USE-OS-ARG4 %s
+// CHECK-VERSION-USE-OS-ARG4: "thumbv7k-apple-watchos4.0.0"
+
// Target with OS version is not overriden by environment variables:
// RUN: env MACOSX_DEPLOYMENT_TARGET=10.1 \
More information about the cfe-commits
mailing list