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

Stephan Bergmann sbergman at redhat.com
Tue Jun 28 14:27:01 UTC 2016


 compilerplugins/clang/compat.hxx                 |   21 +++++++++++++++++++++
 compilerplugins/clang/faileddyncast.cxx          |    1 +
 compilerplugins/clang/implicitboolconversion.cxx |    8 ++++++--
 compilerplugins/clang/passstuffbyref.cxx         |    2 +-
 compilerplugins/clang/privatebase.cxx            |    8 ++++----
 compilerplugins/clang/refcounting.cxx            |    2 +-
 compilerplugins/clang/singlevalfields.cxx        |    6 +++---
 compilerplugins/clang/staticmethods.cxx          |    2 ++
 compilerplugins/clang/typecheck.cxx              |    3 ++-
 compilerplugins/clang/unuseddefaultparams.cxx    |    2 ++
 compilerplugins/clang/unusedmethods.cxx          |    5 ++++-
 compilerplugins/clang/vclwidgets.cxx             |    8 +++++---
 compilerplugins/clang/weakobject.cxx             |    5 +++--
 13 files changed, 55 insertions(+), 18 deletions(-)

New commits:
commit 9308f353186fb39a02eddfc281fc72ac1026e0b6
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue Jun 28 16:25:55 2016 +0200

    Adapt to Clang 3.4 (in preparation of a buildbot on CentOS 7)
    
    Change-Id: Ie2859f03b31c57deb7fd0deba3285f782e33b239

diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx
index e1b4d8e..2f73b7f 100644
--- a/compilerplugins/clang/compat.hxx
+++ b/compilerplugins/clang/compat.hxx
@@ -323,6 +323,27 @@ inline auto getAsTagDecl(clang::Type const& t) -> clang::TagDecl *
 #endif
 }
 
+inline bool isStdNamespace(clang::DeclContext const & context) {
+#if CLANG_VERSION >= 30500
+    return context.isStdNamespace();
+#else
+    // cf. lib/AST/DeclBase.cpp:
+    if (!context.isNamespace()) {
+        return false;
+    }
+    const clang::NamespaceDecl *ND = clang::cast<clang::NamespaceDecl>(
+        &context);
+    if (ND->isInline()) {
+        return isStdNamespace(*ND->getParent());
+    }
+    if (!context.getParent()->getRedeclContext()->isTranslationUnit()) {
+        return false;
+    }
+    const clang::IdentifierInfo *II = ND->getIdentifier();
+    return II && II->isStr("std");
+#endif
+}
+
 }
 
 #endif
diff --git a/compilerplugins/clang/faileddyncast.cxx b/compilerplugins/clang/faileddyncast.cxx
index 6fef227..9be28f0 100644
--- a/compilerplugins/clang/faileddyncast.cxx
+++ b/compilerplugins/clang/faileddyncast.cxx
@@ -9,6 +9,7 @@
 
 #include <algorithm>
 
+#include "clang/AST/Attr.h"
 #include "clang/AST/CXXInheritance.h"
 
 #include "plugin.hxx"
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx
index 1e4c5e2..79dc8fb 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -21,7 +21,9 @@
 
 #if CLANG_VERSION < 30700
 
