AsmPrinter: Fix wrong OS X versions being emitted for darwin triples
authorMatthias Braun <matze@braunis.de>
Wed, 13 Jan 2016 01:18:13 +0000 (01:18 +0000)
committerMatthias Braun <matze@braunis.de>
Wed, 13 Jan 2016 01:18:13 +0000 (01:18 +0000)
The version numbers of the darwin kernel are different from the version
numbers of OS X, so we need adjustments if we had "*-*-darwin" triples.
Use the existing utility functions in TargetTriple for this.

Fixes rdar://22056966

Differential Revision: http://reviews.llvm.org/D14601

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

lib/CodeGen/AsmPrinter/AsmPrinter.cpp
test/CodeGen/X86/2008-11-03-F80VAARG.ll
test/CodeGen/X86/version_directive.ll [new file with mode: 0644]

index be7eafbeb83dda71d5676ecd2c4e8494f78f1bc7..5f67d3daa97fd0a90171189985ee1ebc3986d50e 100644 (file)
@@ -192,22 +192,26 @@ bool AsmPrinter::doInitialization(Module &M) {
   // use the directive, where it would need the same conditionalization
   // anyway.
   Triple TT(getTargetTriple());
-  if (TT.isOSDarwin()) {
+  // If there is a version specified, Major will be non-zero.
+  if (TT.isOSDarwin() && TT.getOSMajorVersion() != 0) {
     unsigned Major, Minor, Update;
-    TT.getOSVersion(Major, Minor, Update);
-    // If there is a version specified, Major will be non-zero.
-    if (Major) {
-      MCVersionMinType VersionType;
-      if (TT.isWatchOS())
-        VersionType = MCVM_WatchOSVersionMin;
-      else if (TT.isTvOS())
-        VersionType = MCVM_TvOSVersionMin;
-      else if (TT.isMacOSX())
-        VersionType = MCVM_OSXVersionMin;
-      else
-        VersionType = MCVM_IOSVersionMin;
-      OutStreamer->EmitVersionMin(VersionType, Major, Minor, Update);
+    MCVersionMinType VersionType;
+    if (TT.isWatchOS()) {
+      VersionType = MCVM_WatchOSVersionMin;
+      TT.getWatchOSVersion(Major, Minor, Update);
+    } else if (TT.isTvOS()) {
+      VersionType = MCVM_TvOSVersionMin;
+      TT.getiOSVersion(Major, Minor, Update);
+    } else if (TT.isMacOSX()) {
+      VersionType = MCVM_OSXVersionMin;
+      if (!TT.getMacOSXVersion(Major, Minor, Update))
+        Major = 0;
+    } else {
+      VersionType = MCVM_IOSVersionMin;
+      TT.getiOSVersion(Major, Minor, Update);
     }
+    if (Major != 0)
+      OutStreamer->EmitVersionMin(VersionType, Major, Minor, Update);
   }
 
   // Allow the target to emit any magic that it wants at the start of the file.
index 507799b7304fb740909c703f00032dc0b741189c..97c046c864261c150ee20a3e31533bde8217faaa 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=x86 -o - | not grep 10
+; RUN: llc < %s -march=x86 -o - | FileCheck %s
 
 declare void @llvm.va_start(i8*) nounwind
 
@@ -6,6 +6,8 @@ declare void @llvm.va_copy(i8*, i8*) nounwind
 
 declare void @llvm.va_end(i8*) nounwind
 
+; CHECK-LABEL: test:
+; CHECK-NOT: 10
 define x86_fp80 @test(...) nounwind {
        %ap = alloca i8*                ; <i8**> [#uses=3]
        %v1 = bitcast i8** %ap to i8*           ; <i8*> [#uses=1]
diff --git a/test/CodeGen/X86/version_directive.ll b/test/CodeGen/X86/version_directive.ll
new file mode 100644 (file)
index 0000000..8e4e6dc
--- /dev/null
@@ -0,0 +1,4 @@
+; RUN: llc -mtriple x86_64-apple-darwin15.0.0 -o - /dev/null | FileCheck %s
+; RUN: llc -mtriple x86_64-apple-macosx10.11.0 -o - /dev/null | FileCheck %s
+
+; CHECK: .macosx_version_min 10, 11