]> granicus.if.org Git - clang/commitdiff
Change CompilerInvocation::CreateFromArgs to report errors using a proper diagnostic...
authorDaniel Dunbar <daniel@zuster.org>
Sun, 29 Nov 2009 20:58:50 +0000 (20:58 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 29 Nov 2009 20:58:50 +0000 (20:58 +0000)
 - 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

include/clang/Frontend/CompilerInvocation.h
lib/Driver/CC1Options.cpp
tools/driver/cc1_main.cpp

index 76863d4ae07101e46b4820e74acda9a4a7915c1a..e7c51aabba59ebb0c1b7518952203c8890a21edf 100644 (file)
@@ -31,6 +31,8 @@ namespace llvm {
 
 namespace clang {
 
+class Diagnostic;
+
 /// CompilerInvocation - Helper class for holding the data necessary to invoke
 /// the compiler.
 ///
@@ -77,8 +79,6 @@ public:
   /// CreateFromArgs - Create a compiler invocation from a list of input
   /// options.
   ///
-  /// FIXME: Documenting error behavior.
-  ///
   /// \param Res [out] - The resulting invocation.
   /// \param ArgBegin - The first element in the argument vector.
   /// \param ArgEnd - The last element in the argument vector.
@@ -86,9 +86,11 @@ public:
   /// compiler path.
   /// \param MainAddr - The address of main (or some other function in the main
   /// executable), for finding the builtin compiler path.
+  /// \param Diags - The diagnostic engine to use for errors.
   static void CreateFromArgs(CompilerInvocation &Res, const char **ArgBegin,
                              const char **ArgEnd, const char *Argv0,
-                             void *MainAddr);
+                             void *MainAddr,
+                             Diagnostic &Diags);
 
   /// toArgs - Convert the CompilerInvocation to a list of strings suitable for
   /// passing to CreateFromArgs.
index 6f0aa26af7e7e70e1d339346422facf43810c6ca..feadae0a90ab4bc1993e9379429cda7edd21d9f6 100644 (file)
@@ -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 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
                                         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 @@ void CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
                  << " 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);
index 5097c25832d068225061e127e230a77c68ee429e..3b8757b52804edf6a533347ccac4fd026a99318e 100644 (file)
@@ -53,7 +53,7 @@ int cc1_main(Diagnostic &Diags, const char **ArgBegin, const char **ArgEnd,
   llvm::errs() << "cc1 creating invocation.\n";
   CompilerInvocation Invocation;
   CompilerInvocation::CreateFromArgs(Invocation, ArgBegin, ArgEnd,
-                                     Argv0, MainAddr);
+                                     Argv0, MainAddr, Diags);
 
   // Convert the invocation back to argument strings.
   std::vector<std::string> InvocationArgs;
@@ -72,7 +72,8 @@ int cc1_main(Diagnostic &Diags, const char **ArgBegin, const char **ArgEnd,
   // same thing.
   CompilerInvocation Invocation2;
   CompilerInvocation::CreateFromArgs(Invocation2, Invocation2Args.begin(),
-                                     Invocation2Args.end(), Argv0, MainAddr);
+                                     Invocation2Args.end(), Argv0, MainAddr,
+                                     Diags);
 
   // FIXME: Implement CompilerInvocation comparison.
   if (true) {