summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/casttovoid.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/casttovoid.cxx')
-rw-r--r--compilerplugins/clang/casttovoid.cxx23
1 files changed, 17 insertions, 6 deletions
diff --git a/compilerplugins/clang/casttovoid.cxx b/compilerplugins/clang/casttovoid.cxx
index 1717fa09a516..87c2f4852aac 100644
--- a/compilerplugins/clang/casttovoid.cxx
+++ b/compilerplugins/clang/casttovoid.cxx
@@ -203,6 +203,9 @@ public:
if (var == nullptr) {
return true;
}
+ if (var->getType().isVolatileQualified()) {
+ return true;
+ }
auto & usage = vars_[var->getCanonicalDecl()];
if (!castToVoid_.empty() && castToVoid_.top().sub == expr) {
usage.castToVoid.push_back(castToVoid_.top().cast);
@@ -423,6 +426,11 @@ private:
}
}
} else {
+ if (auto const fun = dyn_cast_or_null<FunctionDecl>(i.first->getDeclContext())) {
+ if (containsPreprocessingConditionalInclusion(fun->getSourceRange())) {
+ continue;
+ }
+ }
for (auto const j: i.second.castToVoid) {
report(
DiagnosticsEngine::Warning, "unnecessary cast to void",
@@ -439,10 +447,10 @@ private:
bool isFromCIncludeFile(SourceLocation spellingLocation) const {
return !compiler.getSourceManager().isInMainFile(spellingLocation)
- && (StringRef(
- compiler.getSourceManager().getPresumedLoc(spellingLocation)
- .getFilename())
- .endswith(".h"));
+ && compat::ends_with(
+ StringRef(
+ compiler.getSourceManager().getPresumedLoc(spellingLocation).getFilename()),
+ ".h");
}
bool isSharedCAndCppCode(VarDecl const * decl) const {
@@ -464,7 +472,7 @@ private:
return nullptr;
}
if (compiler.getSourceManager().isMacroBodyExpansion(
- compat::getBeginLoc(expr)))
+ expr->getBeginLoc()))
{
return nullptr;
}
@@ -507,11 +515,14 @@ private:
if (var == nullptr) {
return;
}
+ if (var->getType().isVolatileQualified()) {
+ return;
+ }
auto & usage = vars_[var->getCanonicalDecl()];
if (usage.firstConsumption != nullptr) {
return;
}
- auto const loc = compat::getBeginLoc(dre);
+ auto const loc = dre->getBeginLoc();
if (compiler.getSourceManager().isMacroArgExpansion(loc)
&& (Lexer::getImmediateMacroNameForDiagnostics(
loc, compiler.getSourceManager(), compiler.getLangOpts())