summaryrefslogtreecommitdiff
path: root/compilerplugins/clang/literaltoboolconversion.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-07-28 08:14:49 +0200
committerStephan Bergmann <sbergman@redhat.com>2020-07-28 09:56:46 +0200
commit292a5e719543ec9e6f5fe18fec371302983be038 (patch)
tree9d9d65aa5b6cdc57fb32e669b81cc07b28b8468b /compilerplugins/clang/literaltoboolconversion.cxx
parentd668c9a04d04d256fcbbd2165fe226f1db88256b (diff)
Adapt to Clang 12 trunk Expr::getIntegerConstantExpression
<https://github.com/llvm/llvm-project/commit/ 36036aa70ec1df7b51b5d30b2dd8090ad2b6e783> "Reapply 'Rename/refactor isIntegerConstantExpression to getIntegerConstantExpression'" Change-Id: I99277601fe7ffa3e0e5d22a4b3aaca4f51551ab3 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99570 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'compilerplugins/clang/literaltoboolconversion.cxx')
-rw-r--r--compilerplugins/clang/literaltoboolconversion.cxx58
1 files changed, 30 insertions, 28 deletions
diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx
index 6bfef41b6cc0..c3f4c7a62e60 100644
--- a/compilerplugins/clang/literaltoboolconversion.cxx
+++ b/compilerplugins/clang/literaltoboolconversion.cxx
@@ -125,23 +125,25 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr(
handleImplicitCastSubExpr(castExpr, op->getFalseExpr());
return;
}
- APSInt res;
- if (!subExpr->isValueDependent()
- && subExpr->isIntegerConstantExpr(res, compiler.getASTContext())
- && res.getLimitedValue() <= 1)
- {
- SourceLocation loc { compat::getBeginLoc(subExpr) };
- while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
- loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
- }
- if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
- StringRef name { Lexer::getImmediateMacroName(
- loc, compiler.getSourceManager(), compiler.getLangOpts()) };
- if (name == "sal_False" || name == "sal_True") {
- loc = compat::getImmediateExpansionRange(compiler.getSourceManager(), loc).first;
- }
- if (isSharedCAndCppCode(loc)) {
- return;
+ if (!subExpr->isValueDependent()) {
+ if (auto const res = compat::getIntegerConstantExpr(subExpr, compiler.getASTContext())) {
+ if (res->getLimitedValue() <= 1)
+ {
+ SourceLocation loc { compat::getBeginLoc(subExpr) };
+ while (compiler.getSourceManager().isMacroArgExpansion(loc)) {
+ loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
+ }
+ if (compiler.getSourceManager().isMacroBodyExpansion(loc)) {
+ StringRef name { Lexer::getImmediateMacroName(
+ loc, compiler.getSourceManager(), compiler.getLangOpts()) };
+ if (name == "sal_False" || name == "sal_True") {
+ loc = compat::getImmediateExpansionRange(compiler.getSourceManager(), loc)
+ .first;
+ }
+ if (isSharedCAndCppCode(loc)) {
+ return;
+ }
+ }
}
}
}
@@ -209,17 +211,17 @@ void LiteralToBoolConversion::handleImplicitCastSubExpr(
compat::getBeginLoc(expr2))
<< castExpr->getCastKindName() << subExpr->getType()
<< castExpr->getType() << expr2->getSourceRange();
- } else if (!subExpr->isValueDependent()
- && subExpr->isIntegerConstantExpr(res, compiler.getASTContext()))
- {
- report(
- DiagnosticsEngine::Warning,
- ("implicit conversion (%0) of integer constant expression of type"
- " %1 with value %2 to %3"),
- compat::getBeginLoc(expr2))
- << castExpr->getCastKindName() << subExpr->getType()
- << res.toString(10) << castExpr->getType()
- << expr2->getSourceRange();
+ } else if (!subExpr->isValueDependent()) {
+ if (auto const res = compat::getIntegerConstantExpr(subExpr, compiler.getASTContext())) {
+ report(
+ DiagnosticsEngine::Warning,
+ ("implicit conversion (%0) of integer constant expression of type"
+ " %1 with value %2 to %3"),
+ compat::getBeginLoc(expr2))
+ << castExpr->getCastKindName() << subExpr->getType()
+ << res->toString(10) << castExpr->getType()
+ << expr2->getSourceRange();
+ }
}
}