diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-07-04 08:14:20 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-07-04 08:15:08 +0200 |
commit | dfc0dc4801707b2d8080af1540625b43bd463e17 (patch) | |
tree | 7cbf1a030732d577eeba54c28852aaf3c41add9c /compilerplugins | |
parent | f1cef09fcda11e321f8b01ab4600c28339dec45a (diff) |
loplugin:casttovoid: fix containsPreprocessingConditionalInclusion()
...and re-enable plugin
Change-Id: I0b42cfc0f0b45711e714e6661ae9dd39f05f8960
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/casttovoid.cxx | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/compilerplugins/clang/casttovoid.cxx b/compilerplugins/clang/casttovoid.cxx index 37608adcdc3f..01d1e65e3363 100644 --- a/compilerplugins/clang/casttovoid.cxx +++ b/compilerplugins/clang/casttovoid.cxx @@ -390,8 +390,21 @@ private: } bool containsPreprocessingConditionalInclusion(SourceRange range) { + auto const begin = compiler.getSourceManager().getExpansionLoc( + range.getBegin()); + auto const end = compiler.getSourceManager().getExpansionLoc( + range.getEnd()); + assert(begin.isFileID() && end.isFileID()); + if (!(begin == end + || compiler.getSourceManager().isBeforeInTranslationUnit( + begin, end))) + { + // Conservatively assume "yes" if lexing fails (e.g., due to + // macros): + return true; + } auto hash = false; - for (auto loc = range.getBegin();;) { + for (auto loc = begin;;) { Token tok; if (Lexer::getRawToken( loc, tok, compiler.getSourceManager(), @@ -487,7 +500,7 @@ private: } }; -static loplugin::Plugin::Registration<Visitor> reg("casttovoid", false); +static loplugin::Plugin::Registration<Visitor> reg("casttovoid"); } |