]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
dwarflint: Warn about --check rules that never match
authorPetr Machata <pmachata@redhat.com>
Wed, 15 Sep 2010 18:32:23 +0000 (20:32 +0200)
committerPetr Machata <pmachata@redhat.com>
Wed, 15 Sep 2010 18:32:23 +0000 (20:32 +0200)
dwarflint/checkrule.cc
dwarflint/checkrule.hh
dwarflint/main.cc
dwarflint/tests/run-nodebug.sh

index 44e7a370475469eeefe907bc21bf7ce615e3f2f8..051d73777ae7c02a79aa9d8fff64d747d6f7b497 100644 (file)
 checkrule::checkrule (std::string const &a_name, action_t an_action)
   : _m_name (a_name)
   , _m_action (an_action)
+  , _m_used (false)
 {
 }
 
+checkrule_internal::checkrule_internal (std::string const &a_name,
+                                       action_t an_action)
+  : checkrule (a_name, an_action)
+{
+  mark_used ();
+}
+
 namespace
 {
   bool
@@ -72,13 +80,14 @@ checkrules::should_check (checkstack const &stack) const
     {
       std::string const &rule_name = it->name ();
       bool nflag = it->action () == checkrule::request;
-      if (nflag == should)
+      if (nflag == should && it->used ())
        continue;
 
       for (checkstack::const_iterator jt = stack.begin ();
           jt != stack.end (); ++jt)
        if (rule_matches (rule_name, **jt))
          {
+           it->mark_used ();
            //std::cout << " rule: " << rule_name << " " << nflag << std::endl;
            should = nflag;
            break;
index 1171f08b4e304f58c0e6e4f508b87173e48ecf25..6b121b61cf99540d9d0cdc3d273a5f6f60998acf 100644 (file)
@@ -41,12 +41,23 @@ struct checkrule
 private:
   std::string _m_name;
   action_t _m_action;
+  mutable bool _m_used;
 
 public:
   checkrule (std::string const &name, action_t action);
 
   std::string const &name () const { return _m_name; }
   action_t action () const { return _m_action; }
+  bool used () const { return _m_used; }
+  void mark_used () const { _m_used = true; }
+};
+
+// These are like normal rules, but they are initially marked as used
+// so as not to be warned about.
+struct checkrule_internal
+  : public checkrule
+{
+  checkrule_internal (std::string const &name, action_t action);
 };
 
 class checkrules
index d349892ef3a493103ee01dec4e2c94588e9911c5..5a3aa2cda1c0d8547562c6083974b11cee97655e 100644 (file)
@@ -52,8 +52,8 @@ struct check_option_t
     : public checkrules
   {
     initial_checkrules () {
-      push_back (checkrule ("@all", checkrule::request));
-      push_back (checkrule ("@nodefault", checkrule::forbid));
+      push_back (checkrule_internal ("@all", checkrule::request));
+      push_back (checkrule_internal ("@nodefault", checkrule::forbid));
     }
   } rules;
 
@@ -218,5 +218,11 @@ main (int argc, char *argv[])
     }
   while (++remaining < argc);
 
+  for (checkrules::const_iterator it = check_option.rules.begin ();
+       it != check_option.rules.end (); ++it)
+    if (!it->used ())
+      std::cerr << "warning: the rule `" << it->name ()
+               << "' never matched." << std::endl;
+
   return error_count != 0;
 }
index a595433c0c2943378b975af058731d712ebfaa4c..346d9d8cbfde183e3ce24d5ccb3b39aff09ac2f1 100755 (executable)
@@ -40,3 +40,9 @@ EOF
 
 testrun_compare ./dwarflint -q -i nodebug <<EOF
 EOF
+
+# This has nothing to do with the nodebug test, but we can just as
+# well stick it in there.
+testrun_compare ./dwarflint --check=oentuh -q nodebug <<EOF
+warning: the rule \`oentuh' never matched.
+EOF