[PATCH] D14999: MC: Warn on .xxx_version_min <-> target triple version mismatch

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 14:34:27 PST 2015


MatzeB created this revision.
MatzeB added reviewers: t.p.northover, steven_wu, grosbach.
MatzeB added a subscriber: llvm-commits.
MatzeB set the repository for this revision to rL LLVM.

Warn if the .{ios|tvos|macosx|watchos}_version_min version does not match the target triple.

Repository:
  rL LLVM

http://reviews.llvm.org/D14999

Files:
  lib/MC/MCParser/DarwinAsmParser.cpp
  test/MC/MachO/ARM/version-min-diagnostics3.s

Index: test/MC/MachO/ARM/version-min-diagnostics3.s
===================================================================
--- /dev/null
+++ test/MC/MachO/ARM/version-min-diagnostics3.s
@@ -0,0 +1,22 @@
+// RUN: llvm-mc -triple armv7s-apple-ios %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=VNONE %s
+// RUN: llvm-mc -triple armv7s-apple-ios9.0.1 %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=VNINE --check-prefix=VNINE_MICRO %s
+// RUN: llvm-mc -triple armv7s-apple-ios9.0 %s 2>&1 | FileCheck --check-prefix=CHECK --check-prefix=VNINE --check-prefix=VNINE_NOMICRO %s
+
+// VNONE-NOT: version-min-diagnostics3.s:[[@LINE+2]]{{.*}}does not match target version
+// VNINE: version-min-diagnostics3.s:[[@LINE+1]]:1: warning: .ios_version_min 8,0,0 does not match target version 9,
+.ios_version_min 8,0
+// VNONE-NOT: version-min-diagnostics3.s:[[@LINE+2]]{{.*}}does not match target version
+// VNINE: version-min-diagnostics3.s:[[@LINE+1]]:1: warning: .ios_version_min 10,0,0 does not match target version 9,
+.ios_version_min 10,0
+// VNONE-NOT: version-min-diagnostics3.s:[[@LINE+2]]{{.*}}does not match target version
+// VNINE: version-min-diagnostics3.s:[[@LINE+1]]:1: warning: .ios_version_min 9,1,0 does not match target version 9,
+.ios_version_min 9,1
+// VNONE-NOT: version-min-diagnostics3.s:[[@LINE+3]]{{.*}}does not match target version
+// VNINE_NOMICRO-NOT: version-min-diagnostics3.s:[[@LINE+2]]{{.*}}does not match target version
+// VNINE_MICRO: version-min-diagnostics3.s:[[@LINE+1]]:1: warning: .ios_version_min 9,0,2 does not match target version 9,0,1
+.ios_version_min 9,0,2
+
+// CHECK-NOT: version-min-diagnostics3.s:[[@LINE+1]]{{.*}}does not match target version
+.ios_version_min 9,0
+// CHECK-NOT: version-min-diagnostics3.s:[[@LINE+1]]{{.*}}does not match target version
+.ios_version_min 9,0,1
Index: lib/MC/MCParser/DarwinAsmParser.cpp
===================================================================
--- lib/MC/MCParser/DarwinAsmParser.cpp
+++ lib/MC/MCParser/DarwinAsmParser.cpp
@@ -942,9 +942,22 @@
   case MCVM_IOSVersionMin:     ExpectedOS = Triple::IOS;     break;
   case MCVM_OSXVersionMin:     ExpectedOS = Triple::MacOSX;  break;
   }
-  if (T.getOS() != ExpectedOS)
+  if (T.getOS() != ExpectedOS) {
     Warning(Loc, Directive + " should only be used for " +
             Triple::getOSTypeName(ExpectedOS) + " targets");
+  } else {
+    // Check if target triple version matches the one in the directive.
+    unsigned TripleMajor, TripleMinor, TripleMicro;
+    T.getOSVersion(TripleMajor, TripleMinor, TripleMicro);
+    if ((TripleMajor != 0 || TripleMinor != 0 || TripleMicro != 0) &&
+        (Major != TripleMajor || Minor != TripleMinor ||
+         (Update != 0 && TripleMicro != 0 && Update != TripleMicro))) {
+      Warning(Loc, Twine(Directive) + " " + Twine(Major) + "," + Twine(Minor) +
+              "," + Twine(Update) + " does not match target version " +
+              Twine(TripleMajor) + "," + Twine(TripleMinor) + "," +
+              Twine(TripleMicro));
+    }
+  }
 
   if (LastVersionMinDirective.isValid()) {
     Warning(Loc, "overriding previous version_min directive");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D14999.41187.patch
Type: text/x-patch
Size: 3163 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151125/99b5bddb/attachment.bin>


More information about the llvm-commits mailing list