[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann
sbergman at redhat.com
Sat Mar 25 12:52:24 UTC 2017
compilerplugins/clang/redundantcast.cxx | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
New commits:
commit 3c7652203cc381e5c8c06d42130ca3bae5576fd2
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Sat Mar 25 10:46:00 2017 +0100
Teach loplugin:redundantcast about C-style casts in macro bodies
Change-Id: Ic1fbc8dd16c4d78772fc11a9c2ce09f056e36c79
Reviewed-on: https://gerrit.libreoffice.org/35680
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
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())
More information about the Libreoffice-commits
mailing list