From: Petr Machata Date: Wed, 15 Sep 2010 18:32:23 +0000 (+0200) Subject: dwarflint: Warn about --check rules that never match X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=324e64daea1876cb651e3300844c7385717750a7;p=thirdparty%2Felfutils.git dwarflint: Warn about --check rules that never match --- diff --git a/dwarflint/checkrule.cc b/dwarflint/checkrule.cc index 44e7a3704..051d73777 100644 --- a/dwarflint/checkrule.cc +++ b/dwarflint/checkrule.cc @@ -31,9 +31,17 @@ 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; diff --git a/dwarflint/checkrule.hh b/dwarflint/checkrule.hh index 1171f08b4..6b121b61c 100644 --- a/dwarflint/checkrule.hh +++ b/dwarflint/checkrule.hh @@ -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 diff --git a/dwarflint/main.cc b/dwarflint/main.cc index d349892ef..5a3aa2cda 100644 --- a/dwarflint/main.cc +++ b/dwarflint/main.cc @@ -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; } diff --git a/dwarflint/tests/run-nodebug.sh b/dwarflint/tests/run-nodebug.sh index a595433c0..346d9d8cb 100755 --- a/dwarflint/tests/run-nodebug.sh +++ b/dwarflint/tests/run-nodebug.sh @@ -40,3 +40,9 @@ EOF testrun_compare ./dwarflint -q -i nodebug <