Adapt compilerplugins to Clang 17 trunk "Remove llvm::Optional"
(<397f2e9ebe
>)
Change-Id: I51acda5951f8250d1a1b47e1c2612199ae7338a2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152618
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
parent
c2c1e6a272
commit
6f33d21fdd
@ -15,11 +15,10 @@
|
||||
#include <fstream>
|
||||
#include <set>
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
|
||||
#include "config_clang.h"
|
||||
|
||||
#include "check.hxx"
|
||||
#include "compat.hxx"
|
||||
#include "plugin.hxx"
|
||||
|
||||
/**
|
||||
@ -74,7 +73,7 @@ bool ColorCheck::VisitCXXConstructExpr(const CXXConstructExpr* constructExpr)
|
||||
{
|
||||
if (!arg0->isValueDependent())
|
||||
{
|
||||
llvm::Optional<llvm::APSInt> xVal
|
||||
compat::optional<llvm::APSInt> xVal
|
||||
= arg0->getIntegerConstantExpr(compiler.getASTContext());
|
||||
if (xVal && *xVal > 0xffffff)
|
||||
report(DiagnosticsEngine::Warning,
|
||||
|
@ -16,17 +16,29 @@
|
||||
#include "clang/AST/ExprCXX.h"
|
||||
#include "clang/Basic/SourceManager.h"
|
||||
#include "clang/Basic/Specifiers.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
|
||||
#include "config_clang.h"
|
||||
|
||||
#if CLANG_VERSION >= 170000
|
||||
#include <optional>
|
||||
#else
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#endif
|
||||
|
||||
// Compatibility wrapper to abstract over (trivial) changes in the Clang API:
|
||||
namespace compat {
|
||||
|
||||
template<typename T>
|
||||
constexpr bool has_value(llvm::Optional<T> const & o) {
|
||||
#if CLANG_VERSION >= 170000
|
||||
using optional = std::optional<T>;
|
||||
#else
|
||||
using optional = llvm::Optional<T>;
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
constexpr bool has_value(optional<T> const & o) {
|
||||
#if CLANG_VERSION >= 150000
|
||||
return o.has_value();
|
||||
#else
|
||||
@ -35,7 +47,7 @@ constexpr bool has_value(llvm::Optional<T> const & o) {
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
constexpr T const & value(llvm::Optional<T> const & o) {
|
||||
constexpr T const & value(optional<T> const & o) {
|
||||
#if CLANG_VERSION >= 150000
|
||||
return *o;
|
||||
#else
|
||||
|
@ -13,9 +13,8 @@
|
||||
#include <cassert>
|
||||
#include <map>
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
|
||||
#include "check.hxx"
|
||||
#include "compat.hxx"
|
||||
#include "plugin.hxx"
|
||||
|
||||
// Find cases where a variable of a OString/OUString type is initialized
|
||||
@ -447,7 +446,7 @@ private:
|
||||
{
|
||||
}
|
||||
Stmt const* innermostLoop;
|
||||
llvm::Optional<Expr const*> singleUse;
|
||||
compat::optional<Expr const*> singleUse;
|
||||
};
|
||||
|
||||
std::stack<Stmt const*> innermostLoop_;
|
||||
|
@ -7,8 +7,8 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "compat.hxx"
|
||||
#include "plugin.hxx"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
@ -49,7 +49,8 @@ private:
|
||||
SourceRange ignoreMacroExpansions(SourceRange range);
|
||||
SourceRange extendOverComments(SourceRange range);
|
||||
std::string getSourceAsString(SourceRange range);
|
||||
llvm::Optional<std::string> invertCondition(Expr const * condExpr, SourceRange conditionRange);
|
||||
compat::optional<std::string> invertCondition(
|
||||
Expr const * condExpr, SourceRange conditionRange);
|
||||
bool isLargeCompoundStmt(Stmt const *);
|
||||
|
||||
Stmt const * lastStmtInCompoundStmt = nullptr;
|
||||
@ -302,7 +303,7 @@ bool Flatten::rewrite1(IfStmt const * ifStmt)
|
||||
|
||||
// in adjusting the formatting I assume that "{" starts on a new line
|
||||
|
||||
llvm::Optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange);
|
||||
compat::optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange);
|
||||
if (!conditionString)
|
||||
return false;
|
||||
|
||||
@ -392,7 +393,7 @@ bool Flatten::rewriteLargeIf(IfStmt const * ifStmt)
|
||||
|
||||
// in adjusting the formatting I assume that "{" starts on a new line
|
||||
|
||||
llvm::Optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange);
|
||||
compat::optional<std::string> conditionString = invertCondition(ifStmt->getCond(), conditionRange);
|
||||
if (!conditionString)
|
||||
return false;
|
||||
|
||||
@ -416,7 +417,7 @@ bool Flatten::rewriteLargeIf(IfStmt const * ifStmt)
|
||||
return true;
|
||||
}
|
||||
|
||||
llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, SourceRange conditionRange)
|
||||
compat::optional<std::string> Flatten::invertCondition(Expr const * condExpr, SourceRange conditionRange)
|
||||
{
|
||||
std::string s = getSourceAsString(conditionRange);
|
||||
|
||||
@ -455,7 +456,7 @@ llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, Sour
|
||||
s = "!(" + s + ")";
|
||||
}
|
||||
if (!ok)
|
||||
return llvm::Optional<std::string>();
|
||||
return compat::optional<std::string>();
|
||||
}
|
||||
else if (auto opCallExpr = dyn_cast<CXXOperatorCallExpr>(condExpr))
|
||||
{
|
||||
@ -472,7 +473,7 @@ llvm::Optional<std::string> Flatten::invertCondition(Expr const * condExpr, Sour
|
||||
s = "!(" + s + ")";
|
||||
}
|
||||
if (!ok)
|
||||
return llvm::Optional<std::string>();
|
||||
return compat::optional<std::string>();
|
||||
}
|
||||
else if (isa<DeclRefExpr>(condExpr) || isa<CallExpr>(condExpr) || isa<MemberExpr>(condExpr))
|
||||
s = "!" + s;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "plugin.hxx"
|
||||
#include "check.hxx"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "compat.hxx"
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
@ -35,7 +35,7 @@ public:
|
||||
bool VisitBinaryOperator(BinaryOperator const*);
|
||||
|
||||
private:
|
||||
llvm::Optional<double> getExprValue(Expr const* expr);
|
||||
compat::optional<double> getExprValue(Expr const* expr);
|
||||
};
|
||||
|
||||
bool IntVsFloat::VisitVarDecl(VarDecl const* varDecl)
|
||||
@ -49,7 +49,7 @@ bool IntVsFloat::VisitVarDecl(VarDecl const* varDecl)
|
||||
if (varDecl->getType()->isFloatingType())
|
||||
return true;
|
||||
// init->dump();
|
||||
llvm::Optional<double> d = getExprValue(init);
|
||||
compat::optional<double> d = getExprValue(init);
|
||||
if (!d)
|
||||
return true;
|
||||
if (static_cast<long>(*d) == *d)
|
||||
@ -77,7 +77,7 @@ bool IntVsFloat::VisitBinaryOperator(BinaryOperator const* op)
|
||||
return true;
|
||||
if (rhs->getType()->isFloatingType())
|
||||
return true;
|
||||
llvm::Optional<double> d = getExprValue(lhs);
|
||||
compat::optional<double> d = getExprValue(lhs);
|
||||
if (!d)
|
||||
return true;
|
||||
if (static_cast<long>(*d) == *d)
|
||||
@ -88,18 +88,18 @@ bool IntVsFloat::VisitBinaryOperator(BinaryOperator const* op)
|
||||
return true;
|
||||
}
|
||||
|
||||
llvm::Optional<double> IntVsFloat::getExprValue(Expr const* expr)
|
||||
compat::optional<double> IntVsFloat::getExprValue(Expr const* expr)
|
||||
{
|
||||
// Of the available clang Evaluate* APIs, this is the __only__ one that produces useful output
|
||||
// (as of 17 Aug 2018 checkout of clang, ie. towards clang 7)
|
||||
|
||||
if (expr->isValueDependent())
|
||||
return llvm::Optional<double>();
|
||||
return compat::optional<double>();
|
||||
Expr::EvalResult evalResult;
|
||||
if (!expr->EvaluateAsRValue(evalResult, compiler.getASTContext()))
|
||||
return llvm::Optional<double>();
|
||||
return compat::optional<double>();
|
||||
if (!evalResult.Val.isFloat())
|
||||
return llvm::Optional<double>();
|
||||
return compat::optional<double>();
|
||||
llvm::APFloat floatResult = evalResult.Val.getFloat();
|
||||
bool losesInfo;
|
||||
floatResult.convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &losesInfo);
|
||||
|
@ -9,12 +9,11 @@
|
||||
// versions before 9.0 didn't have getExceptionSpecType
|
||||
|
||||
#include "check.hxx"
|
||||
#include "compat.hxx"
|
||||
#include "plugin.hxx"
|
||||
|
||||
#include "config_clang.h"
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
@ -55,7 +54,7 @@ public:
|
||||
bool VisitVarDecl(const VarDecl*);
|
||||
|
||||
private:
|
||||
llvm::Optional<bool> IsCallThrows(const CallExpr* callExpr);
|
||||
compat::optional<bool> IsCallThrows(const CallExpr* callExpr);
|
||||
std::vector<bool> m_ConstructorThrows;
|
||||
std::vector<std::vector<const Decl*>> m_Exclusions;
|
||||
std::vector<bool> m_CannotFix;
|
||||
@ -173,7 +172,7 @@ bool NoExceptMove::VisitCallExpr(const CallExpr* callExpr)
|
||||
return true;
|
||||
if (m_ConstructorThrows.empty())
|
||||
return true;
|
||||
llvm::Optional<bool> bCallThrows = IsCallThrows(callExpr);
|
||||
compat::optional<bool> bCallThrows = IsCallThrows(callExpr);
|
||||
if (!bCallThrows)
|
||||
{
|
||||
callExpr->dump();
|
||||
@ -252,7 +251,7 @@ bool NoExceptMove::VisitVarDecl(const VarDecl* varDecl)
|
||||
return true;
|
||||
}
|
||||
|
||||
llvm::Optional<bool> NoExceptMove::IsCallThrows(const CallExpr* callExpr)
|
||||
compat::optional<bool> NoExceptMove::IsCallThrows(const CallExpr* callExpr)
|
||||
{
|
||||
const FunctionDecl* calleeFunctionDecl = callExpr->getDirectCallee();
|
||||
if (calleeFunctionDecl)
|
||||
@ -302,7 +301,7 @@ llvm::Optional<bool> NoExceptMove::IsCallThrows(const CallExpr* callExpr)
|
||||
else
|
||||
{
|
||||
m_CannotFix.back() = true;
|
||||
return llvm::Optional<bool>();
|
||||
return compat::optional<bool>();
|
||||
}
|
||||
|
||||
// allowlist of functions that could be noexcept, but we can't change them because of backwards-compatibility reasons
|
||||
@ -316,7 +315,7 @@ llvm::Optional<bool> NoExceptMove::IsCallThrows(const CallExpr* callExpr)
|
||||
if (!funcProto)
|
||||
{
|
||||
m_CannotFix.back() = true;
|
||||
return llvm::Optional<bool>();
|
||||
return compat::optional<bool>();
|
||||
}
|
||||
|
||||
auto est = funcProto->getExceptionSpecType();
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
bool VisitCallExpr(CallExpr const*);
|
||||
|
||||
private:
|
||||
llvm::Optional<APSInt> getCallValue(const Expr* arg);
|
||||
compat::optional<APSInt> getCallValue(const Expr* arg);
|
||||
std::vector<FunctionDecl*> functions_;
|
||||
};
|
||||
|
||||
@ -140,7 +140,7 @@ bool PointerBool::VisitCallExpr(CallExpr const* callExpr)
|
||||
return true;
|
||||
}
|
||||
|
||||
llvm::Optional<APSInt> PointerBool::getCallValue(const Expr* arg)
|
||||
compat::optional<APSInt> PointerBool::getCallValue(const Expr* arg)
|
||||
{
|
||||
arg = arg->IgnoreParenCasts();
|
||||
if (auto defArg = dyn_cast<CXXDefaultArgExpr>(arg))
|
||||
@ -150,14 +150,14 @@ llvm::Optional<APSInt> PointerBool::getCallValue(const Expr* arg)
|
||||
// ignore this, it seems to trigger an infinite recursion
|
||||
if (isa<UnaryExprOrTypeTraitExpr>(arg))
|
||||
{
|
||||
return llvm::Optional<APSInt>();
|
||||
return compat::optional<APSInt>();
|
||||
}
|
||||
APSInt x1;
|
||||
if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
|
||||
{
|
||||
return x1;
|
||||
}
|
||||
return llvm::Optional<APSInt>();
|
||||
return compat::optional<APSInt>();
|
||||
}
|
||||
|
||||
loplugin::Plugin::Registration<PointerBool> pointerbool("pointerbool");
|
||||
|
@ -170,7 +170,7 @@ private:
|
||||
bool checkForWriteWhenUsingCollectionType(const CXXMethodDecl * calleeMethodDecl);
|
||||
bool IsPassedByNonConst(const FieldDecl* fieldDecl, const Stmt * child, CallerWrapper callExpr,
|
||||
CalleeWrapper calleeFunctionDecl);
|
||||
llvm::Optional<CalleeWrapper> getCallee(CallExpr const *);
|
||||
compat::optional<CalleeWrapper> getCallee(CallExpr const *);
|
||||
|
||||
RecordDecl * insideMoveOrCopyOrCloneDeclParent = nullptr;
|
||||
RecordDecl * insideStreamOutputOperator = nullptr;
|
||||
@ -1173,7 +1173,7 @@ void UnusedFields::checkTouchedFromOutside(const FieldDecl* fieldDecl, const Exp
|
||||
}
|
||||
}
|
||||
|
||||
llvm::Optional<CalleeWrapper> UnusedFields::getCallee(CallExpr const * callExpr)
|
||||
compat::optional<CalleeWrapper> UnusedFields::getCallee(CallExpr const * callExpr)
|
||||
{
|
||||
FunctionDecl const * functionDecl = callExpr->getDirectCallee();
|
||||
if (functionDecl)
|
||||
@ -1187,7 +1187,7 @@ llvm::Optional<CalleeWrapper> UnusedFields::getCallee(CallExpr const * callExpr)
|
||||
}
|
||||
}
|
||||
|
||||
return llvm::Optional<CalleeWrapper>();
|
||||
return compat::optional<CalleeWrapper>();
|
||||
}
|
||||
|
||||
loplugin::Plugin::Registration< UnusedFields > X("unusedfields", false);
|
||||
|
@ -165,7 +165,7 @@ private:
|
||||
bool checkForWriteWhenUsingCollectionType(const CXXMethodDecl* calleeMethodDecl);
|
||||
bool IsPassedByNonConst(const VarDecl* fieldDecl, const Stmt* child, CallerWrapper callExpr,
|
||||
CalleeWrapper calleeFunctionDecl);
|
||||
llvm::Optional<CalleeWrapper> getCallee(CallExpr const*);
|
||||
compat::optional<CalleeWrapper> getCallee(CallExpr const*);
|
||||
|
||||
// For reasons I do not understand, parentFunctionDecl() is not reliable, so
|
||||
// we store the parent function on the way down the AST.
|
||||
@ -932,7 +932,7 @@ bool UnusedVarsGlobal::IsPassedByNonConst(const VarDecl* varDecl, const Stmt* ch
|
||||
return false;
|
||||
}
|
||||
|
||||
llvm::Optional<CalleeWrapper> UnusedVarsGlobal::getCallee(CallExpr const* callExpr)
|
||||
compat::optional<CalleeWrapper> UnusedVarsGlobal::getCallee(CallExpr const* callExpr)
|
||||
{
|
||||
FunctionDecl const* functionDecl = callExpr->getDirectCallee();
|
||||
if (functionDecl)
|
||||
@ -950,7 +950,7 @@ llvm::Optional<CalleeWrapper> UnusedVarsGlobal::getCallee(CallExpr const* callEx
|
||||
}
|
||||
}
|
||||
|
||||
return llvm::Optional<CalleeWrapper>();
|
||||
return compat::optional<CalleeWrapper>();
|
||||
}
|
||||
|
||||
loplugin::Plugin::Registration<UnusedVarsGlobal> X("unusedvarsglobal", false);
|
||||
|
@ -23,9 +23,9 @@
|
||||
|
||||
#include "plugin.hxx"
|
||||
#include "check.hxx"
|
||||
#include "compat.hxx"
|
||||
|
||||
#include "clang/AST/ParentMapContext.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
|
||||
/**
|
||||
Finds variables that are effectively write-only.
|
||||
@ -162,7 +162,7 @@ private:
|
||||
bool checkForWriteWhenUsingCollectionType(const CXXMethodDecl* calleeMethodDecl);
|
||||
bool IsPassedByNonConst(const VarDecl* varDecl, const Stmt* child, CallerWrapper callExpr,
|
||||
CalleeWrapper calleeFunctionDecl);
|
||||
llvm::Optional<CalleeWrapper> getCallee(CallExpr const*);
|
||||
compat::optional<CalleeWrapper> getCallee(CallExpr const*);
|
||||
|
||||
// For reasons I do not understand, parentFunctionDecl() is not reliable, so
|
||||
// we store the parent function on the way down the AST.
|
||||
@ -1111,7 +1111,7 @@ bool WriteOnlyVars::VisitDeclRefExpr(const DeclRefExpr* declRefExpr)
|
||||
return true;
|
||||
}
|
||||
|
||||
llvm::Optional<CalleeWrapper> WriteOnlyVars::getCallee(CallExpr const* callExpr)
|
||||
compat::optional<CalleeWrapper> WriteOnlyVars::getCallee(CallExpr const* callExpr)
|
||||
{
|
||||
FunctionDecl const* functionDecl = callExpr->getDirectCallee();
|
||||
if (functionDecl)
|
||||
@ -1129,7 +1129,7 @@ llvm::Optional<CalleeWrapper> WriteOnlyVars::getCallee(CallExpr const* callExpr)
|
||||
}
|
||||
}
|
||||
|
||||
return llvm::Optional<CalleeWrapper>();
|
||||
return compat::optional<CalleeWrapper>();
|
||||
}
|
||||
|
||||
loplugin::Plugin::Registration<WriteOnlyVars> X("writeonlyvars", false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user