summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/casttovoid.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/casttovoid.cxx')
-rw-r--r--compilerplugins/clang/casttovoid.cxx51
1 files changed, 31 insertions, 20 deletions
diff --git a/compilerplugins/clang/casttovoid.cxx b/compilerplugins/clang/casttovoid.cxx
index 1717fa09a516..4026162ea0c1 100644
--- a/compilerplugins/clang/casttovoid.cxx
+++ b/compilerplugins/clang/casttovoid.cxx
@@ -20,20 +20,6 @@
namespace {
-bool isWarnUnusedType(QualType type) {
- if (auto const t = type->getAs<TypedefType>()) {
- if (t->getDecl()->hasAttr<WarnUnusedAttr>()) {
- return true;
- }
- }
- if (auto const t = type->getAs<RecordType>()) {
- if (t->getDecl()->hasAttr<WarnUnusedAttr>()) {
- return true;
- }
- }
- return loplugin::isExtraWarnUnusedType(type);
-}
-
Expr const * lookThroughInitListExpr(Expr const * expr) {
if (auto const ile = dyn_cast<InitListExpr>(expr->IgnoreParenImpCasts())) {
if (ile->getNumInits() == 1) {
@@ -203,6 +189,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 +412,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",
@@ -437,12 +431,26 @@ private:
}
}
+ bool isWarnUnusedType(QualType type) {
+ if (auto const t = type->getAs<TypedefType>()) {
+ if (t->getDecl()->hasAttr<WarnUnusedAttr>()) {
+ return true;
+ }
+ }
+ if (auto const t = type->getAs<RecordType>()) {
+ if (compat::getDefinitionOrSelf(compat::getDecl(t))->hasAttr<WarnUnusedAttr>()) {
+ return true;
+ }
+ }
+ return loplugin::isExtraWarnUnusedType(compiler.getASTContext(), type);
+ }
+
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())