summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-11-27 12:56:12 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-11-27 17:16:05 +0100
commit75dd5d2e734ad9e8265b1954c7496d1ba241079e (patch)
treeb3a694e1bbe01dcdfc917a01d44c36bde39e850b
parentecdf05d1b93529a0b1edda04d0f89c08cf580308 (diff)
add EvaluateAsInt compat function for latest clang
the old EvaluateAsInt method has been dropped as from current clang Change-Id: Ie30d1547ad8de777badff4b380d2fc9fb261e8fe Reviewed-on: https://gerrit.libreoffice.org/64107 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/compat.hxx12
-rw-r--r--compilerplugins/clang/constantparam.cxx2
-rw-r--r--compilerplugins/clang/expressionalwayszero.cxx2
-rw-r--r--compilerplugins/clang/loopvartoosmall.cxx2
-rw-r--r--compilerplugins/clang/plugin.cxx2
-rw-r--r--compilerplugins/clang/pointerbool.cxx2
-rw-r--r--compilerplugins/clang/returnconstant.cxx2
-rw-r--r--compilerplugins/clang/shouldreturnbool.cxx2
-rw-r--r--compilerplugins/clang/singlevalfields.cxx2
-rw-r--r--compilerplugins/clang/staticconstfield.cxx2
-rw-r--r--compilerplugins/clang/stringconstant.cxx14
-rw-r--r--compilerplugins/clang/unicodetochar.cxx2
-rw-r--r--compilerplugins/clang/unusedfields.cxx2
13 files changed, 30 insertions, 18 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx
index 4733cd332e5e..97410fcbdc7a 100644
--- a/compilerplugins/clang/compat.hxx
+++ b/compilerplugins/clang/compat.hxx
@@ -156,6 +156,18 @@ inline bool CPlusPlus17(clang::LangOptions const & opts) {
#endif
}
+inline bool EvaluateAsInt(clang::Expr const * expr, llvm::APSInt& intRes, const clang::ASTContext& ctx) {
+#if CLANG_VERSION >= 80000
+ clang::Expr::EvalResult res;
+ bool b = expr->EvaluateAsInt(res, ctx);
+ if (b && res.Val.isInt())
+ intRes = res.Val.getInt();
+ return b;
+#else
+ return expr->EvaluateAsInt(intRes, ctx);
+#endif
+}
+
// Work around <http://reviews.llvm.org/D22128>:
//
// SfxErrorHandler::GetClassString (svtools/source/misc/ehdl.cxx):
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index 34455ee00400..ffacf1102022 100644
--- a/compilerplugins/clang/constantparam.cxx
+++ b/compilerplugins/clang/constantparam.cxx
@@ -170,7 +170,7 @@ std::string ConstantParam::getCallValue(const Expr* arg)
return "unknown1";
}
APSInt x1;
- if (arg->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
return x1.toString(10);
}
diff --git a/compilerplugins/clang/expressionalwayszero.cxx b/compilerplugins/clang/expressionalwayszero.cxx
index c4762aecbc35..d53d20316a5d 100644
--- a/compilerplugins/clang/expressionalwayszero.cxx
+++ b/compilerplugins/clang/expressionalwayszero.cxx
@@ -139,7 +139,7 @@ std::unique_ptr<APSInt> ExpressionAlwaysZero::getExprValue(Expr const * expr)
return std::unique_ptr<APSInt>();
}
APSInt x1;
- if (expr->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(expr, x1, compiler.getASTContext()))
return std::unique_ptr<APSInt>(new APSInt(x1));
return std::unique_ptr<APSInt>();
}
diff --git a/compilerplugins/clang/loopvartoosmall.cxx b/compilerplugins/clang/loopvartoosmall.cxx
index 79503ceaeec6..7ebe34f22474 100644
--- a/compilerplugins/clang/loopvartoosmall.cxx
+++ b/compilerplugins/clang/loopvartoosmall.cxx
@@ -160,7 +160,7 @@ void LoopVarTooSmall::checkSubExpr(Expr const * expr, bool positive) {
//
// with dependent type T:
if (!binOpRHS->isValueDependent()
- && binOpRHS->EvaluateAsInt(aIntResult, compiler.getASTContext()))
+ && compat::EvaluateAsInt(binOpRHS, aIntResult, compiler.getASTContext()))
{
if (less && aIntResult.isStrictlyPositive()) {
--aIntResult;
diff --git a/compilerplugins/clang/plugin.cxx b/compilerplugins/clang/plugin.cxx
index ff12ebb2d6ba..2167cc0e2a7f 100644
--- a/compilerplugins/clang/plugin.cxx
+++ b/compilerplugins/clang/plugin.cxx
@@ -161,7 +161,7 @@ void Plugin::registerPlugin( Plugin* (*create)( const InstantiationData& ), cons
bool Plugin::evaluate(const Expr* expr, APSInt& x)
{
- if (expr->EvaluateAsInt(x, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(expr, x, compiler.getASTContext()))
{
return true;
}
diff --git a/compilerplugins/clang/pointerbool.cxx b/compilerplugins/clang/pointerbool.cxx
index bb5bdff136b5..a3ed40506b8b 100644
--- a/compilerplugins/clang/pointerbool.cxx
+++ b/compilerplugins/clang/pointerbool.cxx
@@ -110,7 +110,7 @@ llvm::Optional<APSInt> PointerBool::getCallValue(const Expr* arg)
return llvm::Optional<APSInt>();
}
APSInt x1;
- if (arg->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
return x1;
}
diff --git a/compilerplugins/clang/returnconstant.cxx b/compilerplugins/clang/returnconstant.cxx
index a11cff3d11de..8040396ef6d0 100644
--- a/compilerplugins/clang/returnconstant.cxx
+++ b/compilerplugins/clang/returnconstant.cxx
@@ -186,7 +186,7 @@ std::string ReturnConstant::getExprValue(Expr const* arg)
return "unknown";
}
APSInt x1;
- if (arg->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
return x1.toString(10);
}
diff --git a/compilerplugins/clang/shouldreturnbool.cxx b/compilerplugins/clang/shouldreturnbool.cxx
index 937dba126da0..03cc0c856a6f 100644
--- a/compilerplugins/clang/shouldreturnbool.cxx
+++ b/compilerplugins/clang/shouldreturnbool.cxx
@@ -235,7 +235,7 @@ bool ShouldReturnBool::isExprOneOrZero(const Expr* arg) const
return false;
}
APSInt x1;
- if (arg->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
return x1 == 1 || x1 == 0;
}
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index e14fd7c84b3b..3412756b87cb 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -461,7 +461,7 @@ std::string SingleValFields::getExprValue(const Expr* arg)
}
}
APSInt x1;
- if (arg->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
return x1.toString(10);
if (isa<CXXNullPtrLiteralExpr>(arg))
return "0";
diff --git a/compilerplugins/clang/staticconstfield.cxx b/compilerplugins/clang/staticconstfield.cxx
index 6925c18ec301..5a9e7adf52ef 100644
--- a/compilerplugins/clang/staticconstfield.cxx
+++ b/compilerplugins/clang/staticconstfield.cxx
@@ -130,7 +130,7 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init)
else
{
APSInt x1;
- if (initexpr->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(initexpr, x1, compiler.getASTContext()))
{
value = x1.toString(10);
found = true;
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index c33ff2cc2d8f..dd4eeff3763a 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -848,7 +848,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
return true;
}
APSInt res;
- if (!expr->getArg(1)->EvaluateAsInt(
+ if (!compat::EvaluateAsInt(expr->getArg(1),
res, compiler.getASTContext()))
{
return true;
@@ -863,14 +863,14 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
return true;
}
APSInt enc;
- if (!expr->getArg(2)->EvaluateAsInt(
+ if (!compat::EvaluateAsInt(expr->getArg(2),
enc, compiler.getASTContext()))
{
return true;
}
auto const encIsAscii = enc == 11; // RTL_TEXTENCODING_ASCII_US
auto const encIsUtf8 = enc == 76; // RTL_TEXTENCODING_UTF8
- if (!expr->getArg(3)->EvaluateAsInt(
+ if (!compat::EvaluateAsInt(expr->getArg(3),
res, compiler.getASTContext())
|| res != 0x333) // OSTRING_TO_OUSTRING_CVTFLAGS
{
@@ -1438,7 +1438,7 @@ bool StringConstant::isStringConstant(
bool StringConstant::isZero(Expr const * expr) {
APSInt res;
- return expr->EvaluateAsInt(res, compiler.getASTContext()) && res == 0;
+ return compat::EvaluateAsInt(expr, res, compiler.getASTContext()) && res == 0;
}
void StringConstant::reportChange(
@@ -1729,7 +1729,7 @@ void StringConstant::handleCharLen(
return;
}
APSInt res;
- if (expr->getArg(arg2)->EvaluateAsInt(res, compiler.getASTContext())) {
+ if (compat::EvaluateAsInt(expr->getArg(arg2), res, compiler.getASTContext())) {
if (res != n) {
return;
}
@@ -1754,7 +1754,7 @@ void StringConstant::handleCharLen(
&cont2, &emb2, &trm2)
&& n2 == n && cont2 == cont && emb2 == emb && trm2 == trm
//TODO: same strings
- && subs->getIdx()->EvaluateAsInt(res, compiler.getASTContext())
+ && compat::EvaluateAsInt(subs->getIdx(), res, compiler.getASTContext())
&& res == 0))
{
return;
@@ -1981,7 +1981,7 @@ void StringConstant::handleFunArgOstring(
&cont, &emb, &trm))
{
APSInt res;
- if (cexpr->getArg(1)->EvaluateAsInt(
+ if (compat::EvaluateAsInt(cexpr->getArg(1),
res, compiler.getASTContext()))
{
if (res == n && !emb && trm) {
diff --git a/compilerplugins/clang/unicodetochar.cxx b/compilerplugins/clang/unicodetochar.cxx
index 19a7aeb3ebb9..e1e381ad2c71 100644
--- a/compilerplugins/clang/unicodetochar.cxx
+++ b/compilerplugins/clang/unicodetochar.cxx
@@ -58,7 +58,7 @@ public:
return true;
}
APSInt res;
- if (expr->getSubExpr()->EvaluateAsInt(res, compiler.getASTContext())
+ if (compat::EvaluateAsInt(expr->getSubExpr(), res, compiler.getASTContext())
&& res >= 0 && res <= 0x7F)
{
return true;
diff --git a/compilerplugins/clang/unusedfields.cxx b/compilerplugins/clang/unusedfields.cxx
index 61dcedf434bb..393c37450b74 100644
--- a/compilerplugins/clang/unusedfields.cxx
+++ b/compilerplugins/clang/unusedfields.cxx
@@ -301,7 +301,7 @@ bool UnusedFields::isSomeKindOfZero(const Expr* arg)
return cxxConstructExpr->getConstructor()->isDefaultConstructor();
}
APSInt x1;
- if (arg->EvaluateAsInt(x1, compiler.getASTContext()))
+ if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
return x1 == 0;
}