summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2021-06-14 13:03:34 +0200
committerStephan Bergmann <sbergman@redhat.com>2021-06-14 15:13:56 +0200
commit900506c9060415ab890a9169c4cb7997d0ba8217 (patch)
tree8ffb8cefc3e4ca6c626c1bd49299a6b2b33bba40
parent2bc78bb5b49c9bb78e65c33c905029b22f29de82 (diff)
Adapt compilerplugins to LLVM 13 APSInt::toString change
<https://github.com/llvm/llvm-project/commit/61cdaf66fe22be2b5942ddee4f46a998b4f3ee29> "[ADT] Remove APInt/APSInt toString() std::string variants". TODO: While most uses of compat::toString should be harmless performance-wise, as they are either in error reporting code or in plugins that are not run by default, some calls like the one in compilerplugins/clang/staticconstfield.cxx might benefit from moving them away from using std::string. Change-Id: Icfac7d6d4a0a4a4edeb5c8bdcdbc13b73e20a5e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117152 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--compilerplugins/clang/compat.hxx10
-rw-r--r--compilerplugins/clang/constantparam.cxx2
-rw-r--r--compilerplugins/clang/expressionalwayszero.cxx10
-rw-r--r--compilerplugins/clang/literaltoboolconversion.cxx2
-rw-r--r--compilerplugins/clang/returnconstant.cxx2
-rw-r--r--compilerplugins/clang/singlevalfields.cxx3
-rw-r--r--compilerplugins/clang/staticconstfield.cxx2
-rw-r--r--compilerplugins/clang/stringconstant.cxx4
-rw-r--r--compilerplugins/clang/virtualdead.cxx3
9 files changed, 26 insertions, 12 deletions
diff --git a/compilerplugins/clang/compat.hxx b/compilerplugins/clang/compat.hxx
index f62061ed48e4..c9b2bc35b5f6 100644
--- a/compilerplugins/clang/compat.hxx
+++ b/compilerplugins/clang/compat.hxx
@@ -10,6 +10,7 @@
#pragma once
#include <cstddef>
+#include <string>
#include <utility>
#include "clang/AST/Decl.h"
@@ -20,6 +21,7 @@
#include "clang/Basic/Specifiers.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Compiler.h"
@@ -41,6 +43,14 @@ template<typename... X, typename Y> LLVM_NODISCARD inline bool isa_and_nonnull(Y
#endif
}
+inline std::string toString(llvm::APSInt const & i, unsigned radix) {
+#if CLANG_VERSION >= 130000
+ return llvm::toString(i, radix);
+#else
+ return i.toString(radix);
+#endif
+}
+
inline clang::SourceLocation getBeginLoc(clang::Decl const * decl) {
#if CLANG_VERSION >= 80000
return decl->getBeginLoc();
diff --git a/compilerplugins/clang/constantparam.cxx b/compilerplugins/clang/constantparam.cxx
index 71c0f69da61a..7cebb1b67efb 100644
--- a/compilerplugins/clang/constantparam.cxx
+++ b/compilerplugins/clang/constantparam.cxx
@@ -175,7 +175,7 @@ std::string ConstantParam::getCallValue(const Expr* arg)
APSInt x1;
if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
- return x1.toString(10);
+ return compat::toString(x1, 10);
}
if (isa<CXXNullPtrLiteralExpr>(arg)) {
return "0";
diff --git a/compilerplugins/clang/expressionalwayszero.cxx b/compilerplugins/clang/expressionalwayszero.cxx
index 24e7287615ba..b5650aa076a2 100644
--- a/compilerplugins/clang/expressionalwayszero.cxx
+++ b/compilerplugins/clang/expressionalwayszero.cxx
@@ -91,8 +91,9 @@ bool ExpressionAlwaysZero::VisitBinaryOperator(BinaryOperator const* binaryOpera
return true;
report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1",
compat::getBeginLoc(binaryOperator))
- << (lhsValue ? lhsValue->toString(10) : "unknown")
- << (rhsValue ? rhsValue->toString(10) : "unknown") << binaryOperator->getSourceRange();
+ << (lhsValue ? compat::toString(*lhsValue, 10) : "unknown")
+ << (rhsValue ? compat::toString(*rhsValue, 10) : "unknown")
+ << binaryOperator->getSourceRange();
return true;
}
@@ -121,8 +122,9 @@ bool ExpressionAlwaysZero::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* c
return true;
report(DiagnosticsEngine::Warning, "expression always evaluates to zero, lhs=%0 rhs=%1",
compat::getBeginLoc(cxxOperatorCallExpr))
- << (lhsValue ? lhsValue->toString(10) : "unknown")
- << (rhsValue ? rhsValue->toString(10) : "unknown") << cxxOperatorCallExpr->getSourceRange();
+ << (lhsValue ? compat::toString(*lhsValue, 10) : "unknown")
+ << (rhsValue ? compat::toString(*rhsValue, 10) : "unknown")
+ << cxxOperatorCallExpr->getSourceRange();
return true;
}
diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index c3f4c7a62e60..54521a60a209 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -219,7 +219,7 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr(
" %1 with value %2 to %3"),
compat::getBeginLoc(expr2))
<< castExpr->getCastKindName() << subExpr->getType()
- << res->toString(10) << castExpr->getType()
+ << compat::toString(*res, 10) << castExpr->getType()
<< expr2->getSourceRange();
}
}
diff --git a/compilerplugins/clang/returnconstant.cxx b/compilerplugins/clang/returnconstant.cxx
index c2c0442bf63d..1f50aee860f9 100644
--- a/compilerplugins/clang/returnconstant.cxx
+++ b/compilerplugins/clang/returnconstant.cxx
@@ -186,7 +186,7 @@ std::string ReturnConstant::getExprValue(Expr const* arg)
APSInt x1;
if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
- return x1.toString(10);
+ return compat::toString(x1, 10);
}
if (isa<CXXNullPtrLiteralExpr>(arg))
{
diff --git a/compilerplugins/clang/singlevalfields.cxx b/compilerplugins/clang/singlevalfields.cxx
index 2731f55c8587..228e7ddcb211 100644
--- a/compilerplugins/clang/singlevalfields.cxx
+++ b/compilerplugins/clang/singlevalfields.cxx
@@ -15,6 +15,7 @@
#include "config_clang.h"
+#include "compat.hxx"
#include "plugin.hxx"
#if CLANG_VERSION >= 110000
@@ -574,7 +575,7 @@ std::string SingleValFields::getExprValue(const Expr* arg)
}
APSInt x1;
if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
- return x1.toString(10);
+ return compat::toString(x1, 10);
if (isa<CXXNullPtrLiteralExpr>(arg))
return "0";
return "?";
diff --git a/compilerplugins/clang/staticconstfield.cxx b/compilerplugins/clang/staticconstfield.cxx
index 0802c323f810..455ea9bac693 100644
--- a/compilerplugins/clang/staticconstfield.cxx
+++ b/compilerplugins/clang/staticconstfield.cxx
@@ -135,7 +135,7 @@ bool StaticConstField::TraverseConstructorInitializer(CXXCtorInitializer* init)
APSInt x1;
if (compat::EvaluateAsInt(initexpr, x1, compiler.getASTContext()))
{
- value = x1.toString(10);
+ value = compat::toString(x1, 10);
found = true;
}
}
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 0447ba96ad1c..9f51dad4f148 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -945,7 +945,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
("suspicious 'rtl::OUString' constructor with literal"
" of length %0 and non-matching length argument %1"),
expr->getExprLoc())
- << n << res.toString(10) << expr->getSourceRange();
+ << n << compat::toString(res, 10) << expr->getSourceRange();
return true;
}
APSInt enc;
@@ -969,7 +969,7 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
" encoding %0 but plain ASCII content; use"
" 'RTL_TEXTENCODING_ASCII_US' instead"),
expr->getArg(2)->getExprLoc())
- << enc.toString(10) << expr->getSourceRange();
+ << compat::toString(enc, 10) << expr->getSourceRange();
return true;
}
if (encIsUtf8) {
diff --git a/compilerplugins/clang/virtualdead.cxx b/compilerplugins/clang/virtualdead.cxx
index 330085b18781..210a3e2f778f 100644
--- a/compilerplugins/clang/virtualdead.cxx
+++ b/compilerplugins/clang/virtualdead.cxx
@@ -9,6 +9,7 @@
#include "plugin.hxx"
#include "check.hxx"
+#include "compat.hxx"
#include <cassert>
#include <string>
@@ -204,7 +205,7 @@ std::string VirtualDead::getCallValue(const Expr* arg)
APSInt x1;
if (compat::EvaluateAsInt(arg, x1, compiler.getASTContext()))
{
- return x1.toString(10);
+ return compat::toString(x1, 10);
}
if (isa<CXXNullPtrLiteralExpr>(arg))
{