-template<> struct std::iterator_traits<ExprIterator> {
+namespace std {
+
+template<> struct iterator_traits<ExprIterator> {
     typedef std::ptrdiff_t difference_type;
     typedef Expr * value_type;
     typedef Expr const ** pointer;
@@ -29,7 +31,7 @@ template<> struct std::iterator_traits<ExprIterator> {
     typedef std::random_access_iterator_tag iterator_category;
 };
 
-template<> struct std::iterator_traits<ConstExprIterator> {
+template<> struct iterator_traits<ConstExprIterator> {
     typedef std::ptrdiff_t difference_type;
     typedef Expr const * value_type;
     typedef Expr const ** pointer;
@@ -37,6 +39,8 @@ template<> struct std::iterator_traits<ConstExprIterator> {
     typedef std::random_access_iterator_tag iterator_category;
 };
 
+}
+
 #endif
 
 namespace {
diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx
index 8c9814e..b2f5ce6 100644
--- a/compilerplugins/clang/passstuffbyref.cxx
+++ b/compilerplugins/clang/passstuffbyref.cxx
@@ -231,7 +231,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
         return;
     }
 
-    const QualType type = functionDecl->getReturnType().getDesugaredType(compiler.getASTContext());
+    const QualType type = compat::getReturnType(*functionDecl).getDesugaredType(compiler.getASTContext());
     if (type->isReferenceType() || type->isIntegralOrEnumerationType() || type->isPointerType()
         || type->isTemplateTypeParmType() || type->isDependentType() || type->isBuiltinType()
         || type->isScalarType())
diff --git a/compilerplugins/clang/privatebase.cxx b/compilerplugins/clang/privatebase.cxx
index 8084ee3..d2a125d 100644
--- a/compilerplugins/clang/privatebase.cxx
+++ b/compilerplugins/clang/privatebase.cxx
@@ -34,14 +34,14 @@ bool PrivateBase::VisitCXXRecordDecl(CXXRecordDecl const * decl) {
     {
         return true;
     }
-    for (auto const & i: decl->bases()) {
-        if (i.getAccessSpecifierAsWritten() == AS_none) {
+    for (auto i = decl->bases_begin(); i != decl->bases_end(); ++i) {
+        if (i->getAccessSpecifierAsWritten() == AS_none) {
             report(
                 DiagnosticsEngine::Warning,
                 "base class is private by default; explicitly give an access"
                     " specifier",
-                i.getLocStart())
-                << i.getSourceRange();
+                i->getLocStart())
+                << i->getSourceRange();
         }
     }
     return true;
diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx
index 9bb9485..9ce88a3 100644
--- a/compilerplugins/clang/refcounting.cxx
+++ b/compilerplugins/clang/refcounting.cxx
@@ -427,7 +427,7 @@ bool RefCounting::VisitFunctionDecl(const FunctionDecl * functionDecl) {
     if (methodDecl && methodDecl->size_overridden_methods() > 0) {
             return true;
     }
-    checkUnoReference(functionDecl->getReturnType(), functionDecl, "", "return");
+    checkUnoReference(compat::getReturnType(*functionDecl), functionDecl, "", "return");
     return true;
 }
 
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index 79866fa..a75b529 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -258,7 +258,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
     if (parent && isa<ReturnStmt>(parent)) {
         const Stmt* parent2 = parentStmt(parent);
         if (parent2 && isa<CompoundStmt>(parent2)) {
-            QualType qt = parentFunction->getReturnType().getDesugaredType(compiler.getASTContext());
+            QualType qt = compat::getReturnType(*parentFunction).getDesugaredType(compiler.getASTContext());
             if (!qt.isConstQualified() && qt->isReferenceType()) {
                 assignValue = "?";
                 bPotentiallyAssignedTo = true;
@@ -443,10 +443,10 @@ void SingleValFields::checkCallExpr(const Stmt* child, const CallExpr* callExpr,
         return;
     }
     for (unsigned i = 0; i < callExpr->getNumArgs(); ++i) {
-        if (i >= proto->getNumParams()) // can happen in template code
+        if (i >= compat::getNumParams(*proto)) // can happen in template code
             break;
         if (callExpr->getArg(i) == child) {
-            QualType qt = proto->getParamTypes()[i].getDesugaredType(compiler.getASTContext());
+            QualType qt = compat::getParamType(*proto, i).getDesugaredType(compiler.getASTContext());
             if (!qt.isConstQualified() && qt->isReferenceType()) {
                 assignValue = "?";
                 bPotentiallyAssignedTo = true;
diff --git a/compilerplugins/clang/staticmethods.cxx b/compilerplugins/clang/staticmethods.cxx
index 43e0f73..be014fd 100644
--- a/compilerplugins/clang/staticmethods.cxx
+++ b/compilerplugins/clang/staticmethods.cxx
@@ -7,6 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include "clang/AST/Attr.h"
+
 #include "plugin.hxx"
 #include "compat.hxx"
 
diff --git a/compilerplugins/clang/typecheck.cxx b/compilerplugins/clang/typecheck.cxx
index 71f9994..d7bccfd 100644
--- a/compilerplugins/clang/typecheck.cxx
+++ b/compilerplugins/clang/typecheck.cxx
@@ -81,7 +81,8 @@ TerminalCheck NamespaceCheck::GlobalNamespace() const {
 }
 
 TerminalCheck NamespaceCheck::StdNamespace() const {
-    return TerminalCheck(context_ != nullptr && context_->isStdNamespace());
+    return TerminalCheck(
+        context_ != nullptr && compat::isStdNamespace(*context_));
 }
 
 }
diff --git a/compilerplugins/clang/unuseddefaultparams.cxx b/compilerplugins/clang/unuseddefaultparams.cxx
index 6d2094e..db58824 100644
--- a/compilerplugins/clang/unuseddefaultparams.cxx
+++ b/compilerplugins/clang/unuseddefaultparams.cxx
@@ -12,6 +12,8 @@
 #include <iostream>
 #include <fstream>
 
+#include "clang/AST/Attr.h"
+
 #include "plugin.hxx"
 #include "compat.hxx"
 
diff --git a/compilerplugins/clang/unusedmethods.cxx b/compilerplugins/clang/unusedmethods.cxx
index 7de434d..0ff053a 100644
--- a/compilerplugins/clang/unusedmethods.cxx
+++ b/compilerplugins/clang/unusedmethods.cxx
@@ -12,6 +12,9 @@
 #include <iostream>
 #include <fstream>
 #include <set>
+
+#include "clang/AST/Attr.h"
+
 #include "plugin.hxx"
 #include "compat.hxx"
 
@@ -265,7 +268,7 @@ gotfunc:
     }
 
     // Now do the checks necessary for the "unused return value" analysis
-    if (calleeFunctionDecl->getReturnType()->isVoidType()) {
+    if (compat::getReturnType(*calleeFunctionDecl)->isVoidType()) {
         return true;
     }
     if (!parent) {
diff --git a/compilerplugins/clang/vclwidgets.cxx b/compilerplugins/clang/vclwidgets.cxx
index 212dcb5..368c962 100644
--- a/compilerplugins/clang/vclwidgets.cxx
+++ b/compilerplugins/clang/vclwidgets.cxx
@@ -205,9 +205,11 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD
     if (pCompoundStatement) {
         bool bFoundDisposeOnce = false;
         int nNumExtraStatements = 0;
-        for(auto const * x : pCompoundStatement->body())
+        for (auto i = pCompoundStatement->body_begin();
+             i != pCompoundStatement->body_end(); ++i)
         {
-            const CXXMemberCallExpr *pCallExpr = dyn_cast<CXXMemberCallExpr>(x);
+            const CXXMemberCallExpr *pCallExpr = dyn_cast<CXXMemberCallExpr>(
+                *i);
             if (pCallExpr) {
                 if( const FunctionDecl* func = pCallExpr->getDirectCallee()) {
                     if( func->getNumParams() == 0 && func->getIdentifier() != NULL
@@ -217,7 +219,7 @@ bool VCLWidgets::VisitCXXDestructorDecl(const CXXDestructorDecl* pCXXDestructorD
                 }
             }
             // checking for ParenExpr is a hacky way to ignore assert statements in older versions of clang (i.e. <= 3.2)
-            if (!pCallExpr && !dyn_cast<ParenExpr>(x))
+            if (!pCallExpr && !dyn_cast<ParenExpr>(*i))
                 nNumExtraStatements++;
         }
         bOk = bFoundDisposeOnce && nNumExtraStatements == 0;
diff --git a/compilerplugins/clang/weakobject.cxx b/compilerplugins/clang/weakobject.cxx
index cac13cd..c714274 100644
--- a/compilerplugins/clang/weakobject.cxx
+++ b/compilerplugins/clang/weakobject.cxx
@@ -98,10 +98,11 @@ public:
         }
         CompoundStmt const*const pCompoundStatement(
                 dyn_cast<CompoundStmt>(pMethodDecl->getBody()));
-        for (auto const pStmt : pCompoundStatement->body())
+        for (auto i = pCompoundStatement->body_begin();
+             i != pCompoundStatement->body_end(); ++i)
         {
             // note: this is not a CXXMemberCallExpr
-            CallExpr const*const pCallExpr(dyn_cast<CallExpr>(pStmt));
+            CallExpr const*const pCallExpr(dyn_cast<CallExpr>(*i));
             if (pCallExpr)
             {
                 // note: this is only sometimes a CXXMethodDecl


More information about the Libreoffice-commits mailing list