summaryrefslogtreecommitdiffstats
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-03-25 10:46:00 +0100
committerStephan Bergmann <sbergman@redhat.com>2017-03-25 12:51:54 +0000
commit3c7652203cc381e5c8c06d42130ca3bae5576fd2 (patch)
tree63244c6db32d01fce0193dd96626e4a34e32f969 /compilerplugins
parentReplace some macros with constexpr functions (diff)
downloadcore-3c7652203cc381e5c8c06d42130ca3bae5576fd2.tar.gz
core-3c7652203cc381e5c8c06d42130ca3bae5576fd2.zip
Teach loplugin:redundantcast about C-style casts in macro bodies
Change-Id: Ic1fbc8dd16c4d78772fc11a9c2ce09f056e36c79 Reviewed-on: https://gerrit.libreoffice.org/35680 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/redundantcast.cxx25
1 files changed, 23 insertions, 2 deletions
diff --git a/compilerplugins/clang/redundantcast.cxx b/compilerplugins/clang/redundantcast.cxx
index c18e1cf5be0e..17e3bac33ca7 100644
--- a/compilerplugins/clang/redundantcast.cxx
+++ b/compilerplugins/clang/redundantcast.cxx
@@ -306,9 +306,30 @@ bool RedundantCast::VisitCStyleCastExpr(CStyleCastExpr const * expr) {
<< t1 << t2 << expr->getSourceRange();
return true;
}
- if (loplugin::TypeCheck(t1).Typedef() && loplugin::TypeCheck(t2).Typedef() && t1 == t2
- && !compiler.getSourceManager().isMacroBodyExpansion(expr->getLocStart()))
+ if (loplugin::TypeCheck(t1).Typedef() && loplugin::TypeCheck(t2).Typedef() && t1 == t2)
{
+ // Ignore FD_ISSET expanding to "...(SOCKET)(fd)..." in some Microsoft
+ // winsock2.h (TODO: improve heuristic of determining that the whole
+ // expr is part of a single macro body expansion):
+ auto l1 = expr->getLocStart();
+ while (compiler.getSourceManager().isMacroArgExpansion(l1)) {
+ l1 = compiler.getSourceManager().getImmediateMacroCallerLoc(l1);
+ }
+ auto l2 = expr->getExprLoc();
+ while (compiler.getSourceManager().isMacroArgExpansion(l2)) {
+ l2 = compiler.getSourceManager().getImmediateMacroCallerLoc(l2);
+ }
+ auto l3 = expr->getLocEnd();
+ while (compiler.getSourceManager().isMacroArgExpansion(l3)) {
+ l3 = compiler.getSourceManager().getImmediateMacroCallerLoc(l3);
+ }
+ if (compiler.getSourceManager().isMacroBodyExpansion(l1)
+ && compiler.getSourceManager().isMacroBodyExpansion(l2)
+ && compiler.getSourceManager().isMacroBodyExpansion(l3)
+ && ignoreLocation(compiler.getSourceManager().getSpellingLoc(l2)))
+ {
+ return true;
+ }
report(
DiagnosticsEngine::Warning,
"redundant cstyle typedef cast from %0 to %1", expr->getExprLoc())