summaryrefslogtreecommitdiffstats
path: root/compilerplugins/clang/intvsfloat.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'compilerplugins/clang/intvsfloat.cxx')
-rw-r--r--compilerplugins/clang/intvsfloat.cxx20
1 files changed, 10 insertions, 10 deletions
diff --git a/compilerplugins/clang/intvsfloat.cxx b/compilerplugins/clang/intvsfloat.cxx
index d89b34155cce..f6bd996a1e6d 100644
--- a/compilerplugins/clang/intvsfloat.cxx
+++ b/compilerplugins/clang/intvsfloat.cxx
@@ -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,13 +49,13 @@ 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)
return true;
report(DiagnosticsEngine::Warning, "assigning constant float value to int truncates data",
- compat::getBeginLoc(init))
+ init->getBeginLoc())
<< init->getSourceRange();
return true;
@@ -67,7 +67,7 @@ bool IntVsFloat::VisitBinaryOperator(BinaryOperator const* op)
{
return true;
}
- if (ignoreLocation(compat::getBeginLoc(op)))
+ if (ignoreLocation(op->getBeginLoc()))
return true;
auto lhs = op->getLHS()->IgnoreImpCasts();
auto rhs = op->getRHS()->IgnoreImpCasts();
@@ -77,29 +77,29 @@ 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)
return true;
report(DiagnosticsEngine::Warning, "comparing integer to float constant, can never be true",
- compat::getBeginLoc(op))
+ op->getBeginLoc())
<< op->getSourceRange();
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);