[Libreoffice-commits] core.git: compilerplugins/clang

Noel Grandin noel at peralex.com
Tue Jul 14 00:44:55 PDT 2015


 compilerplugins/clang/unusedmethods.cxx |   17 +++++++----------
 compilerplugins/clang/unusedmethods.py  |    3 +--
 2 files changed, 8 insertions(+), 12 deletions(-)

New commits:
commit a04354ecb34216d7fb9868f701fd3ee2b70883c8
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Jul 13 13:31:13 2015 +0200

    improve the unusedmethods plugin
    
    to find stuff called from 2 levels+ inside template methods
    
    Change-Id: I4ba308a992e64a091e5364b8aa89e44d6772dcb0

diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index 655dfe2..162bff0 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -33,7 +33,6 @@ to auto-remove the method declarations
 Note that the actual process may involve a fair amount of undoing, hand editing, and general messing around
 to get it to work :-)
 
-TODO ignore calls from a method to itself, so we can eliminate unused recursive methods
 TODO deal with calls to superclass/member constructors from other constructors, so
      we can find unused constructors
 TODO need to handle places where the code takes the address of a method, that needs to count
@@ -139,7 +138,7 @@ static bool isStandardStuff(const std::string& s)
 }
 
 // prevent recursive templates from blowing up the stack
-static std::set<std::string> traversedTemplateFunctionSet;
+static std::set<std::string> traversedFunctionSet;
 
 bool UnusedMethods::VisitCallExpr(CallExpr* expr)
 {
@@ -150,14 +149,12 @@ bool UnusedMethods::VisitCallExpr(CallExpr* expr)
     if (calleeFunctionDecl == nullptr) {
         return true;
     }
-    // if we see a call to a templated function, it effectively creates new code,
-    // so we need to examine it's interior to see if it, in turn, calls anything else
-    if (calleeFunctionDecl->getTemplatedKind() != FunctionDecl::TemplatedKind::TK_NonTemplate
-        || calleeFunctionDecl->isFunctionTemplateSpecialization())
-    {
-        if (traversedTemplateFunctionSet.insert(calleeFunctionDecl->getQualifiedNameAsString()).second)
-            TraverseFunctionDecl(calleeFunctionDecl);
-    }
+    // if we see a call to a function, it may effectively create new code,
+    // if the function is templated. However, if we are inside a template function,
+    // calling another function on the same template, the same problem occurs.
+    // Rather than tracking all of that, just traverse anything we have not already traversed.
+    if (traversedFunctionSet.insert(calleeFunctionDecl->getQualifiedNameAsString()).second)
+        TraverseFunctionDecl(calleeFunctionDecl);
 
     CXXMethodDecl* calleeMethodDecl = dyn_cast_or_null<CXXMethodDecl>(calleeFunctionDecl);
     if (calleeMethodDecl == nullptr) {
diff --git a/compilerplugins/clang/unusedmethods.py b/compilerplugins/clang/unusedmethods.py
index ef2beb9..1d4208c 100755
--- a/compilerplugins/clang/unusedmethods.py
+++ b/compilerplugins/clang/unusedmethods.py
@@ -29,7 +29,6 @@ exclusionSet = set([
     "void comphelper::IEventProcessor::release()",
     "void SotMutexHolder::acquire()",
     "void SotMutexHolder::release()",
-    "class Rectangle ComboBox::GetDropDownPosSizePixel() const"
     # only used by Windows build
     "_Bool basegfx::B2ITuple::equalZero() const",
     "class basegfx::B2DPolyPolygon basegfx::unotools::UnoPolyPolygon::getPolyPolygonUnsafe() const",
@@ -47,7 +46,7 @@ exclusionSet = set([
     "int PhysicalFontFace::GetWidth() const",
     "void PhysicalFontFace::SetBitmapSize(int,int)",
     "_Bool SalObject::IsEraseBackgroundEnabled()",
-    # instantiated from a template in VCL, not sure why it is not being picked up
+    # instantiated from templates, not sure why it is not being picked up
     "class basegfx::B2DPolygon OutputDevice::PixelToLogic(const class basegfx::B2DPolygon &,const class MapMode &) const",
     # only used by OSX build
     "void StyleSettings::SetHideDisabledMenuItems(_Bool)",


More information about the Libreoffice-commits mailing list