Bump --enable-compiler-plugins to Clang 3.8.0

<https://lists.freedesktop.org/archives/libreoffice/2017-December/079107.html>
"Clang baseline bump"

Change-Id: I18fca8794ea34118fc6308458064d0c28cf5caf7
Reviewed-on: https://gerrit.libreoffice.org/46557
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2017-12-15 14:20:38 +01:00
parent 00bc5a0973
commit 9663341f92
32 changed files with 93 additions and 399 deletions

View File

@@ -50,7 +50,7 @@ C++17, C++14, or C++11" in its current form (due to the #pragma GCC diagnostic i
that it does not understand). that it does not understand).
If you want to use Clang with the LibreOffice compiler plugins, the minimal If you want to use Clang with the LibreOffice compiler plugins, the minimal
version of Clang is 3.4. Since Xcode doesn't provide the compiler plugin version of Clang is 3.8. Since Xcode doesn't provide the compiler plugin
headers, you have to compile your own Clang to use them on macOS. headers, you have to compile your own Clang to use them on macOS.
You can find the TDF configure switches in the distro-configs/ directory. You can find the TDF configure switches in the distro-configs/ directory.

View File

@@ -9,8 +9,9 @@
#include <cassert> #include <cassert>
#include <clang/AST/DeclCXX.h>
#include "check.hxx" #include "check.hxx"
#include "compat.hxx"
namespace loplugin { namespace loplugin {
@@ -153,14 +154,14 @@ ContextCheck DeclCheck::MemberFunction() const {
TerminalCheck ContextCheck::GlobalNamespace() const { TerminalCheck ContextCheck::GlobalNamespace() const {
return TerminalCheck( return TerminalCheck(
context_ != nullptr context_ != nullptr
&& ((compat::isLookupContext(*context_) && ((context_->isLookupContext()
? context_ : context_->getLookupParent()) ? context_ : context_->getLookupParent())
->isTranslationUnit())); ->isTranslationUnit()));
} }
TerminalCheck ContextCheck::StdNamespace() const { TerminalCheck ContextCheck::StdNamespace() const {
return TerminalCheck( return TerminalCheck(
context_ != nullptr && compat::isStdNamespace(*context_)); context_ != nullptr && context_->isStdNamespace());
} }
ContextCheck ContextCheck::AnonymousNamespace() const { ContextCheck ContextCheck::AnonymousNamespace() const {
@@ -171,13 +172,7 @@ ContextCheck ContextCheck::AnonymousNamespace() const {
namespace { namespace {
bool BaseCheckNotSomethingInterestingSubclass( bool BaseCheckNotSomethingInterestingSubclass(const clang::CXXRecordDecl *BaseDefinition) {
const clang::CXXRecordDecl *BaseDefinition
#if CLANG_VERSION < 30800
, void *
#endif
)
{
if (BaseDefinition) { if (BaseDefinition) {
auto tc = TypeCheck(BaseDefinition); auto tc = TypeCheck(BaseDefinition);
if (tc.Class("Dialog").GlobalNamespace() || tc.Class("SfxPoolItem").GlobalNamespace()) { if (tc.Class("Dialog").GlobalNamespace() || tc.Class("SfxPoolItem").GlobalNamespace()) {
@@ -201,7 +196,7 @@ bool isDerivedFromSomethingInteresting(const clang::CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!compat::forallBases(*decl, BaseCheckNotSomethingInterestingSubclass, nullptr, true)) { !decl->forallBases(BaseCheckNotSomethingInterestingSubclass, true)) {
return true; return true;
} }
return false; return false;

View File

@@ -9,9 +9,9 @@
* *
*/ */
#include <memory>
#include <set> #include <set>
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
#include <clang/Lex/Preprocessor.h> #include <clang/Lex/Preprocessor.h>
@@ -37,14 +37,14 @@ class CheckConfigMacros
explicit CheckConfigMacros( const InstantiationData& data ); explicit CheckConfigMacros( const InstantiationData& data );
virtual void run() override; virtual void run() override;
virtual void MacroDefined( const Token& macroToken, const MacroDirective* info ) override; virtual void MacroDefined( const Token& macroToken, const MacroDirective* info ) override;
virtual void MacroUndefined( const Token& macroToken, compat::MacroDefinitionParam virtual void MacroUndefined( const Token& macroToken, MacroDefinition const &
#if CLANG_VERSION >= 50000 #if CLANG_VERSION >= 50000
, MacroDirective const * , MacroDirective const *
#endif #endif
) override; ) override;
virtual void Ifdef( SourceLocation location, const Token& macroToken, compat::MacroDefinitionParam ) override; virtual void Ifdef( SourceLocation location, const Token& macroToken, MacroDefinition const & ) override;
virtual void Ifndef( SourceLocation location, const Token& macroToken, compat::MacroDefinitionParam ) override; virtual void Ifndef( SourceLocation location, const Token& macroToken, MacroDefinition const & ) override;
virtual void Defined( const Token& macroToken, compat::MacroDefinitionParam, SourceRange Range ) override; virtual void Defined( const Token& macroToken, MacroDefinition const &, SourceRange Range ) override;
enum { isPPCallback = true }; enum { isPPCallback = true };
private: private:
void checkMacro( const Token& macroToken, SourceLocation location ); void checkMacro( const Token& macroToken, SourceLocation location );
@@ -54,7 +54,7 @@ class CheckConfigMacros
CheckConfigMacros::CheckConfigMacros( const InstantiationData& data ) CheckConfigMacros::CheckConfigMacros( const InstantiationData& data )
: Plugin( data ) : Plugin( data )
{ {
compat::addPPCallbacks(compiler.getPreprocessor(), this); compiler.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(this));
} }
void CheckConfigMacros::run() void CheckConfigMacros::run()
@@ -75,7 +75,7 @@ void CheckConfigMacros::MacroDefined( const Token& macroToken, const MacroDirect
} }
} }
void CheckConfigMacros::MacroUndefined( const Token& macroToken, compat::MacroDefinitionParam void CheckConfigMacros::MacroUndefined( const Token& macroToken, MacroDefinition const &
#if CLANG_VERSION >= 50000 #if CLANG_VERSION >= 50000
, MacroDirective const * , MacroDirective const *
#endif #endif
@@ -84,17 +84,17 @@ void CheckConfigMacros::MacroUndefined( const Token& macroToken, compat::MacroDe
configMacros.erase( macroToken.getIdentifierInfo()->getName()); configMacros.erase( macroToken.getIdentifierInfo()->getName());
} }
void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken, compat::MacroDefinitionParam ) void CheckConfigMacros::Ifdef( SourceLocation location, const Token& macroToken, MacroDefinition const & )
{ {
checkMacro( macroToken, location ); checkMacro( macroToken, location );
} }
void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken, compat::MacroDefinitionParam ) void CheckConfigMacros::Ifndef( SourceLocation location, const Token& macroToken, MacroDefinition const & )
{ {
checkMacro( macroToken, location ); checkMacro( macroToken, location );
} }
void CheckConfigMacros::Defined( const Token& macroToken, compat::MacroDefinitionParam , SourceRange ) void CheckConfigMacros::Defined( const Token& macroToken, MacroDefinition const &, SourceRange )
{ {
checkMacro( macroToken, macroToken.getLocation()); checkMacro( macroToken, macroToken.getLocation());
} }

View File

@@ -11,26 +11,14 @@
#define INCLUDED_COMPILERPLUGINS_CLANG_COMPAT_HXX #define INCLUDED_COMPILERPLUGINS_CLANG_COMPAT_HXX
#include <cstddef> #include <cstddef>
#include <memory>
#include <string>
#include "clang/AST/Decl.h" #include "clang/AST/Decl.h"
#include "clang/AST/DeclBase.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Expr.h" #include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h" #include "clang/AST/ExprCXX.h"
#include "clang/AST/Type.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/Linkage.h"
#include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManager.h"
#include "clang/Basic/Visibility.h"
#include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "config_clang.h" #include "config_clang.h"
@@ -46,37 +34,6 @@ inline llvm::StringRef take_front(llvm::StringRef ref, std::size_t N = 1) {
#endif #endif
} }
inline bool isLookupContext(clang::DeclContext const & ctxt) {
#if CLANG_VERSION >= 30700
return ctxt.isLookupContext();
#else
return !ctxt.isFunctionOrMethod()
&& ctxt.getDeclKind() != clang::Decl::LinkageSpec;
#endif
}
inline bool forallBases(
clang::CXXRecordDecl const & decl,
clang::CXXRecordDecl::ForallBasesCallback BaseMatches,
void* callbackParam,
bool AllowShortCircuit)
{
#if CLANG_VERSION >= 30800
(void) callbackParam;
return decl.forallBases(BaseMatches, AllowShortCircuit);
#else
return decl.forallBases(BaseMatches, callbackParam, AllowShortCircuit);
#endif
}
inline clang::QualType getReturnType(clang::FunctionDecl const & decl) {
#if CLANG_VERSION >= 30500
return decl.getReturnType();
#else
return decl.getResultType();
#endif
}
#if CLANG_VERSION >= 30900 #if CLANG_VERSION >= 30900
inline clang::ArrayRef<clang::ParmVarDecl *> parameters( inline clang::ArrayRef<clang::ParmVarDecl *> parameters(
@@ -84,128 +41,15 @@ inline clang::ArrayRef<clang::ParmVarDecl *> parameters(
{ {
return decl.parameters(); return decl.parameters();
} }
#elif CLANG_VERSION >= 30500 #else
inline clang::FunctionDecl::param_const_range parameters( inline clang::FunctionDecl::param_const_range parameters(
clang::FunctionDecl const & decl) clang::FunctionDecl const & decl)
{ {
return decl.params(); return decl.params();
} }
#else
struct FunctionDeclParamsWrapper
{
clang::FunctionDecl const & decl;
FunctionDeclParamsWrapper(clang::FunctionDecl const & _decl) : decl(_decl) {}
clang::FunctionDecl::param_const_iterator begin() const { return decl.param_begin(); }
clang::FunctionDecl::param_const_iterator end() const { return decl.param_end(); }
};
inline FunctionDeclParamsWrapper parameters(
clang::FunctionDecl const & decl)
{
return FunctionDeclParamsWrapper(decl);
}
#endif #endif
inline clang::QualType getReturnType(clang::FunctionProtoType const & type) {
#if CLANG_VERSION >= 30500
return type.getReturnType();
#else
return type.getResultType();
#endif
}
inline unsigned getNumParams(clang::FunctionProtoType const & type) {
#if CLANG_VERSION >= 30500
return type.getNumParams();
#else
return type.getNumArgs();
#endif
}
inline clang::QualType getParamType(
clang::FunctionProtoType const & type, unsigned i)
{
#if CLANG_VERSION >= 30500
return type.getParamType(i);
#else
return type.getArgType(i);
#endif
}
inline clang::Stmt::const_child_iterator begin(
clang::Stmt::const_child_range const & range)
{
#if CLANG_VERSION >= 30800
return range.begin();
#else
return range.first;
#endif
}
inline clang::Stmt::const_child_iterator end(
clang::Stmt::const_child_range const & range)
{
#if CLANG_VERSION >= 30800
return range.end();
#else
return range.second;
#endif
}
inline unsigned getBuiltinCallee(clang::CallExpr const & expr) {
#if CLANG_VERSION >= 30500
return expr.getBuiltinCallee();
#else
return expr.isBuiltinCall();
#endif
}
inline unsigned getCustomDiagID(
clang::DiagnosticsEngine & engine, clang::DiagnosticsEngine::Level L,
llvm::StringRef FormatString)
{
#if CLANG_VERSION >= 30500
return engine.getDiagnosticIDs()->getCustomDiagID(
static_cast<clang::DiagnosticIDs::Level>(L), FormatString);
#else
return engine.getCustomDiagID(L, FormatString);
#endif
}
inline std::unique_ptr<llvm::raw_fd_ostream> create_raw_fd_ostream(
char const * Filename, std::string & ErrorInfo)
{
#if CLANG_VERSION >= 30600
std::error_code ec;
std::unique_ptr<llvm::raw_fd_ostream> s(
new llvm::raw_fd_ostream(Filename, ec, llvm::sys::fs::F_None));
ErrorInfo = ec ? "error: " + ec.message() : std::string();
return s;
#elif CLANG_VERSION >= 30500
return std::unique_ptr<llvm::raw_fd_ostream>(
new llvm::raw_fd_ostream(Filename, ErrorInfo, llvm::sys::fs::F_None));
#else
return std::unique_ptr<llvm::raw_fd_ostream>(
new llvm::raw_fd_ostream(Filename, ErrorInfo));
#endif
}
#if CLANG_VERSION >= 30700
using MacroDefinitionParam = clang::MacroDefinition const &;
#else
using MacroDefinitionParam = clang::MacroDirective const *;
#endif
inline void addPPCallbacks(
clang::Preprocessor & preprocessor, clang::PPCallbacks * C)
{
#if CLANG_VERSION >= 30600
preprocessor.addPPCallbacks(std::unique_ptr<clang::PPCallbacks>(C));
#else
preprocessor.addPPCallbacks(C);
#endif
}
inline bool isPointWithin( inline bool isPointWithin(
clang::SourceManager const & SM, clang::SourceLocation Location, clang::SourceLocation Start, clang::SourceManager const & SM, clang::SourceLocation Location, clang::SourceLocation Start,
clang::SourceLocation End) clang::SourceLocation End)
@@ -272,37 +116,6 @@ inline llvm::StringRef getImmediateMacroNameForDiagnostics(
#endif #endif
} }
inline auto getAsTagDecl(clang::Type const& t) -> clang::TagDecl *
{
#if CLANG_VERSION >= 30500
// TODO not sure if it works with clang 3.6, trunk is known to work
return t.getAsTagDecl();
#else
return t.getAs<clang::TagType>()->getDecl();
#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
}
// Work around <http://reviews.llvm.org/D22128>: // Work around <http://reviews.llvm.org/D22128>:
// //
// SfxErrorHandler::GetClassString (svtools/source/misc/ehdl.cxx): // SfxErrorHandler::GetClassString (svtools/source/misc/ehdl.cxx):

View File

@@ -107,12 +107,8 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
functionDecl = functionDecl->getInstantiatedFromMemberFunction(); functionDecl = functionDecl->getInstantiatedFromMemberFunction();
else if (functionDecl->getClassScopeSpecializationPattern()) else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern(); functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern()) else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern(); functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif
if (!functionDecl->getNameInfo().getLoc().isValid()) if (!functionDecl->getNameInfo().getLoc().isValid())
return; return;
@@ -131,7 +127,7 @@ void ConstantParam::addToCallSet(const FunctionDecl* functionDecl, int paramInde
MyCallSiteInfo aInfo; MyCallSiteInfo aInfo;
aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); aInfo.returnType = functionDecl->getReturnType().getCanonicalType().getAsString();
if (isa<CXXMethodDecl>(functionDecl)) { if (isa<CXXMethodDecl>(functionDecl)) {
const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent(); const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent();
@@ -259,11 +255,8 @@ bool ConstantParam::VisitCallExpr(const CallExpr * callExpr) {
functionDecl = functionDecl->getInstantiatedFromMemberFunction(); functionDecl = functionDecl->getInstantiatedFromMemberFunction();
else if (functionDecl->getClassScopeSpecializationPattern()) else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern(); functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern()) else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern(); functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif
unsigned len = std::max(callExpr->getNumArgs(), functionDecl->getNumParams()); unsigned len = std::max(callExpr->getNumArgs(), functionDecl->getNumParams());
for (unsigned i = 0; i < len; ++i) { for (unsigned i = 0; i < len; ++i) {

View File

@@ -95,11 +95,8 @@ void CountUsersOfDefaultParams::niceName(const FunctionDecl* functionDecl, MyFun
functionDecl = functionDecl->getInstantiatedFromMemberFunction(); functionDecl = functionDecl->getInstantiatedFromMemberFunction();
else if (functionDecl->getClassScopeSpecializationPattern()) else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern(); functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern()) else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern(); functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif
switch (functionDecl->getAccess()) switch (functionDecl->getAccess())
{ {
@@ -108,7 +105,7 @@ void CountUsersOfDefaultParams::niceName(const FunctionDecl* functionDecl, MyFun
case AS_protected: aInfo.access = "protected"; break; case AS_protected: aInfo.access = "protected"; break;
default: aInfo.access = "unknown"; break; default: aInfo.access = "unknown"; break;
} }
aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); aInfo.returnType = functionDecl->getReturnType().getCanonicalType().getAsString();
if (isa<CXXMethodDecl>(functionDecl)) { if (isa<CXXMethodDecl>(functionDecl)) {
const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent(); const CXXRecordDecl* recordDecl = dyn_cast<CXXMethodDecl>(functionDecl)->getParent();
@@ -160,11 +157,8 @@ bool CountUsersOfDefaultParams::VisitCallExpr(const CallExpr * callExpr) {
functionDecl = functionDecl->getInstantiatedFromMemberFunction(); functionDecl = functionDecl->getInstantiatedFromMemberFunction();
else if (functionDecl->getClassScopeSpecializationPattern()) else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern(); functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern()) else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern(); functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif
int n = functionDecl->getNumParams() - 1; int n = functionDecl->getNumParams() - 1;
if (n < 0 || !functionDecl->getParamDecl(n)->hasDefaultArg()) { if (n < 0 || !functionDecl->getParamDecl(n)->hasDefaultArg()) {
return true; return true;
@@ -192,11 +186,8 @@ bool CountUsersOfDefaultParams::VisitCXXConstructExpr(const CXXConstructExpr * c
constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getInstantiatedFromMemberFunction()); constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getInstantiatedFromMemberFunction());
else if (constructorDecl->getClassScopeSpecializationPattern()) else if (constructorDecl->getClassScopeSpecializationPattern())
constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getClassScopeSpecializationPattern()); constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getClassScopeSpecializationPattern());
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (constructorDecl->getTemplateInstantiationPattern()) else if (constructorDecl->getTemplateInstantiationPattern())
constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getTemplateInstantiationPattern()); constructorDecl = dyn_cast<CXXConstructorDecl>(constructorDecl->getTemplateInstantiationPattern());
#endif
int n = constructorDecl->getNumParams() - 1; int n = constructorDecl->getNumParams() - 1;
if (n < 0 || !constructorDecl->getParamDecl(n)->hasDefaultArg()) { if (n < 0 || !constructorDecl->getParamDecl(n)->hasDefaultArg()) {
return true; return true;

View File

@@ -100,8 +100,6 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
fieldDecl = fieldDecl->getCanonicalDecl(); fieldDecl = fieldDecl->getCanonicalDecl();
#if CLANG_VERSION >= 30800
auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& Paths) auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& Paths)
{ {
if (!cxxBaseSpecifier->getType().getTypePtr()) if (!cxxBaseSpecifier->getType().getTypePtr())
@@ -143,7 +141,6 @@ bool DataMemberShadow::VisitFieldDecl(FieldDecl const * fieldDecl)
CXXBasePaths aPaths; CXXBasePaths aPaths;
parentCXXRecordDecl->lookupInBases(BaseMatchesCallback, aPaths); parentCXXRecordDecl->lookupInBases(BaseMatchesCallback, aPaths);
#endif
return true; return true;
} }

View File

@@ -116,11 +116,8 @@ MyFuncInfo ExpandableMethods::niceName(const FunctionDecl* functionDecl)
functionDecl = functionDecl->getInstantiatedFromMemberFunction(); functionDecl = functionDecl->getInstantiatedFromMemberFunction();
else if (functionDecl->getClassScopeSpecializationPattern()) else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern(); functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern()) else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern(); functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif
MyFuncInfo aInfo; MyFuncInfo aInfo;
switch (functionDecl->getAccess()) switch (functionDecl->getAccess())
@@ -131,7 +128,7 @@ MyFuncInfo ExpandableMethods::niceName(const FunctionDecl* functionDecl)
default: aInfo.access = "unknown"; break; default: aInfo.access = "unknown"; break;
} }
if (!isa<CXXConstructorDecl>(functionDecl)) { if (!isa<CXXConstructorDecl>(functionDecl)) {
aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); aInfo.returnType = functionDecl->getReturnType().getCanonicalType().getAsString();
} else { } else {
aInfo.returnType = ""; aInfo.returnType = "";
} }

View File

@@ -13,7 +13,6 @@
// only compile this on clang 3.7 or higher, which is known to work // only compile this on clang 3.7 or higher, which is known to work
// there were problems on clang 3.5 at least // there were problems on clang 3.5 at least
#include "config_clang.h" #include "config_clang.h"
#if CLANG_VERSION >= 30700
#include <cassert> #include <cassert>
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
@@ -312,6 +311,5 @@ loplugin::Plugin::Registration<GetImplementationName> X(
"getimplementationname", false); "getimplementationname", false);
} }
#endif #endif
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -19,30 +19,6 @@
#include "compat.hxx" #include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
#if CLANG_VERSION < 30700
namespace std {
template<> struct iterator_traits<ExprIterator> {
typedef std::ptrdiff_t difference_type;
typedef Expr * value_type;
typedef Expr const ** pointer;
typedef Expr const & reference;
typedef std::random_access_iterator_tag iterator_category;
};
template<> struct iterator_traits<ConstExprIterator> {
typedef std::ptrdiff_t difference_type;
typedef Expr const * value_type;
typedef Expr const ** pointer;
typedef Expr const & reference;
typedef std::random_access_iterator_tag iterator_category;
};
}
#endif
namespace { namespace {
Expr const * ignoreParenAndTemporaryMaterialization(Expr const * expr) { Expr const * ignoreParenAndTemporaryMaterialization(Expr const * expr) {
@@ -334,19 +310,19 @@ bool ImplicitBoolConversion::TraverseCallExpr(CallExpr * expr) {
std::ptrdiff_t n = j - expr->arg_begin(); std::ptrdiff_t n = j - expr->arg_begin();
assert(n >= 0); assert(n >= 0);
if (t != nullptr if (t != nullptr
&& static_cast<std::size_t>(n) >= compat::getNumParams(*t)) && static_cast<std::size_t>(n) >= t->getNumParams())
{ {
assert(t->isVariadic()); assert(t->isVariadic());
// ignore bool to int promotions of variadic arguments // ignore bool to int promotions of variadic arguments
} else if (bExt) { } else if (bExt) {
if (t != nullptr) { if (t != nullptr) {
assert( assert(
static_cast<std::size_t>(n) < compat::getNumParams(*t)); static_cast<std::size_t>(n) < t->getNumParams());
if (!(compat::getParamType(*t, n)->isSpecificBuiltinType( if (!(t->getParamType(n)->isSpecificBuiltinType(
BuiltinType::Int) BuiltinType::Int)
|| compat::getParamType(*t, n)->isSpecificBuiltinType( || t->getParamType(n)->isSpecificBuiltinType(
BuiltinType::UInt) BuiltinType::UInt)
|| compat::getParamType(*t, n)->isSpecificBuiltinType( || t->getParamType(n)->isSpecificBuiltinType(
BuiltinType::Long))) BuiltinType::Long)))
{ {
reportWarning(i); reportWarning(i);
@@ -831,7 +807,7 @@ bool ImplicitBoolConversion::TraverseReturnStmt(ReturnStmt * stmt) {
bool ImplicitBoolConversion::TraverseFunctionDecl(FunctionDecl * decl) { bool ImplicitBoolConversion::TraverseFunctionDecl(FunctionDecl * decl) {
bool bExt = false; bool bExt = false;
if (hasCLanguageLinkageType(decl) && decl->isThisDeclarationADefinition()) { if (hasCLanguageLinkageType(decl) && decl->isThisDeclarationADefinition()) {
QualType t { compat::getReturnType(*decl) }; QualType t { decl->getReturnType() };
if (t->isSpecificBuiltinType(BuiltinType::Int) if (t->isSpecificBuiltinType(BuiltinType::Int)
|| t->isSpecificBuiltinType(BuiltinType::UInt)) || t->isSpecificBuiltinType(BuiltinType::UInt))
{ {

View File

@@ -7,6 +7,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/ */
#include <memory>
#include "compat.hxx" #include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
@@ -16,7 +18,7 @@ class IncludeForm final: public PPCallbacks, public loplugin::RewritePlugin {
public: public:
explicit IncludeForm(loplugin::InstantiationData const & data): explicit IncludeForm(loplugin::InstantiationData const & data):
RewritePlugin(data) RewritePlugin(data)
{ compat::addPPCallbacks(compiler.getPreprocessor(), this); } { compiler.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(this)); }
private: private:
void run() override {} void run() override {}

View File

@@ -31,10 +31,10 @@ private:
}; };
static bool oneAndOnlyOne(clang::Stmt::const_child_range range) { static bool oneAndOnlyOne(clang::Stmt::const_child_range range) {
if (compat::begin(range) == compat::end(range)) { if (range.begin() == range.end()) {
return false; return false;
} }
if (++compat::begin(range) != compat::end(range)) { if (++range.begin() != range.end()) {
return false; return false;
} }
return true; return true;
@@ -133,7 +133,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
{ {
childStmt2 = *childStmt2->child_begin(); childStmt2 = *childStmt2->child_begin();
if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr
&& compat::begin(childStmt2->children()) == compat::end(childStmt2->children())) && childStmt2->children().begin() == childStmt2->children().end())
{ {
return true; return true;
} }
@@ -144,7 +144,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
{ {
const Stmt* childStmt2 = *childStmt->child_begin(); const Stmt* childStmt2 = *childStmt->child_begin();
if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr if (dyn_cast<CXXThisExpr>( childStmt2 ) != nullptr
&& compat::begin(childStmt2->children()) == compat::end(childStmt2->children())) && childStmt2->children().begin() == childStmt2->children().end())
{ {
return true; return true;
} }
@@ -207,7 +207,7 @@ bool InlineSimpleMemberFunctions::VisitCXXMethodDecl(const CXXMethodDecl * funct
} }
return true; return true;
} }
if ( compat::begin(childStmt->children()) == compat::end(childStmt->children()) ) if ( childStmt->children().begin() == childStmt->children().end() )
return true; return true;
childStmt = *childStmt->child_begin(); childStmt = *childStmt->child_begin();
} }

View File

@@ -8,8 +8,8 @@
*/ */
#include <cassert> #include <cassert>
#include <memory>
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
namespace { namespace {
@@ -17,7 +17,7 @@ namespace {
class OslEndian: public loplugin::Plugin, public PPCallbacks { class OslEndian: public loplugin::Plugin, public PPCallbacks {
public: public:
explicit OslEndian(loplugin::InstantiationData const & data): Plugin(data) { explicit OslEndian(loplugin::InstantiationData const & data): Plugin(data) {
compat::addPPCallbacks(compiler.getPreprocessor(), this); compiler.getPreprocessor().addPPCallbacks(std::unique_ptr<PPCallbacks>(this));
} }
enum { isPPCallback = true }; enum { isPPCallback = true };
@@ -59,7 +59,7 @@ private:
} }
void MacroUndefined( void MacroUndefined(
Token const & MacroNameTok, compat::MacroDefinitionParam Token const & MacroNameTok, MacroDefinition const &
#if CLANG_VERSION >= 50000 #if CLANG_VERSION >= 50000
, MacroDirective const * , MacroDirective const *
#endif #endif
@@ -75,7 +75,7 @@ private:
} }
void Defined( void Defined(
Token const & MacroNameTok, compat::MacroDefinitionParam, SourceRange) Token const & MacroNameTok, MacroDefinition const &, SourceRange)
override override
{ {
check(MacroNameTok); check(MacroNameTok);
@@ -83,14 +83,14 @@ private:
void Ifdef( void Ifdef(
SourceLocation, Token const & MacroNameTok, SourceLocation, Token const & MacroNameTok,
compat::MacroDefinitionParam) override MacroDefinition const &) override
{ {
check(MacroNameTok); check(MacroNameTok);
} }
void Ifndef( void Ifndef(
SourceLocation, Token const & MacroNameTok, SourceLocation, Token const & MacroNameTok,
compat::MacroDefinitionParam) override MacroDefinition const &) override
{ {
check(MacroNameTok); check(MacroNameTok);
} }

View File

@@ -11,7 +11,6 @@
#include <set> #include <set>
#include "check.hxx" #include "check.hxx"
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
// Find places where various things are passed by value. // Find places where various things are passed by value.
@@ -222,7 +221,7 @@ void PassStuffByRef::checkReturnValue(const FunctionDecl * functionDecl, const C
return; return;
} }
const QualType type = compat::getReturnType(*functionDecl).getDesugaredType(compiler.getASTContext()); const QualType type = functionDecl->getReturnType().getDesugaredType(compiler.getASTContext());
if (type->isReferenceType() || type->isIntegralOrEnumerationType() || type->isPointerType() if (type->isReferenceType() || type->isIntegralOrEnumerationType() || type->isPointerType()
|| type->isTemplateTypeParmType() || type->isDependentType() || type->isBuiltinType() || type->isTemplateTypeParmType() || type->isDependentType() || type->isBuiltinType()
|| type->isScalarType()) || type->isScalarType())

View File

@@ -10,7 +10,8 @@
*/ */
#include <memory> #include <memory>
#include "compat.hxx" #include <system_error>
#include "plugin.hxx" #include "plugin.hxx"
#include "pluginhandler.hxx" #include "pluginhandler.hxx"
@@ -168,9 +169,9 @@ DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, const c
} }
fullMessage += "]"; fullMessage += "]";
if( loc.isValid()) if( loc.isValid())
return diag.Report( loc, compat::getCustomDiagID(diag, level, fullMessage) ); return diag.Report( loc, diag.getDiagnosticIDs()->getCustomDiagID(static_cast<DiagnosticIDs::Level>(level), fullMessage) );
else else
return diag.Report( compat::getCustomDiagID(diag, level, fullMessage) ); return diag.Report( diag.getDiagnosticIDs()->getCustomDiagID(static_cast<DiagnosticIDs::Level>(level), fullMessage) );
} }
DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc ) DiagnosticBuilder PluginHandler::report( DiagnosticsEngine::Level level, StringRef message, SourceLocation loc )
@@ -305,15 +306,18 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
sprintf( filename, "%s.new.%d", modifyFile.c_str(), getpid()); sprintf( filename, "%s.new.%d", modifyFile.c_str(), getpid());
std::string error; std::string error;
bool bOk = false; bool bOk = false;
std::error_code ec;
std::unique_ptr<raw_fd_ostream> ostream( std::unique_ptr<raw_fd_ostream> ostream(
compat::create_raw_fd_ostream(filename, error) ); new raw_fd_ostream(filename, ec, sys::fs::F_None));
if( error.empty()) if( !ec)
{ {
it->second.write( *ostream ); it->second.write( *ostream );
ostream->close(); ostream->close();
if( !ostream->has_error() && rename( filename, modifyFile.c_str()) == 0 ) if( !ostream->has_error() && rename( filename, modifyFile.c_str()) == 0 )
bOk = true; bOk = true;
} }
else
error = "error: " + ec.message();
ostream->clear_error(); ostream->clear_error();
unlink( filename ); unlink( filename );
if( !bOk ) if( !bOk )
@@ -323,17 +327,10 @@ void PluginHandler::HandleTranslationUnit( ASTContext& context )
#endif #endif
} }
#if CLANG_VERSION >= 30600
std::unique_ptr<ASTConsumer> LibreOfficeAction::CreateASTConsumer( CompilerInstance& Compiler, StringRef ) std::unique_ptr<ASTConsumer> LibreOfficeAction::CreateASTConsumer( CompilerInstance& Compiler, StringRef )
{ {
return llvm::make_unique<PluginHandler>( Compiler, _args ); return llvm::make_unique<PluginHandler>( Compiler, _args );
} }
#else
ASTConsumer* LibreOfficeAction::CreateASTConsumer( CompilerInstance& Compiler, StringRef )
{
return new PluginHandler( Compiler, _args );
}
#endif
bool LibreOfficeAction::ParseArgs( const CompilerInstance&, const std::vector< std::string >& args ) bool LibreOfficeAction::ParseArgs( const CompilerInstance&, const std::vector< std::string >& args )
{ {

View File

@@ -80,11 +80,7 @@ class LibreOfficeAction
: public PluginASTAction : public PluginASTAction
{ {
public: public:
#if CLANG_VERSION >= 30600
virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile ); virtual std::unique_ptr<ASTConsumer> CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#else
virtual ASTConsumer* CreateASTConsumer( CompilerInstance& Compiler, StringRef InFile );
#endif
virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args ); virtual bool ParseArgs( const CompilerInstance& CI, const std::vector< std::string >& args );
private: private:

View File

@@ -103,20 +103,10 @@ public:
} }
} }
bool TraverseInitListExpr( bool TraverseInitListExpr(InitListExpr * expr, DataRecursionQueue * queue = nullptr) {
InitListExpr * expr
#if CLANG_VERSION >= 30800
, DataRecursionQueue * queue = nullptr
#endif
)
{
return WalkUpFromInitListExpr(expr) return WalkUpFromInitListExpr(expr)
&& TraverseSynOrSemInitListExpr( && TraverseSynOrSemInitListExpr(
expr->isSemanticForm() ? expr : expr->getSemanticForm() expr->isSemanticForm() ? expr : expr->getSemanticForm(), queue);
#if CLANG_VERSION >= 30800
, queue
#endif
);
} }
bool VisitImplicitCastExpr(ImplicitCastExpr const * expr); bool VisitImplicitCastExpr(ImplicitCastExpr const * expr);
@@ -806,7 +796,7 @@ bool RedundantCast::visitBinOp(BinaryOperator const * expr) {
bool RedundantCast::isOverloadedFunction(FunctionDecl const * decl) { bool RedundantCast::isOverloadedFunction(FunctionDecl const * decl) {
auto const ctx = decl->getDeclContext(); auto const ctx = decl->getDeclContext();
if (!compat::isLookupContext(*ctx)) { if (!ctx->isLookupContext()) {
return false; return false;
} }
auto const canon = decl->getCanonicalDecl(); auto const canon = decl->getCanonicalDecl();

View File

@@ -11,7 +11,6 @@
#include <iostream> #include <iostream>
#include "check.hxx" #include "check.hxx"
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
#include "clang/AST/CXXInheritance.h" #include "clang/AST/CXXInheritance.h"
@@ -95,15 +94,10 @@ bool isDerivedFrom(const CXXRecordDecl *decl, DeclChecker base) {
if (!decl->hasDefinition()) { if (!decl->hasDefinition()) {
return false; return false;
} }
if (!compat::forallBases( if (!decl->forallBases(
*decl,
#if CLANG_VERSION < 30800
BaseCheckNotSubclass,
#else
[&base](const CXXRecordDecl *BaseDefinition) -> bool [&base](const CXXRecordDecl *BaseDefinition) -> bool
{ return BaseCheckNotSubclass(BaseDefinition, &base); }, { return BaseCheckNotSubclass(BaseDefinition, &base); },
#endif true))
&base, true))
{ {
return true; return true;
} }
@@ -550,7 +544,7 @@ bool RefCounting::VisitFunctionDecl(const FunctionDecl * functionDecl) {
if (methodDecl && methodDecl->size_overridden_methods() > 0) { if (methodDecl && methodDecl->size_overridden_methods() > 0) {
return true; return true;
} }
checkUnoReference(compat::getReturnType(*functionDecl), functionDecl, nullptr, "return"); checkUnoReference(functionDecl->getReturnType(), functionDecl, nullptr, "return");
return true; return true;
} }

View File

@@ -59,7 +59,6 @@ void ReservedId::run() {
if (TraverseDecl(compiler.getASTContext().getTranslationUnitDecl()) if (TraverseDecl(compiler.getASTContext().getTranslationUnitDecl())
&& compiler.hasPreprocessor()) && compiler.hasPreprocessor())
{ {
#if CLANG_VERSION >= 30700
auto & prep = compiler.getPreprocessor(); auto & prep = compiler.getPreprocessor();
for (auto const & m: prep.macros(false)) { for (auto const & m: prep.macros(false)) {
auto id = m.first->getName(); auto id = m.first->getName();
@@ -129,7 +128,6 @@ void ReservedId::run() {
} }
} }
} }
#endif
} }
} }

View File

@@ -108,7 +108,7 @@ BoolOverloadKind isBoolOverloadOf(
// encounter in practice: // encounter in practice:
bool hasBoolOverload(FunctionDecl const * decl, bool mustBeDeleted) { bool hasBoolOverload(FunctionDecl const * decl, bool mustBeDeleted) {
auto ctx = decl->getDeclContext(); auto ctx = decl->getDeclContext();
if (!compat::isLookupContext(*ctx)) { if (!ctx->isLookupContext()) {
return false; return false;
} }
auto res = ctx->lookup(decl->getDeclName()); auto res = ctx->lookup(decl->getDeclName());
@@ -285,8 +285,8 @@ bool SalBool::VisitCallExpr(CallExpr * expr) {
} }
} }
if (ft != nullptr) { if (ft != nullptr) {
for (unsigned i = 0; i != compat::getNumParams(*ft); ++i) { for (unsigned i = 0; i != ft->getNumParams(); ++i) {
QualType t(compat::getParamType(*ft, i)); QualType t(ft->getParamType(i));
bool b = false; bool b = false;
if (t->isLValueReferenceType()) { if (t->isLValueReferenceType()) {
t = t.getNonReferenceType(); t = t.getNonReferenceType();
@@ -688,7 +688,7 @@ bool SalBool::VisitFunctionDecl(FunctionDecl const * decl) {
if (ignoreLocation(decl)) { if (ignoreLocation(decl)) {
return true; return true;
} }
if (isSalBool(compat::getReturnType(*decl).getNonReferenceType()) if (isSalBool(decl->getReturnType().getNonReferenceType())
&& !(decl->isDeletedAsWritten() && isa<CXXConversionDecl>(decl))) && !(decl->isDeletedAsWritten() && isa<CXXConversionDecl>(decl)))
{ {
FunctionDecl const * f = decl->getCanonicalDecl(); FunctionDecl const * f = decl->getCanonicalDecl();

View File

@@ -11,7 +11,6 @@
#include <iostream> #include <iostream>
#include "plugin.hxx" #include "plugin.hxx"
#include "compat.hxx"
#include "check.hxx" #include "check.hxx"
#include "clang/AST/CXXInheritance.h" #include "clang/AST/CXXInheritance.h"
@@ -34,13 +33,7 @@ public:
bool VisitCXXRecordDecl( const CXXRecordDecl* ); bool VisitCXXRecordDecl( const CXXRecordDecl* );
}; };
bool BaseCheckNotSfxPoolItemSubclass( bool BaseCheckNotSfxPoolItemSubclass(const CXXRecordDecl *BaseDefinition) {
const CXXRecordDecl *BaseDefinition
#if CLANG_VERSION < 30800
, void *
#endif
)
{
if (BaseDefinition && loplugin::TypeCheck(BaseDefinition).Class("SfxPoolItem").GlobalNamespace()) { if (BaseDefinition && loplugin::TypeCheck(BaseDefinition).Class("SfxPoolItem").GlobalNamespace()) {
return false; return false;
} }
@@ -58,20 +51,14 @@ bool isDerivedFromSfxPoolItem(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!compat::forallBases(*decl, BaseCheckNotSfxPoolItemSubclass, nullptr, true)) { !decl->forallBases(BaseCheckNotSfxPoolItemSubclass, true)) {
return true; return true;
} }
return false; return false;
} }
bool BaseCheckNotSwMsgPoolItemSubclass( bool BaseCheckNotSwMsgPoolItemSubclass(const CXXRecordDecl *BaseDefinition) {
const CXXRecordDecl *BaseDefinition
#if CLANG_VERSION < 30800
, void *
#endif
)
{
if (BaseDefinition && loplugin::TypeCheck(BaseDefinition).Class("SwMsgPoolItem")) { if (BaseDefinition && loplugin::TypeCheck(BaseDefinition).Class("SwMsgPoolItem")) {
return false; return false;
} }
@@ -89,7 +76,7 @@ bool isDerivedFromSwMsgPoolItem(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!compat::forallBases(*decl, BaseCheckNotSwMsgPoolItemSubclass, nullptr, true)) { !decl->forallBases(BaseCheckNotSwMsgPoolItemSubclass, true)) {
return true; return true;
} }
return false; return false;

View File

@@ -13,7 +13,6 @@
#include <fstream> #include <fstream>
#include <set> #include <set>
#include "plugin.hxx" #include "plugin.hxx"
#include "compat.hxx"
/** /**
Look for fields that are only ever assigned a single constant value. Look for fields that are only ever assigned a single constant value.
@@ -262,7 +261,7 @@ bool SingleValFields::VisitMemberExpr( const MemberExpr* memberExpr )
if (parentFunction && parent && isa<ReturnStmt>(parent)) { if (parentFunction && parent && isa<ReturnStmt>(parent)) {
const Stmt* parent2 = getParentStmt(parent); const Stmt* parent2 = getParentStmt(parent);
if (parent2 && isa<CompoundStmt>(parent2)) { if (parent2 && isa<CompoundStmt>(parent2)) {
QualType qt = compat::getReturnType(*parentFunction).getDesugaredType(compiler.getASTContext()); QualType qt = parentFunction->getReturnType().getDesugaredType(compiler.getASTContext());
if (!qt.isConstQualified() && qt->isReferenceType()) { if (!qt.isConstQualified() && qt->isReferenceType()) {
bPotentiallyAssignedTo = true; bPotentiallyAssignedTo = true;
} }
@@ -449,10 +448,10 @@ void SingleValFields::checkCallExpr(const Stmt* child, const CallExpr* callExpr,
return; return;
} }
for (unsigned i = 0; i < callExpr->getNumArgs(); ++i) { for (unsigned i = 0; i < callExpr->getNumArgs(); ++i) {
if (i >= compat::getNumParams(*proto)) // can happen in template code if (i >= proto->getNumParams()) // can happen in template code
break; break;
if (callExpr->getArg(i) == child) { if (callExpr->getArg(i) == child) {
QualType qt = compat::getParamType(*proto, i).getDesugaredType(compiler.getASTContext()); QualType qt = proto->getParamType(i).getDesugaredType(compiler.getASTContext());
if (!qt.isConstQualified() && qt->isReferenceType()) { if (!qt.isConstQualified() && qt->isReferenceType()) {
assignValue = "?"; assignValue = "?";
bPotentiallyAssignedTo = true; bPotentiallyAssignedTo = true;

View File

@@ -10,7 +10,6 @@
#include "clang/AST/Attr.h" #include "clang/AST/Attr.h"
#include "check.hxx" #include "check.hxx"
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
/* /*
@@ -39,13 +38,7 @@ private:
StringRef getFilename(SourceLocation loc); StringRef getFilename(SourceLocation loc);
}; };
bool BaseCheckNotTestFixtureSubclass( bool BaseCheckNotTestFixtureSubclass(const CXXRecordDecl *BaseDefinition) {
const CXXRecordDecl *BaseDefinition
#if CLANG_VERSION < 30800
, void *
#endif
)
{
if (loplugin::TypeCheck(BaseDefinition).Class("TestFixture").Namespace("CppUnit").GlobalNamespace()) { if (loplugin::TypeCheck(BaseDefinition).Class("TestFixture").Namespace("CppUnit").GlobalNamespace()) {
return false; return false;
} }
@@ -58,7 +51,7 @@ bool isDerivedFromTestFixture(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!compat::forallBases(*decl, BaseCheckNotTestFixtureSubclass, nullptr, true)) { !decl->forallBases(BaseCheckNotTestFixtureSubclass, true)) {
return true; return true;
} }
return false; return false;

View File

@@ -11,7 +11,6 @@
#include <string> #include <string>
#include <iostream> #include <iostream>
#include "plugin.hxx" #include "plugin.hxx"
#include "compat.hxx"
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/types.h> #include <sys/types.h>
#include <fcntl.h> #include <fcntl.h>
@@ -75,7 +74,7 @@ std::string niceName(const CXXMethodDecl* functionDecl)
{ {
std::string s = std::string s =
functionDecl->getParent()->getQualifiedNameAsString() + "::" functionDecl->getParent()->getQualifiedNameAsString() + "::"
+ compat::getReturnType(*functionDecl).getAsString() + "-" + functionDecl->getReturnType().getAsString() + "-"
+ functionDecl->getNameAsString() + "("; + functionDecl->getNameAsString() + "(";
for (const ParmVarDecl *pParmVarDecl : functionDecl->params()) { for (const ParmVarDecl *pParmVarDecl : functionDecl->params()) {
s += pParmVarDecl->getType().getAsString(); s += pParmVarDecl->getType().getAsString();

View File

@@ -10,7 +10,6 @@
#include <string> #include <string>
#include <set> #include <set>
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
// Find places where we are returning a pointer to something, where we can be returning a reference. // Find places where we are returning a pointer to something, where we can be returning a reference.
@@ -55,7 +54,7 @@ bool ReturnByRef::VisitCXXMethodDecl(const CXXMethodDecl * functionDecl) {
if (isInUnoIncludeFile(functionDecl)) { if (isInUnoIncludeFile(functionDecl)) {
return true; return true;
} }
QualType t1 { compat::getReturnType(*functionDecl) }; QualType t1 { functionDecl->getReturnType() };
if (!t1->isPointerType()) { if (!t1->isPointerType()) {
return true; return true;
} }

View File

@@ -11,8 +11,6 @@
#include <config_clang.h> #include <config_clang.h>
// '#if CLANG_VERSION >= 30800' covers large parts of compilerplugins/clang/datamembershadow.cxx
#if CLANG_VERSION >= 30800
struct Bar { struct Bar {
int x; // expected-note {{superclass member here [loplugin:datamembershadow]}} int x; // expected-note {{superclass member here [loplugin:datamembershadow]}}
}; };
@@ -20,8 +18,5 @@ struct Bar {
struct Foo : public Bar { struct Foo : public Bar {
int x; // expected-error {{data member x is shadowing member in superclass, through inheritance path Foo->Bar [loplugin:datamembershadow]}} int x; // expected-error {{data member x is shadowing member in superclass, through inheritance path Foo->Bar [loplugin:datamembershadow]}}
}; };
#else
// expected-no-diagnostics
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

View File

@@ -14,7 +14,6 @@
#include <set> #include <set>
#include <clang/AST/CXXInheritance.h> #include <clang/AST/CXXInheritance.h>
#include "compat.hxx"
#include "plugin.hxx" #include "plugin.hxx"
/** /**
@@ -102,12 +101,7 @@ public:
private: private:
const CXXMethodDecl * findOverriddenOrSimilarMethodInSuperclasses(const CXXMethodDecl *); const CXXMethodDecl * findOverriddenOrSimilarMethodInSuperclasses(const CXXMethodDecl *);
bool BaseCheckCallback( bool BaseCheckCallback(const CXXRecordDecl *BaseDefinition);
const CXXRecordDecl *BaseDefinition
#if CLANG_VERSION < 30800
, void *
#endif
);
}; };
bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl) bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
@@ -277,8 +271,8 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
} }
} }
if (compat::getReturnType(*methodDecl).getCanonicalType() if (methodDecl->getReturnType().getCanonicalType()
!= compat::getReturnType(*overriddenMethodDecl).getCanonicalType()) != overriddenMethodDecl->getReturnType().getCanonicalType())
{ {
return true; return true;
} }
@@ -290,7 +284,7 @@ bool UnnecessaryOverride::VisitCXXMethodDecl(const CXXMethodDecl* methodDecl)
return true; return true;
const CXXMemberCallExpr* callExpr = nullptr; const CXXMemberCallExpr* callExpr = nullptr;
if (compat::getReturnType(*methodDecl).getCanonicalType()->isVoidType()) if (methodDecl->getReturnType().getCanonicalType()->isVoidType())
{ {
if (auto const e = dyn_cast<Expr>(*compoundStmt->body_begin())) { if (auto const e = dyn_cast<Expr>(*compoundStmt->body_begin())) {
callExpr = dyn_cast<CXXMemberCallExpr>(e->IgnoreImplicit()->IgnoreParens()); callExpr = dyn_cast<CXXMemberCallExpr>(e->IgnoreImplicit()->IgnoreParens());
@@ -395,9 +389,6 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
return nullptr; return nullptr;
} }
#if CLANG_VERSION < 30800
return nullptr;
#else
std::vector<const CXXMethodDecl*> maSimilarMethods; std::vector<const CXXMethodDecl*> maSimilarMethods;
auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& ) auto BaseMatchesCallback = [&](const CXXBaseSpecifier *cxxBaseSpecifier, CXXBasePath& )
@@ -425,8 +416,8 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
{ {
continue; continue;
} }
if (compat::getReturnType(*methodDecl).getCanonicalType() if (methodDecl->getReturnType().getCanonicalType()
!= compat::getReturnType(*baseMethod).getCanonicalType()) != baseMethod->getReturnType().getCanonicalType())
{ {
continue; continue;
} }
@@ -454,7 +445,6 @@ const CXXMethodDecl* UnnecessaryOverride::findOverriddenOrSimilarMethodInSupercl
return maSimilarMethods[0]; return maSimilarMethods[0];
} }
return nullptr; return nullptr;
#endif
} }

View File

@@ -84,7 +84,7 @@ std::string niceName(const CXXMethodDecl* functionDecl)
{ {
std::string s = std::string s =
functionDecl->getParent()->getQualifiedNameAsString() + "::" functionDecl->getParent()->getQualifiedNameAsString() + "::"
+ compat::getReturnType(*functionDecl).getAsString() + "-" + functionDecl->getReturnType().getAsString() + "-"
+ functionDecl->getNameAsString() + "("; + functionDecl->getNameAsString() + "(";
for (const ParmVarDecl *pParmVarDecl : compat::parameters(*functionDecl)) { for (const ParmVarDecl *pParmVarDecl : compat::parameters(*functionDecl)) {
s += pParmVarDecl->getType().getAsString(); s += pParmVarDecl->getType().getAsString();

View File

@@ -136,11 +136,8 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
functionDecl = functionDecl->getInstantiatedFromMemberFunction(); functionDecl = functionDecl->getInstantiatedFromMemberFunction();
else if (functionDecl->getClassScopeSpecializationPattern()) else if (functionDecl->getClassScopeSpecializationPattern())
functionDecl = functionDecl->getClassScopeSpecializationPattern(); functionDecl = functionDecl->getClassScopeSpecializationPattern();
// workaround clang-3.5 issue
#if CLANG_VERSION >= 30600
else if (functionDecl->getTemplateInstantiationPattern()) else if (functionDecl->getTemplateInstantiationPattern())
functionDecl = functionDecl->getTemplateInstantiationPattern(); functionDecl = functionDecl->getTemplateInstantiationPattern();
#endif
MyFuncInfo aInfo; MyFuncInfo aInfo;
switch (functionDecl->getAccess()) switch (functionDecl->getAccess())
@@ -151,7 +148,7 @@ MyFuncInfo UnusedMethods::niceName(const FunctionDecl* functionDecl)
default: aInfo.access = "unknown"; break; default: aInfo.access = "unknown"; break;
} }
if (!isa<CXXConstructorDecl>(functionDecl)) { if (!isa<CXXConstructorDecl>(functionDecl)) {
aInfo.returnType = compat::getReturnType(*functionDecl).getCanonicalType().getAsString(); aInfo.returnType = functionDecl->getReturnType().getCanonicalType().getAsString();
} else { } else {
aInfo.returnType = ""; aInfo.returnType = "";
} }
@@ -262,7 +259,7 @@ gotfunc:
} }
// Now do the checks necessary for the "unused return value" analysis // Now do the checks necessary for the "unused return value" analysis
if (compat::getReturnType(*calleeFunctionDecl)->isVoidType()) { if (calleeFunctionDecl->getReturnType()->isVoidType()) {
return true; return true;
} }
if (!parent) { if (!parent) {

View File

@@ -76,7 +76,7 @@ UnusedMethodsRemove::~UnusedMethodsRemove()
std::string niceName(const CXXMethodDecl* functionDecl) std::string niceName(const CXXMethodDecl* functionDecl)
{ {
std::string s = std::string s =
compat::getReturnType(*functionDecl).getCanonicalType().getAsString() functionDecl->getReturnType().getCanonicalType().getAsString()
+ " " + functionDecl->getParent()->getQualifiedNameAsString() + " " + functionDecl->getParent()->getQualifiedNameAsString()
+ "::" + functionDecl->getNameAsString() + "::" + functionDecl->getNameAsString()
+ "("; + "(";

View File

@@ -12,7 +12,6 @@
#include <iostream> #include <iostream>
#include "plugin.hxx" #include "plugin.hxx"
#include "compat.hxx"
#include "check.hxx" #include "check.hxx"
#include "clang/AST/CXXInheritance.h" #include "clang/AST/CXXInheritance.h"
@@ -55,13 +54,7 @@ private:
#define BASE_REF_COUNTED_CLASS "VclReferenceBase" #define BASE_REF_COUNTED_CLASS "VclReferenceBase"
bool BaseCheckNotWindowSubclass( bool BaseCheckNotWindowSubclass(const CXXRecordDecl *BaseDefinition) {
const CXXRecordDecl *BaseDefinition
#if CLANG_VERSION < 30800
, void *
#endif
)
{
return !loplugin::DeclCheck(BaseDefinition).Class(BASE_REF_COUNTED_CLASS) return !loplugin::DeclCheck(BaseDefinition).Class(BASE_REF_COUNTED_CLASS)
.GlobalNamespace(); .GlobalNamespace();
} }
@@ -80,7 +73,7 @@ bool isDerivedFromVclReferenceBase(const CXXRecordDecl *decl) {
if (// not sure what hasAnyDependentBases() does, if (// not sure what hasAnyDependentBases() does,
// but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1 // but it avoids classes we don't want, e.g. WeakAggComponentImplHelper1
!decl->hasAnyDependentBases() && !decl->hasAnyDependentBases() &&
!compat::forallBases(*decl, BaseCheckNotWindowSubclass, nullptr, true)) { !decl->forallBases(BaseCheckNotWindowSubclass, true)) {
return true; return true;
} }
return false; return false;

View File

@@ -5921,8 +5921,7 @@ if test "$GCC" = "yes" -o "$COM_IS_CLANG" = TRUE; then
], [AC_MSG_RESULT([no])]) ], [AC_MSG_RESULT([no])])
AC_LANG_POP([C++]) AC_LANG_POP([C++])
dnl Available in GCC 4.9 and at least in Clang 3.4 (which is the baseline dnl Available in GCC 4.9 and at least since Clang 3.4:
dnl for at least --enable-compiler-plugins according to README.md):
AC_MSG_CHECKING([whether $CXX supports __attribute__((warn_unused))]) AC_MSG_CHECKING([whether $CXX supports __attribute__((warn_unused))])
AC_LANG_PUSH([C++]) AC_LANG_PUSH([C++])
save_CXXFLAGS=$CXXFLAGS save_CXXFLAGS=$CXXFLAGS
@@ -6419,6 +6418,13 @@ if test "$COM_IS_CLANG" = "TRUE"; then
else else
compiler_plugins=no compiler_plugins=no
fi fi
if test "$compiler_plugins" != no -a "$CLANGVER" -lt 30800; then
if test "$compiler_plugins" = yes; then
AC_MSG_ERROR([Clang $CLANGVER is too old to build compiler plugins; need >= 3.8.0.])
else
compiler_plugins=no
fi
fi
if test "$compiler_plugins" != "no"; then if test "$compiler_plugins" != "no"; then
dnl The prefix where Clang resides, override to where Clang resides if dnl The prefix where Clang resides, override to where Clang resides if
dnl using a source build: dnl using a source build: