diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-11-29 20:58:50 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-11-29 20:58:50 +0000 |
commit | e03245246acbec5c46e93b68ec6942ce42b9e256 (patch) | |
tree | cb4d0ae874c7b690a8d2ee2bf30a7b2ba424719b | |
parent | 4cbe3b64be7b1b312e4e555e8c93ef8e5bd3a820 (diff) |
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
-rw-r--r-- | include/clang/Frontend/CompilerInvocation.h | 8 | ||||
-rw-r--r-- | lib/Driver/CC1Options.cpp | 12 | ||||
-rw-r--r-- | tools/driver/cc1_main.cpp | 5 |
3 files changed, 19 insertions, 6 deletions
diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index 76863d4ae0..e7c51aabba 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -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. diff --git a/lib/Driver/CC1Options.cpp b/lib/Driver/CC1Options.cpp index 6f0aa26af7..feadae0a90 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 @@ 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); diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index 5097c25832..3b8757b528 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -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) { |