summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/plugin.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-10-29 22:53:33 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-10-30 07:14:17 +0100
commit1136ed6c5112018af08f8ac703070cc195389b40 (patch)
tree149b884147725a6df32e35301eb40e657121aa86 /compilerplugins/clang/plugin.cxx
parentloplugin:finalclasses svtools (diff)
downloadcore-1136ed6c5112018af08f8ac703070cc195389b40.tar.gz
core-1136ed6c5112018af08f8ac703070cc195389b40.zip
Fix Plugin::containsPreprocessingConditionalInclusion
...which had been broken since dfc0dc4801707b2d8080af1540625b43bd463e17 "loplugin:casttovoid: fix containsPreprocessingConditionalInclusion()", and, when range.getEnd() was a macro loc, would typically have wandered off past the end of the intended range, until it would have encountered some #if etc. and erroneously returned true. Fixed the fallout across the code base. While at it, added a clarifying comment and made the "lexing fails" cases that should never happen fail with a fatal error in debug mode. Change-Id: Ieff44548384426d7716b6fc6c836c9069d878729 Reviewed-on: https://gerrit.libreoffice.org/81721 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/plugin.cxx')
-rw-r--r--compilerplugins/clang/plugin.cxx26
1 files changed, 21 insertions, 5 deletions
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 6839fec0a836..01484bddc432 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -285,6 +285,8 @@ bool Plugin::isUnitTestMode()
bool Plugin::containsPreprocessingConditionalInclusion(SourceRange range)
{
+ // Preprocessing directives (other than _Pragma, which is not relevant here) cannot appear in
+ // macro expansions, so it is safe to just consider the range of expansion locations:
auto const begin = compiler.getSourceManager().getExpansionLoc(
range.getBegin());
auto const end = compiler.getSourceManager().getExpansionLoc(
@@ -294,8 +296,15 @@ bool Plugin::containsPreprocessingConditionalInclusion(SourceRange range)
|| compiler.getSourceManager().isBeforeInTranslationUnit(
begin, end)))
{
- // Conservatively assume "yes" if lexing fails (e.g., due to
- // macros):
+ if (isDebugMode()) {
+ report(
+ DiagnosticsEngine::Fatal,
+ ("unexpected broken range for Plugin::containsPreprocessingConditionalInclusion,"
+ " case 1"),
+ range.getBegin())
+ << range;
+ }
+ // Conservatively assume "yes" if lexing fails:
return true;
}
auto hash = false;
@@ -305,8 +314,15 @@ bool Plugin::containsPreprocessingConditionalInclusion(SourceRange range)
loc, tok, compiler.getSourceManager(),
compiler.getLangOpts(), true))
{
- // Conservatively assume "yes" if lexing fails (e.g., due to
- // macros):
+ if (isDebugMode()) {
+ report(
+ DiagnosticsEngine::Fatal,
+ ("unexpected broken range for"
+ " Plugin::containsPreprocessingConditionalInclusion, case 2"),
+ loc)
+ << range;
+ }
+ // Conservatively assume "yes" if lexing fails:
return true;
}
if (hash && tok.is(tok::raw_identifier)) {
@@ -317,7 +333,7 @@ bool Plugin::containsPreprocessingConditionalInclusion(SourceRange range)
return true;
}
}
- if (loc == range.getEnd()) {
+ if (loc == end) {
break;
}
hash = tok.is(tok::hash) && tok.isAtStartOfLine();