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

Noel Grandin noel.grandin at collabora.co.uk
Tue Sep 27 12:11:54 UTC 2016


 compilerplugins/clang/constantparam.cxx             |    1 
 compilerplugins/clang/countusersofdefaultparams.cxx |    1 
 compilerplugins/clang/plugin.cxx                    |   61 ++++++++++----------
 compilerplugins/clang/plugin.hxx                    |    2 
 compilerplugins/clang/singlevalfields.cxx           |    1 
 compilerplugins/clang/unuseddefaultparams.cxx       |    1 
 compilerplugins/clang/unusedenumvalues.cxx          |    1 
 compilerplugins/clang/unusedfields.cxx              |    1 
 compilerplugins/clang/unusedmethods.cxx             |    1 
 9 files changed, 42 insertions(+), 28 deletions(-)

New commits:
commit 3468dab9ff02ecdf5d0806a00e15b9b579c8dc35
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Sep 27 10:00:03 2016 +0200

    clang plugins: do "dotdot" normalisation
    
    which fixes some false positives
    
    Change-Id: I555349180b5ca819f29695789f1545ba2177bd09
    Reviewed-on: https://gerrit.libreoffice.org/29320
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index 61428ac..c517e59 100644
--- a/compilerplugins/clang/constantparam.cxx
+++ b/compilerplugins/clang/constantparam.cxx
@@ -137,6 +137,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
     aInfo.callValue = callValue;
 
     aInfo.sourceLocation = filename.str() + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 
     callSet.insert(aInfo);
 }
diff --git a/compilerplugins/clang/countusersofdefaultparams.cxx b/compilerplugins/clang/countusersofdefaultparams.cxx
index a425cfc..b6323d0 100644
--- a/compilerplugins/clang/countusersofdefaultparams.cxx
+++ b/compilerplugins/clang/countusersofdefaultparams.cxx
@@ -130,6 +130,7 @@ void CountUsersOfDefaultParams::niceName(const FunctionDecl* functionDecl, MyFun
     }
 
     aInfo.sourceLocation = locationToString(functionDecl->getLocation());
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 }
 
 bool CountUsersOfDefaultParams::VisitCallExpr(const CallExpr * callExpr) {
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index 9f13ee7..3507371 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -55,34 +55,7 @@ bool Plugin::ignoreLocation( SourceLocation loc )
             return true;
         }
         std::string s(bufferName);
-        for (std::string::size_type i = 0;;) {
-            i = s.find("/.", i);
-            if (i == std::string::npos) {
-                break;
-            }
-            if (i + 2 == s.length() || s[i + 2] == '/') {
-                s.erase(i, 2); // [AAA]/.[/CCC] -> [AAA][/CCC]
-            } else if (s[i + 2] == '.'
-                       && (i + 3 == s.length() || s[i + 3] == '/'))
-            {
-                if (i == 0) { // /..[/CCC] -> /..[/CCC]
-                    break;
-                }
-                auto j = s.rfind('/', i - 1);
-                if (j == std::string::npos) {
-                    // BBB/..[/CCC] -> BBB/..[/CCC] (instead of BBB/../CCC ->
-                    // CCC, to avoid wrong ../../CCC -> CCC; relative paths
-                    // shouldn't happen anyway, and even if they did, wouldn't
-                    // match against WORKDIR anyway, as WORKDIR should be
-                    // absolute):
-                    break;
-                }
-                s.erase(j, i + 3 - j); // AAA/BBB/..[/CCC] -> AAA[/CCC]
-                i = j;
-            } else {
-                i += 2;
-            }
-        }
+        normalizeDotDotInFilePath(s);
         if (strncmp(s.c_str(), WORKDIR, strlen(WORKDIR)) == 0) {
             return true;
         }
@@ -93,6 +66,38 @@ bool Plugin::ignoreLocation( SourceLocation loc )
     return true;
     }
 
