[darwin][driver] Warn about mismatching -<os>-version-min rather than
authorAlex Lorenz <arphaman@gmail.com>
Wed, 20 Dec 2017 02:31:30 +0000 (02:31 +0000)
committerAlex Lorenz <arphaman@gmail.com>
Wed, 20 Dec 2017 02:31:30 +0000 (02:31 +0000)
superfluous -<os>-version-min compiler option

rdar://35813850

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

llvm-svn: 321145

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

index 3d53a17..289f4ed 100644 (file)
@@ -1523,12 +1523,29 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   Optional<DarwinPlatform> OSTarget =
       getDeploymentTargetFromTargetArg(Args, getTriple(), getDriver());
   if (OSTarget) {
-    // Warn about superfluous -m<os>-version-min arg.
     Optional<DarwinPlatform> OSVersionArgTarget =
         getDeploymentTargetFromOSVersionArg(Args, getDriver());
-    if (OSVersionArgTarget)
-      getDriver().Diag(clang::diag::warn_drv_unused_argument)
-          << OSVersionArgTarget->getAsString(Args, Opts);
+    if (OSVersionArgTarget) {
+      unsigned TargetMajor, TargetMinor, TargetMicro;
+      bool TargetExtra;
+      unsigned ArgMajor, ArgMinor, ArgMicro;
+      bool ArgExtra;
+      if (OSTarget->getPlatform() != OSVersionArgTarget->getPlatform() ||
+          (Driver::GetReleaseVersion(OSTarget->getOSVersion(), TargetMajor,
+                                     TargetMinor, TargetMicro, TargetExtra) &&
+           Driver::GetReleaseVersion(OSVersionArgTarget->getOSVersion(),
+                                     ArgMajor, ArgMinor, ArgMicro, ArgExtra) &&
+           (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;
+      }
+    }
   } else {
     // The OS target can be specified using the -m<os>version-min argument.
     OSTarget = getDeploymentTargetFromOSVersionArg(Args, getDriver());
index e67e34f..4a9cdf9 100644 (file)
 
 // RUN: %clang -target x86_64-apple-macos10.11.2 -mmacos-version-min=10.6 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TNO-OSV1 %s
-// CHECK-VERSION-TNO-OSV1: argument unused during compilation: '-mmacosx-version-min=10.6'
+// CHECK-VERSION-TNO-OSV1: overriding '-mmacosx-version-min=10.6' option with '--target=x86_64-apple-macos10.11.2'
 
 // RUN: %clang -target x86_64-apple-macos -miphoneos-version-min=9.1 -c %s -### 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK-VERSION-TNO-OSV2 %s
-// CHECK-VERSION-TNO-OSV2: argument unused during compilation: '-miphoneos-version-min=9.1'
+// CHECK-VERSION-TNO-OSV2: overriding '-miphoneos-version-min=9.1' option with '--target=x86_64-apple-macos'
+
+// 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-NOT: argument unused during compilation
+
+// RUN: %clang -target arm64-apple-ios10.1.0 -miphoneos-version-min=10.1.0.1 -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TNO-OSV4 %s
+// CHECK-VERSION-TNO-OSV4: overriding '-miphoneos-version-min=10.1.0.1' option with '--target=arm64-apple-ios10.1.0'
+
+// RUN: %clang -target x86_64-apple-macos10.6 -mmacos-version-min=10.6 -c %s -### 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK-VERSION-TNO-SAME %s
+// CHECK-VERSION-TNO-SAME-NOT: overriding
+// CHECK-VERSION-TNO-SAME-NOT: argument unused during compilation
 
 // Target with OS version is not overriden by -m<os>-version-min variables: