Add clang -cc1 -load option.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90413 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index 2899684..b189b4b 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -42,6 +42,7 @@
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
+#include "llvm/System/DynamicLibrary.h"
 #include "llvm/System/Host.h"
 #include "llvm/System/Path.h"
 #include "llvm/System/Signals.h"
@@ -299,7 +300,8 @@
                                    Clang.getDiagnostics(), argv[0]))
     return 1;
 #else
-  // Buffer diagnostics from argument parsing.
+  // Buffer diagnostics from argument parsing so that we can output them using a
+  // well formed diagnostic object.
   TextDiagnosticBuffer DiagsBuffer;
   Diagnostic Diags(&DiagsBuffer);
 
@@ -321,6 +323,15 @@
 
   DiagsBuffer.FlushDiagnostics(Clang.getDiagnostics());
 
+  // Load any requested plugins.
+  for (unsigned i = 0,
+         e = Clang.getFrontendOpts().Plugins.size(); i != e; ++i) {
+    const std::string &Path = Clang.getFrontendOpts().Plugins[i];
+    std::string Error;
+    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+      Diags.Report(diag::err_fe_unable_to_load_plugin) << Path << Error;
+  }
+
   // If there were any errors in processing arguments, exit now.
   if (Clang.getDiagnostics().getNumErrors())
     return 1;