+void Plugin::normalizeDotDotInFilePath( std::string & s )
+    {
+    for (std::string::size_type i = 0;;) {
+        i = s.find("/.", i);
+        if (i == std::string::npos) {
+            break;
+        }
+        if (i + 2 == s.length() || s[i + 2] == '/') {
+            s.erase(i, 2); // [AAA]/.[/CCC] -> [AAA][/CCC]
+        } else if (s[i + 2] == '.'
+                   && (i + 3 == s.length() || s[i + 3] == '/'))
+        {
+            if (i == 0) { // /..[/CCC] -> /..[/CCC]
+                break;
+            }
+            auto j = s.rfind('/', i - 1);
+            if (j == std::string::npos) {
+                // BBB/..[/CCC] -> BBB/..[/CCC] (instead of BBB/../CCC ->
+                // CCC, to avoid wrong ../../CCC -> CCC; relative paths
+                // shouldn't happen anyway, and even if they did, wouldn't
+                // match against WORKDIR anyway, as WORKDIR should be
+                // absolute):
+                break;
+            }
+            s.erase(j, i + 3 - j); // AAA/BBB/..[/CCC] -> AAA[/CCC]
+            i = j;
+        } else {
+            i += 2;
+        }
+    }
+    }
+
 void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault )
     {
     PluginHandler::registerPlugin( create, optionName, isPPCallback, byDefault );
diff --git a/compilerplugins/clang/plugin.hxx b/compilerplugins/clang/plugin.hxx
index 6b9f682..635dcfe 100644
--- a/compilerplugins/clang/plugin.hxx
+++ b/compilerplugins/clang/plugin.hxx
@@ -75,6 +75,8 @@ class Plugin
          which is not allowed to be changed.
         */
         bool isInUnoIncludeFile(SourceLocation spellingLocation) const;
+
+        static void normalizeDotDotInFilePath(std::string&);
     private:
         static void registerPlugin( Plugin* (*create)( const InstantiationData& ), const char* optionName, bool isPPCallback, bool byDefault );
         template< typename T > static Plugin* createHelper( const InstantiationData& data );
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index c663bd6..491d260 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -116,6 +116,7 @@ void SingleValFields::niceName(const FieldDecl* fieldDecl, MyFieldInfo& aInfo)
     SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( fieldDecl->getLocation() );
     StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
     aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 }
 
 bool SingleValFields::VisitFieldDecl( const FieldDecl* fieldDecl )
diff --git a/compilerplugins/clang/unuseddefaultparams.cxx b/compilerplugins/clang/unuseddefaultparams.cxx
index 11cd37d..6b5aefa 100644
--- a/compilerplugins/clang/unuseddefaultparams.cxx
+++ b/compilerplugins/clang/unuseddefaultparams.cxx
@@ -124,6 +124,7 @@ MyFuncInfo UnusedDefaultParams::niceName(const FunctionDecl* functionDecl)
     SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() );
     StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
     aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 
     return aInfo;
 }
diff --git a/compilerplugins/clang/unusedenumvalues.cxx b/compilerplugins/clang/unusedenumvalues.cxx
index 6e3c874..bfde960 100644
--- a/compilerplugins/clang/unusedenumvalues.cxx
+++ b/compilerplugins/clang/unusedenumvalues.cxx
@@ -101,6 +101,7 @@ MyEnumValueInfo UnusedEnumValues::niceName(const EnumConstantDecl* enumDecl)
     SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( enumDecl->getLocation() );
     StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
     aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 
     return aInfo;
 }
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index 41fab03..6e4da40 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -109,6 +109,7 @@ MyFieldInfo UnusedFields::niceName(const FieldDecl* fieldDecl)
     SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( fieldDecl->getLocation() );
     StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
     aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 
     return aInfo;
 }
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index c16b446..3c5498d 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -166,6 +166,7 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
     SourceLocation expansionLoc = compiler.getSourceManager().getExpansionLoc( functionDecl->getLocation() );
     StringRef name = compiler.getSourceManager().getFilename(expansionLoc);
     aInfo.sourceLocation = std::string(name.substr(strlen(SRCDIR)+1)) + ":" + std::to_string(compiler.getSourceManager().getSpellingLineNumber(expansionLoc));
+    normalizeDotDotInFilePath(aInfo.sourceLocation);
 
     return aInfo;
 }


More information about the Libreoffice-commits mailing list