Change CompilerInvocation::CreateFromArgs to report errors using a proper diagnostic engine.
 - Clients that care about having the diagnostics output honor the user-controllable diagnostic options can buffer the diagnostics and issue them later.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90092 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/CC1Options.cpp b/lib/Driver/CC1Options.cpp
index 6f0aa26..feadae0 100644
--- a/lib/Driver/CC1Options.cpp
+++ b/lib/Driver/CC1Options.cpp
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "clang/Driver/CC1Options.h"
+#include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/Version.h"
 #include "clang/Driver/ArgList.h"
 #include "clang/Driver/Arg.h"
@@ -662,7 +663,8 @@
                                         const char **ArgBegin,
                                         const char **ArgEnd,
                                         const char *Argv0,
-                                        void *MainAddr) {
+                                        void *MainAddr,
+                                        Diagnostic &Diags) {
   // Parse the arguments.
   llvm::OwningPtr<OptTable> Opts(createCC1OptTable());
   unsigned MissingArgIndex, MissingArgCount;
@@ -678,6 +680,14 @@
                  << " value )\n";
   }
 
+  // Issue errors on unknown arguments.
+  for (arg_iterator it = InputArgs->filtered_begin(OPT_UNKNOWN),
+         ie = InputArgs->filtered_end(); it != ie; ++it) {
+    unsigned ID = Diags.getCustomDiagID(Diagnostic::Error,
+                                        "unknown argument: '%0'");
+    Diags.Report(ID) << it->getAsString(*InputArgs);
+  }
+
   ParseAnalyzerArgs(Res.getAnalyzerOpts(), *InputArgs);
   ParseCodeGenArgs(Res.getCodeGenOpts(), *InputArgs);
   ParseDependencyOutputArgs(Res.getDependencyOutputOpts(), *InputArgs);