[PATCH] D17453: [Driver] Enable --rtlib option for MSVC target

Roman Shirokiy via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 10 03:56:50 PST 2016


roman.shirokiy updated this revision to Diff 50260.
roman.shirokiy added a comment.

Updated diff with the test for "nostdlib" + "rtlib" case.


http://reviews.llvm.org/D17453

Files:
  lib/Driver/Tools.cpp
  test/Driver/msvc-compiler-rt.c
  test/Driver/nostdlib.c

Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -8945,10 +8945,20 @@
       break;
     }
     break;
-  case ToolChain::RLT_Libgcc:
-    AddLibgcc(TC.getTriple(), D, CmdArgs, Args);
-    break;
-  }
+    case ToolChain::RLT_Libgcc:
+      // Make sure libgcc is not used under MSVC environment by default
+      if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
+         // Issue error diagnostic if libgcc is explicitly specified 
+         // through command line as --rtlib option argument.
+         if (Args.hasArg(options::OPT_rtlib_EQ)) {
+           TC.getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform)
+               << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "MSVC";
+         }    
+      }
+      else   
+        AddLibgcc(TC.getTriple(), D, CmdArgs, Args);
+      break;
+    }
 }
 
 static const char *getLDMOption(const llvm::Triple &T, const ArgList &Args) {
@@ -9752,6 +9762,12 @@
     }
   }
 
+  // Add compiler-rt lib in case if it was explicitly
+  // specified as an argument for --rtlib option.
+  if (!Args.hasArg(options::OPT_nostdlib)) {
+    AddRunTimeLibs(TC, TC.getDriver(), CmdArgs, Args);
+  }
+
   // Add filenames, libraries, and other linker inputs.
   for (const auto &Input : Inputs) {
     if (Input.isFilename()) {
Index: test/Driver/nostdlib.c
===================================================================
--- test/Driver/nostdlib.c
+++ test/Driver/nostdlib.c
@@ -22,6 +22,10 @@
 // RUN:     -resource-dir=%S/Inputs/resource_dir -lclang_rt.builtins-i686 \
 // RUN:   | FileCheck --check-prefix=CHECK-LINUX-NOSTDLIB %s
 //
+// RUN: %clang -target x86_64-pc-windows-msvc -nostdlib --rtlib=compiler-rt -### %s 2>&1 | FileCheck %s -check-prefix CHECK-MSVC-NOSTDLIB
+// RUN: %clang -target x86_64-pc-windows-msvc --rtlib=compiler-rt -nostdlib -### %s 2>&1 | FileCheck %s -check-prefix CHECK-MSVC-NOSTDLIB
+//
 // CHECK-LINUX-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
 // CHECK-LINUX-NOSTDLIB: "{{(.*[^.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-LINUX-NOSTDLIB-NOT: "{{.*}}/Inputs/resource_dir{{/|\\\\}}lib{{/|\\\\}}linux{{/|\\\\}}libclang_rt.builtins-i686.a"
+// CHECK-MSVC-NOSTDLIB: warning: argument unused during compilation: '--rtlib=compiler-rt'
Index: test/Driver/msvc-compiler-rt.c
===================================================================
--- test/Driver/msvc-compiler-rt.c
+++ test/Driver/msvc-compiler-rt.c
@@ -0,0 +1,5 @@
+// RUN: %clang -target x86_64-pc-windows-msvc --rtlib=compiler-rt -### %s 2>&1 | FileCheck %s -check-prefix MSVC-COMPILER-RT
+// RUN: not %clang %s -target x86_64-pc-windows-msvc --rtlib=libgcc 2>&1 | FileCheck %s -check-prefix CHECK-ERROR
+
+// MSVC-COMPILER-RT: "{{.*}}clang_rt.builtins{{.*}}"
+// CHECK-ERROR: unsupported runtime library 'libgcc' for platform 'MSVC'


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17453.50260.patch
Type: text/x-patch
Size: 2922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160310/02796945/attachment.bin>


More information about the cfe-commits mailing list