]> granicus.if.org Git - clang/commitdiff
Driver: Start warning about unused arguments.
authorDaniel Dunbar <daniel@zuster.org>
Sun, 15 Mar 2009 01:38:15 +0000 (01:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sun, 15 Mar 2009 01:38:15 +0000 (01:38 +0000)
 - This has a number of current flaws, enabling now to flush out
   problems while bringing up other parts.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67015 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticDriverKinds.def
include/clang/Driver/Arg.h
lib/Driver/Driver.cpp

index 006bd34eb676f9525cd0deb652f179d1febb53b1..d825f3c88a5000b23fddfb296e12fa89be056062 100644 (file)
@@ -31,3 +31,5 @@ DIAG(err_drv_use_of_Z_option, ERROR,
 
 DIAG(warn_drv_input_file_unused, WARNING,
      "%0: '%1' input file unused when '%2' is present")
+DIAG(warn_drv_unused_argument, WARNING,
+     "argument unused during compilatin: '%0'")
index a35739f298188bd7f246b1540c27725c79a65506..a8c9bd209765fce9b840780ba84042086f55d8b7 100644 (file)
@@ -72,11 +72,7 @@ namespace driver {
 
     unsigned getIndex() const { return Index; }
 
-    virtual unsigned getNumValues() const = 0;
-    virtual const char *getValue(const ArgList &Args, unsigned N=0) const = 0;
-    
-    /// render - Append the argument onto the given array as strings.
-    virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
+    bool isClaimed() const { return Claimed; }
 
     /// claim - Set the Arg claimed bit.
     
@@ -84,6 +80,12 @@ namespace driver {
     // in the original argument; not the derived one.
     void claim() { Claimed = true; }
 
+    virtual unsigned getNumValues() const = 0;
+    virtual const char *getValue(const ArgList &Args, unsigned N=0) const = 0;
+    
+    /// render - Append the argument onto the given array as strings.
+    virtual void render(const ArgList &Args, ArgStringList &Output) const = 0;
+
     static bool classof(const Arg *) { return true; }    
 
     void dump() const;
index 2aa50180bd2dcd622338e6683b1f4c49da68b9ba..d3993589c3c1155bab182803a2f121bfb85d53bb 100644 (file)
@@ -171,7 +171,21 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
     return 0;
   }
 
-  return BuildJobs(*Args, Actions);
+  Compilation *C = BuildJobs(*Args, Actions);
+
+  // If there were no errors, warn about any unused arguments.
+  for (ArgList::iterator it = Args->begin(), ie = Args->end(); it != ie; ++it) {
+    Arg *A = *it;
+
+    // FIXME: It would be nice to be able to send the argument to the
+    // Diagnostic, so that extra values, position, and so on could be
+    // printed.
+    if (!A->isClaimed())
+      Diag(clang::diag::warn_drv_unused_argument) 
+        << A->getOption().getName();
+  }
+
+  return C;
 }
 
 void Driver::PrintOptions(const ArgList &Args) const {
@@ -563,7 +577,6 @@ Action *Driver::ConstructPhaseAction(const ArgList &Args, phases::ID Phase,
 
 Compilation *Driver::BuildJobs(const ArgList &Args, 
                                const ActionList &Actions) const {
-  assert(0 && "FIXME: Implement");
   return 0;
 }