Driver: Generate an error when trying to pass an LLVM bc input to a
non-Darwin linker (sorry Gold + LTO-plugin users).


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td
index ced7cea..8a0616b 100644
--- a/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/include/clang/Basic/DiagnosticDriverKinds.td
@@ -41,6 +41,8 @@
   "invalid argument '%0' not allowed with '%1'">;
 def err_drv_invalid_version_number : Error<
   "invalid version number in '%0'">;
+def err_drv_no_linker_llvm_support : Error<
+  "'%0': unable to pass LLVM bit-code files to linker">;
 
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input unused when '%2' is present">;
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index c862228..d79f850 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -608,6 +608,7 @@
                                const InputInfoList &Inputs,
                                const ArgList &Args,
                                const char *LinkingOutput) const {
+  const Driver &D = getToolChain().getHost().getDriver();
   ArgStringList CmdArgs;
 
   for (ArgList::const_iterator
@@ -660,6 +661,12 @@
   for (InputInfoList::const_iterator
          it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
     const InputInfo &II = *it;
+
+    // Don't try to pass LLVM inputs to a generic gcc.
+    if (II.getType() == types::TY_LLVMBC)
+      D.Diag(clang::diag::err_drv_no_linker_llvm_support)
+        << getToolChain().getTripleString().c_str();
+
     if (types::canTypeBeUserSpecified(II.getType())) {
       CmdArgs.push_back("-x");
       CmdArgs.push_back(types::getTypeName(II.getType()));
@@ -1726,8 +1733,8 @@
                                  Job &Dest, const InputInfo &Output,
                                  const InputInfoList &Inputs,
                                  const ArgList &Args,
-                                 const char *LinkingOutput) const
-{
+                                 const char *LinkingOutput) const {
+  const Driver &D = getToolChain().getHost().getDriver();
   ArgStringList CmdArgs;
 
   if (Args.hasArg(options::OPT_static)) {
@@ -1778,6 +1785,12 @@
   for (InputInfoList::const_iterator
          it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
     const InputInfo &II = *it;
+
+    // Don't try to pass LLVM inputs to a generic gcc.
+    if (II.getType() == types::TY_LLVMBC)
+      D.Diag(clang::diag::err_drv_no_linker_llvm_support)
+        << getToolChain().getTripleString().c_str();
+
     if (II.isPipe())
       CmdArgs.push_back("-");
     else if (II.isFilename())
@@ -1871,6 +1884,7 @@
                                  const InputInfoList &Inputs,
                                  const ArgList &Args,
                                  const char *LinkingOutput) const {
+  const Driver &D = getToolChain().getHost().getDriver();
   ArgStringList CmdArgs;
 
   if (Args.hasArg(options::OPT_static)) {
@@ -1920,6 +1934,12 @@
   for (InputInfoList::const_iterator
          it = Inputs.begin(), ie = Inputs.end(); it != ie; ++it) {
     const InputInfo &II = *it;
+
+    // Don't try to pass LLVM inputs to a generic gcc.
+    if (II.getType() == types::TY_LLVMBC)
+      D.Diag(clang::diag::err_drv_no_linker_llvm_support)
+        << getToolChain().getTripleString().c_str();
+
     if (II.isPipe())
       CmdArgs.push_back("-");
     else if (II.isFilename())
diff --git a/test/Driver/emit-llvm.c b/test/Driver/emit-llvm.c
new file mode 100644
index 0000000..a4aabe7
--- /dev/null
+++ b/test/Driver/emit-llvm.c
@@ -0,0 +1,3 @@
+// RUN: not clang -ccc-host-triple i386-pc-linux-gnu -emit-llvm -o %t %s 2> %t.log &&
+// RUN: grep 'unable to pass LLVM bit-code files to linker' %t.log
+