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 | fcb9caa7726eda3194029d846213a524a60b640f (patch) | |
tree | 323bdd68ded7096c58b3d9566174d8c4aa68f2c9 /clang | |
parent | ecd0444e8cac6e04972fea7661591f164a5849c8 (diff) | |
download | bcm5719-llvm-fcb9caa7726eda3194029d846213a524a60b640f.tar.gz bcm5719-llvm-fcb9caa7726eda3194029d846213a524a60b640f.zip |
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.
llvm-svn: 90092
Diffstat (limited to 'clang')
-rw-r--r-- | clang/include/clang/Frontend/CompilerInvocation.h | 8 | ||||
-rw-r--r-- | clang/lib/Driver/CC1Options.cpp | 12 | ||||
-rw-r--r-- | clang/tools/driver/cc1_main.cpp | 5 |
3 files changed, 19 insertions, 6 deletions
diff --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h index 76863d4ae07..e7c51aabba5 100644 --- a/clang/include/clang/Frontend/CompilerInvocation.h +++ b/clang/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/clang/lib/Driver/CC1Options.cpp b/clang/lib/Driver/CC1Options.cpp index 6f0aa26af7e..feadae0a90a 100644 --- a/clang/lib/Driver/CC1Options.cpp +++ b/clang/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/clang/tools/driver/cc1_main.cpp b/clang/tools/driver/cc1_main.cpp index 5097c25832d..3b8757b5280 100644 --- a/clang/tools/driver/cc1_main.cpp +++ b/clang/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) { |